OpenCV无法读取ffmpeg视频 [英] OpenCV cannot read ffmpeg videos

查看:232
本文介绍了OpenCV无法读取ffmpeg视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用ffmpeg之后,我无法在OpenCV(python和c ++)中读取视频帧。

I was unable to read video frames in OpenCV (python and c++) after using ffmpeg.

具体来说,我遇到以下问题:

Specifically, I had the following problems:

1)无法使用 VideoCapture 打开视频文件。

1) unable to open the video file using VideoCapture.

2)能够使用 VideoCapture 打开视频文件,但读取零帧和/或接收大小为0x0像素的帧。

2) able to open the video file using VideoCapture, but reading zero frames and/or receiving frames of size 0x0 pixels.

我正在粘贴我的解决方案,希望这将有助于他人。

I am pasting my solution below, hoping this will help others.

在Mac OS X Sierra 10.12.5,ffmpeg 3.2.4,Python 2.7中遇到了这些问题。 13,g ++ 4.2.1

These problems were encountered on Mac OS X Sierra 10.12.5, ffmpeg 3.2.4, Python 2.7.13, g++ 4.2.1

推荐答案

1)OpenCV无法读取与ffmpeg一样多的视频格式。因此,通常可以在VLC中播放视频,但不能在OpenCV的 VideoCapture 中打开它们。因此,通常需要使用诸如 ffmpeg 的工具进行转换(见下一点)。对于我来说,一种格式是h.264。

1) OpenCV cannot read as many video formats as ffmpeg. Therefore, it is often possible to play videos in VLC, but not to open them in OpenCV's VideoCapture. Hence, conversion with a tool such as ffmpeg is often required (see next point). One format that worked for me is h.264.

2)OpenCV似乎需要YUV420,而 ffmpeg YUV444默认。因此,以下命令解决了我的问题:

2) OpenCV seemed to require YUV420, whereas ffmpeg used YUV444 by default. Therefore, the following command solved my problems:

ffmpeg -i input.avi -c:v libx264 -vf format = yuv420p output.mp4

这篇关于OpenCV无法读取ffmpeg视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆