OpenCV-C ++ VideoCapture无法打开视频文件

时间:2016-11-02 19:35:33

标签: c++ opencv ffmpeg

最近我将我的操作系统从Ubuntu Precise Saucy(13.10)升级到Trusty(14.04)。升级后,cv :: VideoCapture无法正常工作。程序在读取视频文件时中止。例如,

int main(int argc, char**argv)
{
  cv::VideoCapture vin("sample/vout2l.avi");
...

执行此程序时,会中止消息:

*** Error in `./cv2-videoread.out': malloc(): memory corruption: 0x0000000000e3eff0 ***
Abort (core dumped)

回溯看起来像:

[New LWP 15586]
[New LWP 15587]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `./cv2-videoread.out'.
Program terminated with signal SIGABRT, Aborted.
#0  0x00007ff953e61c37 in raise () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) bt
#0  0x00007ff953e61c37 in raise () from /lib/x86_64-linux-gnu/libc.so.6
#1  0x00007ff953e65028 in abort () from /lib/x86_64-linux-gnu/libc.so.6
#2  0x00007ff953e9e2a4 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#3  0x00007ff953eabe26 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#4  0x00007ff953eac1ab in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#5  0x00007ff953eadba4 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#6  0x00007ff953eaf7d2 in posix_memalign () from /lib/x86_64-linux-gnu/libc.so.6
#7  0x00007ff94fa640fe in av_malloc () from /usr/lib/x86_64-linux-gnu/libavutil.so.52
#8  0x00007ff94fa641b1 in av_strdup () from /usr/lib/x86_64-linux-gnu/libavutil.so.52
#9  0x00007ff94fa5e5db in av_dict_set ()
  from /usr/lib/x86_64-linux-gnu/libavutil.so.52
#10 0x00007ff954738574 in CvCapture_FFMPEG::open(char const*) ()
  from /usr/lib/libopencv_highgui.so.2.4
#11 0x00007ff954738719 in cvCreateFileCapture_FFMPEG ()
  from /usr/lib/libopencv_highgui.so.2.4
#12 0x00007ff95473aac9 in cvCreateFileCapture_FFMPEG_proxy(char const*) ()
  from /usr/lib/libopencv_highgui.so.2.4
---Type <return> to continue, or q <return> to quit---
#13 0x00007ff954722d89 in cvCreateFileCapture ()
  from /usr/lib/libopencv_highgui.so.2.4
#14 0x00007ff954723045 in cv::VideoCapture::open(std::string const&) ()
  from /usr/lib/libopencv_highgui.so.2.4
#15 0x00007ff95472315c in cv::VideoCapture::VideoCapture(std::string const&) ()
  from /usr/lib/libopencv_highgui.so.2.4
#16 0x0000000000401281 in main (argc=1, argv=0x7fff1f938388) at cv2-videoread.cpp:30
(gdb)

注意:cv::VideoCapture vin(...是第30行。

在升级操作系统之前,此代码使用相同的输入文件。

从回溯中,似乎问题发生在CvCapture_FFMPEGlibavutil。我升级了包ffmpeg libavutil-dev libavutil51 libavutil52,但它们已经是最新的。 此外,OpenCV包是最新的(我检查libopencv-core-dev libopencv-core2.4 libopencv-dev libopencv-highgui-dev libopencv-highgui2.4)。

我还测试了从源代码构建的OpenCV,但得到了相同的结果。

你有想法解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

所以,我已经解决了这个问题。

通过使用ldd分析程序,我发现它与/usr/lib/libopencv_highgui.so相关联。但是,在x86_64系统中,它应该是/usr/lib/x86_64-linux-gnu/libopencv_highgui.so。在我的系统中,两个文件都已安装。

问题是由/usr/lib/libopencv_*.so造成的(我不知道我是如何安装它们的。也许是源代码......?)。我删除了这些文件,并再次编译了上述程序。然后它没有错误地工作。