Repository: opencv
Issue: CvCapture_FFMPEG::retrieveFrame(...) gives SIGSEGV for high-framerate AVI
Labels: bug,auto-transferred,priority: normal,category: videoio,affected: 2.4

Transferred from http://code.opencv.org/issues/3030

```
|| Brian TheLion on 2013-05-16 18:48
|| Priority: Normal
|| Affected: 2.4.5 (latest release)
|| Category: highgui-video
|| Tracker: Bug
|| Difficulty: None
|| PR: 
|| Platform: None / None
```
## CvCapture_FFMPEG::retrieveFrame(...) gives SIGSEGV for high-framerate AVI

```
Basic video capture-and-display scenario using compiled 2.4.5 libraries:

<pre>
/* cvvideoshow.cpp */
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;

int main( int argc, char** argv ) {
  if( argc != 2) {
    cout <<" Usage: cvimshow [video_file]" << endl;
    return -1;
  }

  VideoCapture cap(argv[1]);
  if (!cap.isOpened()) {       //check if video device has been initialized
    cout << "Cannot open file" << endl;
  }

  Mat cameraFrame;

  //unconditional loop
  while (true) {
    if (!cap.read(cameraFrame)) break;
    imshow("cam", cameraFrame);
    if (waitKey(30) >= 0) break;
  }
  return 0;
}
</pre>

<pre>
$ gcc cvvideoshow.cpp -o cvvideoshow -lopencv_highgui -lopencv_core -lstdc++
$ ./cvvideoshow 1000fps.avi # file available for download at https://docs.google.com/file/d/0Bz_2ACaA7oKEV2d6eF93WDd6YVk/edit?usp=sharing
Segmentation Fault
$ (install)br@breach:~/dev/proj/cv/build/cvhelpers/src/cvimshow$ gdb --args ./cvimshow 1000fps.avi 
GNU gdb (GDB) 7.5.91.20130417-cvs-ubuntu
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from cvvideoshow...(no debugging symbols found)...done.
(gdb) r
Starting program: ./cvvideoshow 1000fps.avi
warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7ffff7ffa000
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff31c3e51 in ?? ()
   from /usr/lib/x86_64-linux-gnu/libswscale.so.2
(gdb) bt
#0  0x00007ffff31c3e51 in ?? ()
   from /usr/lib/x86_64-linux-gnu/libswscale.so.2
#1  0x00007ffff31a9e16 in sws_scale ()
   from /usr/lib/x86_64-linux-gnu/libswscale.so.2
#2  0x00007ffff7bae851 in CvCapture_FFMPEG::retrieveFrame(int, unsigned char**, int*, int*, int*, int*) ()
   from /usr/lib/libopencv_highgui.so.2.4
#3  0x00007ffff7bae8fb in cvRetrieveFrame_FFMPEG ()
   from /usr/lib/libopencv_highgui.so.2.4
#4  0x00007ffff7badc49 in CvCapture_FFMPEG_proxy::retrieveFrame(int) () from /usr/lib/libopencv_highgui.so.2.4
#5  0x00007ffff7bac607 in cv::VideoCapture::retrieve(cv::Mat&, int) () from /usr/lib/libopencv_highgui.so.2.4
#6  0x00007ffff7bac407 in cv::VideoCapture::read(cv::Mat&) ()
   from /usr/lib/libopencv_highgui.so.2.4
#7  0x00000000004017a1 in main ()
(gdb) q
A debugging session is active.

    Inferior 1 [process 30800] will be killed.

Quit anyway? (y or n) y
</pre>
```
## History
##### Alexander Shishkov on 2013-05-17 14:02

```
Thank you for reporting the issue. Could you add more details about your OS and FFMPEG versions? Does this code work with other videos?
-   Assignee set to Brian TheLion
-   Category set to highgui-video
```
##### Brian TheLion on 2013-05-17 16:26

```
Yes, example code works fine for other videos. Here's how I discovered the issue:

1) The example code was initially implemented on Ubuntu 12.10 using the distro's libopencv-dev (OpenCV v2.3.1-7) package. It worked fine.
2) Last week I upgraded from Ubuntu 12.10 to 13.04.
3) I rebuilt the example code against the distro's libopencv-dev package, now because of the upgrade at OpenCV v2.4.2.
4) The bug appeared.
5) I uninstalled libopencv-dev and built OpenCV v2.4.5 from the source tarball.
6) I rebuilt the example code and still found the bug.

I had someone else here in the office verify this scenario as well. Thus, the bug appears to have been introduced somewhere between v2.3.1-7 and v2.4.2.
```
##### Brian TheLion on 2013-05-17 18:29

```
FFMPEG-related functionality on Ubuntu 13.04 is provided by libavutil. Here are the relevant dependencies from apt:

<pre>
br@breach:~$ aptitude show libopencv-highgui2.4 
Package: libopencv-highgui2.4            
State: installed
Automatically installed: yes
Version: 2.4.2+dfsg-0exp2ubuntu1
Priority: optional
Section: universe/libs
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Architecture: amd64
Uncompressed Size: 313 k
Depends: libavcodec53 (>= 6:0.8.3-1~) | libavcodec-extra-53
         (>= 6:0.8.4), libavformat53 (>= 6:0.8.3-1~) |
         libavformat-extra-53 (>= 6:0.8.4), libavutil51 (>=
         6:0.8.3-1~) | libavutil-extra-51 (>= 6:0.8.4), libc6
         (>= 2.15), libdc1394-22, libgcc1 (>= 1:4.1.1),
         libglib2.0-0 (>= 2.31.8), libgtk2.0-0 (>= 2.8.0),
         libilmbase6 (>= 1.0.1), libjasper1, libjpeg8 (>= 8c),
         libopencv-core2.4, libopencv-imgproc2.4 (=
         2.4.2+dfsg-0exp2ubuntu1), libopenexr6 (>= 1.6.1),
         libpng12-0 (>= 1.2.13-4), libstdc++6 (>= 4.1.1),
         libswscale2 (>= 6:0.8.3-1~) | libswscale-extra-2 (>=
         6:0.8.4), libtiff5 (> 4.0.0-1~), libv4l-0 (>= 0.5.0)
</pre>

And the versions of the libav dependencies:

libavcodec53         6:0.8.6-1ubuntu2
libavcodec-extra-53  6:0.8.6ubuntu2
libavformat53        6:0.8.6-1ubuntu2
libavformat-extra-53 6:0.8.6ubuntu2
libavutil51          6:0.8.6-1ubuntu2
libavutil-extra-51   6:0.8.6ubuntu2
libswscale2          6:0.8.6-1ubuntu2
libswscale-extra-2   6:0.8.6ubuntu2
```
##### Brian TheLion on 2013-05-22 14:53

```
Can someone upstream please confirm this bug? I am now blocking on it. I have provided the code, the configuration, and an example video for which it fails. Cheers!
```
##### Jaime  Alemany on 2013-08-17 00:32

```
Hi

I recently upgrade to ubuntu 13.04 and had the same problem. I resolved this setting the frame position to 0 before reading first frame with cvSetCaptureProperty(). 

After that the video plays again but now i found a new problem: some of the frames show corrupted data... (im trying to find why)
```