首页 > 代码库 > [原]通过配合ffmpeg.exe获取视频文件时长
[原]通过配合ffmpeg.exe获取视频文件时长
import subprocessimport osimport timedef 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获取视频文件时长
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。