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中selenium实现文件上传所有方法整理总结

文件上传是所有UI自动化测试都要面对的一个头疼问题,今天博主在这里给大家分享下自己处理文件上传的经验,希望能够帮助到广大被文件上传坑住的seleniumer。 首先,我们要区分出上传按钮...

Python 获取新浪微博的最新公共微博实例分享

API: statuses/public_timeline  返回最新的200条公共微博,返回结果非完全实时 CODE: #!/usr/bin/python # -*-...

Python-opencv 双线性插值实例

我就废话不多说了,直接上代码吧! #coding=utf-8 import cv2 import numpy as np '''双线性插值''' img = cv2.imread('...

Python用zip函数同时遍历多个迭代器示例详解

前言 本文主要介绍的是Python如何使用zip函数同时遍历多个迭代器,文中的版本为Python3,zip函数是Python内置的函数。下面话不多说,来看详细的内容。 应用举例...

python实现批量按比例缩放图片效果

本文实例为大家分享了python实现批量按比例缩放图片的具体代码,供大家参考,具体内容如下 把脚本文件放在要缩放的文件夹下面。 双击运行脚本,输入要缩放的系数。脚本会在当前目录下创建一个...