如何在Windows上从ffmpeg到python同时获取实时视频帧和时间戳
发布时间:2020-12-14 01:38:20 所属栏目:Windows 来源:网络整理
导读:搜索OpenCV的替代方案不会为我的计算机视觉算法中需要的实时摄像机流(在 Windows上)提供时间戳,我发现了ffmpeg和这篇优秀的文章 https://zulko.github.io/blog/2013/09/27/read-and-write-video-frames-in-python-using-ffmpeg/ 该解决方案使用ffmpeg,访问其
搜索OpenCV的替代方案不会为我的计算机视觉算法中需要的实时摄像机流(在
Windows上)提供时间戳,我发现了ffmpeg和这篇优秀的文章
https://zulko.github.io/blog/2013/09/27/read-and-write-video-frames-in-python-using-ffmpeg/
该解决方案使用ffmpeg,访问其标准输出(stdout)流.我将其扩展为读取标准错误(stderr)流. 在Windows上处理python代码,同时我收到来自ffmpeg stdout的视频帧,但是stderr在为第一帧提供showinfo videofilter详细信息(时间戳)后冻结. 我记得在某个地方的ffmpeg论坛上看到重定向时会绕过像showinfo这样的视频过滤器.这是为什么以下代码无法按预期工作的原因? 预期:它应该将视频帧写入磁盘以及打印时间戳详细信息. 这是我试过的代码: import subprocess as sp import numpy import cv2 command = [ 'ffmpeg','-i','e:sample.wmv','-pix_fmt','rgb24','-vcodec','rawvideo','-vf','showinfo',# video filter - showinfo will provide frame timestamps '-an','-sn',#-an,-sn disables audio and sub-title processing respectively '-f','image2pipe','-'] # we need to output to a pipe pipe = sp.Popen(command,stdout = sp.PIPE,stderr = sp.PIPE) # TODO someone on ffmpeg forum said video filters (e.g. showinfo) are bypassed when stdout is redirected to pipes??? for i in range(10): raw_image = pipe.stdout.read(1280*720*3) img_info = pipe.stderr.read(244) # 244 characters is the current output of showinfo video filter print "showinfo output",img_info image1 = numpy.fromstring(raw_image,dtype='uint8') image2 = image1.reshape((720,1280,3)) # write video frame to file just to verify videoFrameName = 'Video_Frame{0}.png'.format(i) cv2.imwrite(videoFrameName,image2) # throw away the data in the pipe's buffer. pipe.stdout.flush() pipe.stderr.flush() 那么如何将帧时间戳从ffmpeg转换为python代码,以便可以在我的计算机视觉算法中使用… 解决方法
你可以使用
MoviePy:
import moviepy.editor as mpy vid = mpy.VideoFileClip('e:sample.wmv') for timestamp,raw_img in vid.iter_frames(with_times=True): # do stuff (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Windows与Linux文件互传
- microsoft-metro – Windows 8商店应用程序是否具有Message
- 窗口 – 当开始与Qt框架,什么选择 – 小部件或QT快?
- 文件服务器 – 具有存储空间直接的横向扩展文件服务器
- windows-phone-7 – 如何隐藏WP7中的状态栏(Silverlight)
- Windows – Win32,多个NIC计算机,每个NIC不同的DNS,gethost
- Windows PowerShell 2.0中的运行空间是什么?
- winapi – 检查Windows帐户的用户名和密码
- 想说再见不容易,win7最新市占率依然超36%
- windows-7 – Windows 7上的SetCommState失败
推荐文章
站长推荐
- Windows+MyEclipse+MySQL【连接数据库报错cachin
- Microsoft Teams Voice语音落地系列-4 实战:Team
- windows-server-2008 – 如果你有多个域控制器,有
- 关于Windows的Lua IDE和调试器的建议
- 为什么Windows XP防火墙在启动时不会使用域设置?
- 如何在NTFS / Windows上禁用“上次访问”属性?
- Windows系统 Mysql5.6下载安装以及配置
- windows – 如何使用PowerShell远程重命名域中的
- 你能在Windows 10上使用JavaScript检测Edge和IE1
- 可启动的Windows Server 2016 USB驱动器
热点阅读