python通过ffmgep从视频中抽帧的方法
如下所示:
ffmpeg中文文档:http://linux.51yip.com/search/ffmpeg
ffmpeg-itest_baofeng.wmv-y-fimage2-ss00:00:03-vframes1myframe.jpg
ffmpeg-itest.mp4-y-fmjpeg-ss3-t1test1.jpg
-ffmt强迫采用格式fmt
-Ifilename输入文件
-y覆盖输出文件
-tduration设置纪录时间hh:mm:ss[.xxx]格式的记录时间也支持
-ssposition搜索到指定的时间[-]hh:mm:ss[.xxx]的格式也支持
python使用ffmgep,通常用:subprocessffmpeg/libav
--------------------python通过ffmgep抽帧---------------------
importos,sys
fromPILimportImage
#openapipefromacommand
a,b,c=os.popen3("ffmpeg-itest.avi")
out=c.read()
dp=out.index("Duration:")
duration=out[dp+10:dp+out[dp:].index(",")]
hh,mm,ss=map(float,duration.split(":"))
#totaltimess
total=(hh*60+mm)*60+ss
foriinxrange(9):
t=int((i+1)*total/10)
#ffmpeg-itest.mp4-y-fmjpeg-ss3-t1test1.jpg
os.system("ffmpeg-itest.avi-y-fmjpeg-ss%s-t1frame%i.jpg"%(t,i))
"""
num=int(total-3)
i=0
fortinxrange(0,num,3):
i=i+1
#ffmpeg-itest.mp4-y-fmjpeg-ss3-t1test1.jpg
os.system("ffmpeg-itest.avi-y-fmjpeg-ss%s-t1%sframe%i.jpg"%(t,t,i))
"""
以上这篇python通过ffmgep从视频中抽帧的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。