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获取视频文件时长的更多相关文章

  1. 以springMVC为例获取上传视频文件时长

    毕设项目是一个在线学习系统,教师用户有上传视频的功能,在答辩之前赶了一个demo出来,好多功能都写死了,比如课程学习进度就是被我写死在前端的一个变量,最近导师要我把项目打包发给他,这才心慌慌赶紧把这些 ...

  2. Shell32.ShellClass服务器操作系统无法获取 音频文件时长问题

    前言: 上传音频文件,自动写入此音频文件的时长,这里用 COM组件Microsoft Shell Controls And Automation来实现. 首先 1.引用:Microsoft Shell ...

  3. java 获取音频文件时长

    需要导入jar包:jave 1.0.2 jar 如果是maven项目,在pom.xml文件中添加: <dependency> <groupId>it.sauronsoftwar ...

  4. java读取视频文件时长

    1.下载jar包:http://www.sauronsoftware.it/projects/jave/index.php 2.上代码 @RequestMapping(value = "am ...

  5. PHP如何获取视频总时长与码率等信息

    利用PHP中的FFmpeg读取视频播放时长与码率等信息   function getVideoInfo($file) {    define('FFMPEG_PATH', '/usr/local/ff ...

  6. C#获取mp3文件时长、解决发布到服务器无法使用问题

    首先引用COM组件:Microsoft Shell Controls And Automation,需要引用1.2版本的,1.0的会出问题. 这里需要注意DLL的属性Embed Interop Typ ...

  7. C#中获取音频文件时长

    1.在项目中添加引入:COM组件的Microsoft Shell Controls And Automation 2.在引用中找到Shell32,点击右键,在属性中将“嵌入互操作类型”的值改为“fal ...

  8. JAVA通过URL链接获取视频文件信息(无需下载文件)

    最近项目碰到一个大坑:APP上需要在获取视频列表时就获取视频的时长,但早期上传的时候数据库都没有保存这个数据,所以前段时间添加一个时长字段,在上传时手动输入视频时长,但是之前库中有上万条数据没这个信息 ...

  9. js 获取上传视频的时长、大小、后缀名

    参考资料:获取时长 var fileName = $("#sectionfileUpload").val(); //C:\fakepath\3.jpeg var exts = fi ...

随机推荐

  1. 为 Docker Registry 增加 Nginx 前端

    其实Docker Registry 就是一个API backend,所以加一个Nginx前端有大大的好处,比如docker push 时增加用户名密码验证. 怎么加?请参考以下nginx配置 upst ...

  2. day9mysql操作

    #!/usr/bin/env python #coding:utf8 import MySQLdb pip install MySQL-python 先创建一个表 mysql> use xym; ...

  3. [JavaScript]配置日期选择控件

    我选择的日期控件是:bootstrap-datepicker(下载路径:https://github.com/Aymkdn/Datepicker-for-Bootstrap) 比较方便,实用.原来是英 ...

  4. sql install error

    解决SQL Server 2008 R2安装过程中提示Could not open key的解决方法:以管理员身份运行CMD命令提示符,输入以下语句并运行就OK了secedit /configure ...

  5. linux出现user account has expired解决方案

    SUSE Linux 用户user1登陆不了,确认密码没错,使用root用户登陆,su - user1 提示密码不对,passwd user1提示帐户过期user account hasexpired ...

  6. Notepad++的xml文本格式化

    1.需要使用插件 2.使用插件

  7. asp.net中如何调取数据库中存储过程输出的两个变量

    public DataTable GetList_GenqtyNumPrice(int _peoid, int _genstorageid,int _goodsid) { DataSet ds = n ...

  8. loaded the "ViewController" nib but the view outlet was not set.'

    错误代码: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[U ...

  9. 如何启动另一个应用的activity

    1.使用action Intent i=new Intent(); i.setAction(".........."); startActivity(i); 前提条件:要启动的ac ...

  10. PHP正则表达式模式修饰符 /i, /is, /s, /isU等

    模式修饰符 下面列出了当前可用的 PCRE 修饰符.括号中提到的名字是 PCRE 内部这些修饰符的名称. 模式修饰符中的空格,换行符会被忽略,其他字符会导致错误. i (PCRE_CASELESS) ...