简体   繁体   English

使用OpenCV VideoCapture读取视频文件

[英]Reading video files with OpenCV VideoCapture

I am having trouble being able top open any video files in OpenCV besides those encoded in MJPEG. 除了以MJPEG编码的视频文件之外,我无法在OpenCV中打开任何视频文件。

I have installed OpenCV using this script (which should compile OpenCV with support for ffmpeg) and an testing using the sample provided here . 我已经使用脚本安装了OpenCV(应使用ffmpeg的支持编译OpenCV)并使用此处提供的示例进行测试。

When running with a h264 encoded video I get: 当使用h264编码的视频运行时,我得到:

[mov,mp4,m4a,3gp,3g2,mj2 @ 0x123ed80] multiple edit list entries, a/v desync might occur, patch welcome
[h264 @ 0x12465e0] A non-intra slice in an IDR NAL unit.
[h264 @ 0x12465e0] decode_slice_header error
Could not open the output video for write: test.mp4

When running with an MPEG-2 encoded video I get: 当以MPEG-2编码的视频运行时,我得到:

[mpegts @ 0x1e92d80] PES packet size mismatch
[mpegts @ 0x1e92d80] PES packet size mismatch
[mpegts @ 0x1e92d80] max_analyze_duration reached
[mpegts @ 0x1e92d80] PES packet size mismatch
Could not open the output video for write: test.mpeg

I am running x64 Ubuntu 12.04. 我正在运行x64 Ubuntu 12.04。

EDIT: I tried OpenCV 2.4.8 on a Ubuntu 13.10 x86 VM, ffmpeg works fine, however the sample code still fails, this time with the following error: 编辑:我在Ubuntu 13.10 x86 VM上尝试过OpenCV 2.4.8, ffmpeg可以正常工作,但是示例代码仍然失败,这次出现以下错误:

[h264 @ 0x849ff40] A non-intra slice in an IDR NAL unit.
[h264 @ 0x849ff40] decode_slice_header error
Could not find encoder for codec id 28: Encoder not foundOpenCV Error: Unsupported format or combination of formats (Gstreamer Opencv backend doesn't support this codec acutally.) in CvVideoWriter_GStreamer::open, file /home/dan/Install-OpenCV/Ubuntu/2.4/OpenCV/opencv-2.4.8/modules/highgui/src/cap_gstreamer.cpp, line 505
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/dan/Install-OpenCV/Ubuntu/2.4/OpenCV/opencv-2.4.8/modules/highgui/src/cap_gstreamer.cpp:505: error: (-210) Gstreamer Opencv backend doesn't support this codec acutally. in function CvVideoWriter_GStreamer::open

I am not sure about the main reason for this. 我不确定主要原因。 But I guess this problem is relate to the decoder installed on your system. 但是我想这个问题与您系统上安装的解码器有关。 According to the install script from github, it removes your ffmpg and x264 then rebuilds them from source code. 根据github上的安装脚本,它将删除ffmpg和x264,然后从源代码中重建它们。 Before testing your OpenCV code, try simple "ffmpeg" command on your test video. 在测试您的OpenCV代码之前,请在测试视频上尝试简单的“ ffmpeg”命令。 Such as: ffmpeg -i inputfile.avi -f image2 image-%3d.jpeg 例如: ffmpeg -i inputfile.avi -f image2 image-%3d.jpeg

  1. The script you have used is quite old and installs old version of OpenCV (2.4.2, while the latest stable is 2.4.8), try to use this script - https://github.com/jayrambhia/Install-OpenCV/blob/master/Ubuntu/2.4/opencv2_4_8.sh or install OpenCV and ffmpeg on you own. 您使用的脚本相当旧,并且安装了旧版本的OpenCV(2.4.2,而最新的稳定版是2.4.8),请尝试使用此脚本-https: //github.com/jayrambhia/Install-OpenCV/blob /master/Ubuntu/2.4/opencv2_4_8.sh或自行安装OpenCV和ffmpeg。
  2. As rookiepig mentioned - check whether ffmpeg is working. 正如菜鸟所说的-检查ffmpeg是否正常工作。
  3. Try to use different codec - here http://www.fourcc.org/ is full list of options, of course testing all of them is useless - jsut try the most popular codecs. 尝试使用其他编解码器-这里的http://www.fourcc.org/是完整的选项列表,当然测试所有这些选项都是没有用的-jsut尝试最流行的编解码器。
  4. I know that it's stupid, but on Windows some codecs works only in release mode(okay, probably they are working in both modes, but on my machine they used to work only in release mode). 我知道这很愚蠢,但是在Windows上,某些编解码器只能在发布模式下工作(好的,可能它们在两种模式下都可以工作,但是在我的机器上,它们以前只能在发布模式下工作)。 Try to compile you program in both modes and check whether there is some difference. 尝试在两种模式下编译程序,并检查是否存在一些差异。

And show us you code, maybe there is something wrong in it. 并向我们​​显示您的代码,也许其中有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM