python通过ffmgep从视频中抽帧的方法

yipeiwu_com5年前Python基础

如下所示:

ffmpeg中文文档:http://linux.51yip.com/search/ffmpeg

ffmpeg -i test_baofeng.wmv -y -f image2 -ss 00:00:03 -vframes 1 myframe.jpg

ffmpeg -i test.mp4 -y -f mjpeg -ss 3 -t 1 test1.jpg

-f fmt 强迫采用格式fmt

-I filename 输入文件

-y 覆盖输出文件

-t duration 设置纪录时间 hh:mm:ss[.xxx]格式的记录时间也支持

-ss position 搜索到指定的时间 [-]hh:mm:ss[.xxx]的格式也支持

python使用ffmgep,通常用:subprocess ffmpeg/libav

--------------------python通过ffmgep抽帧---------------------

import os, sys
from PIL import Image
#open a pipe from a command 
a, b, c = os.popen3("ffmpeg -i test.avi")
out = c.read()
dp = out.index("Duration: ")
duration = out[dp+10:dp+out[dp:].index(",")]
hh, mm, ss = map(float, duration.split(":"))
#total time ss
total = (hh*60 + mm)*60 + ss
for i in xrange(9):
 t = int((i + 1) * total / 10)
 # ffmpeg -i test.mp4 -y -f mjpeg -ss 3 -t 1 test1.jpg 
 os.system("ffmpeg -i test.avi -y -f mjpeg -ss %s -t 1 frame%i.jpg" % (t, i))
 
"""
num=int(total-3)
i=0
for t in xrange(0,num,3):
 i = i+1
 # ffmpeg -i test.mp4 -y -f mjpeg -ss 3 -t 1 test1.jpg 
 os.system("ffmpeg -i test.avi -y -f mjpeg -ss %s -t 1 %sframe%i.jpg" % (t,t, i))
"""

以上这篇python通过ffmgep从视频中抽帧的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python根据文章标题内容自动生成摘要的实例

python根据文章标题内容自动生成摘要的实例

text.py title = '智能金融起锚:文因、数库、通联瞄准的kensho革命' text = '''2015年9月13日,39岁的鲍捷乘上从硅谷至北京的飞机,开启了他心中的...

Python实现接受任意个数参数的函数方法

这个功能倒也不是我多么急需的功能,只是恰好看到了,觉得或许以后会用的到。功能就是实现函数能够接受不同数目的参数。 其实,在C语言中这个功能是熟悉的,虽说实现的形式不太一样。C语言中的ma...

使用python+whoosh实现全文检索

whoosh的官方介绍:http://whoosh.readthedocs.io/en/latest/quickstart.html 因为做的是中文的全文检索需要导入jieba工具包以及...

合并百度影音的离线数据( with python 2.3)

四种格式的解析: filelist slicelist download.cfg third_party_download.cfg 还是2个文件。替换之前版本即可。 初步测试正常,但时间...

python求pi的方法

本文实例讲述了python求pi的方法,是一篇翻译自国外网站的文章,分享给大家供大家参考。 具体实现方法如下: #_*_ coding=utf-8 *_* ## {{{ http:/...