[原]通过配合ffmpeg.exe获取视频文件时长
Posted casio1374633
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[原]通过配合ffmpeg.exe获取视频文件时长相关的知识,希望对你有一定的参考价值。
import subprocess import os import time def getTime(flvpath,fid): #file_str = ‘1.flv‘ file_str = flvpath wg = subprocess.Popen([‘ffmpeg.exe‘, ‘-i‘, file_str], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) (standardout, junk) = wg.communicate() ans = str(standardout) num = ans.find("Duration:") out = ans[num+10:num+18] fid.write(file_str + "<| time is |>" + out) fid.write("\r\n") def getFileName(path, warp): #f_list = os.listdir(path) #rootdir = os.getcwd() rootdir = path logname = warp[1:] + ‘_log.txt‘ fid = open(logname, ‘w‘) for (dirpath, dirnames, filenames) in os.walk(rootdir): for filename in filenames: pathname = os.path.join(dirpath, filename) if os.path.splitext(pathname)[1].lower() == warp: getTime(pathname,fid) fid.close() if __name__ == "__main__": print("Begin time: " + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())) rootdir = "D:\\mooc\\视频资料" warp = ".flv" getFileName(rootdir, warp) warp = ".mp4" getFileName(rootdir, warp) print("End time:" + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
以上是关于[原]通过配合ffmpeg.exe获取视频文件时长的主要内容,如果未能解决你的问题,请参考以下文章