• [原]通过配合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("
    ")
    
    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()))
  • 相关阅读:
    Passing Reference by value
    WPF中override ResourceDictionary中的设置的方法
    WPF中TextBox的PreviewMouseLeftButtonUp事件
    Attribute的理解和认识
    IIS添加服务
    Unix时间戳转换成C#中的DateTime
    KMP算法的实现
    IDA 宏定义
    实验吧-catalyst-system
    python整数转ASCII码
  • 原文地址:https://www.cnblogs.com/esta-pessoa/p/6134278.html
Copyright © 2020-2023  润新知