[原]通过配合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()))

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM