简体   繁体   中英

Segmentation Fault with opencv on reading a video from a file

i am running a simple code to capture a video from a file but its return a segmentation fault

     #include "opencv2/highgui/highgui.hpp"
     #include<opencv2/opencv.hpp>
     #include <stdio.h>
     //#include <iostream>

     using namespace cv;
     using namespace std;

     int main()
     {
    CvCapture* capture = cvCreateFileCapture("/home/ayush/20130521053652.avi");

    IplImage* frame = NULL;

    if(!capture)
    {
        printf("Video Not Opened\n");
        return -1;
    }

    int width = (int)cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_WIDTH);
    int height = (int)cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_HEIGHT);
    double fps = cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);
    int frame_count = (int)cvGetCaptureProperty(capture,  CV_CAP_PROP_FRAME_COUNT);

    printf("Video Size = %d x %d\n",width,height);
    printf("FPS = %f\nTotal Frames = %d\n",fps,frame_count);

    while(1)
    {
        frame = cvQueryFrame(capture);

        if(!frame)
        {
            printf("Capture Finished\n");
            break;
        }

        cvShowImage("video",frame);
        cvWaitKey(10);
    }

    cvReleaseCapture(&capture);
    return 0;
}

i am also tried this above code which is actually a solution for a particular question but its still giving me a same thing...

Video file information

   $file 20130521053652.avi 
   20130521053652.avi: RIFF (little-endian) data, AVI, 640 x 480, 30.00 fps, video:

some more information

   Dimensions: 640 x 480
   Codec:      24-bit RGB
   Framerate:  30 frames per second
   Bitrate:    N/A  

i think there must be issue with codec my platform is linux/ubuntu 12.04 LTS please can any body suggest me solution for this

Through gdb debugger the Segmentation fault is giving at frame = cvQueryFrame(capture)

o/p is something this

     (gdb) 
      66          frame = cvQueryFrame(capture);           
     (gdb) 

                  Program received signal SIGSEGV, Segmentation fault.
                __memcpy_ssse3 () at ../sysdeps/i386/i686/multiarch/memcpy-ssse3.S:160
       160  ../sysdeps/i386/i686/multiarch/memcpy-ssse3.S: No such file or directory.

through Qt IDE ==> Debugging

      0xb751d9fa  <+0x146a>         movzbl (%eax),%eax
      1951  in ../sysdeps/i386/i686/multiarch/memcpy-ssse3.S
      0xb751d9fd  <+0x146d>         mov    %al,(%edx)
      1952  in ../sysdeps/i386/i686/multiarch/memcpy-ssse3.S
      1953  in ../sysdeps/i386/i686/multiarch/memcpy-ssse3.S
      0xb751d9ff  <+0x146f>         mov    0x8(%esp),%eax
      1954  in ../sysdeps/i386/i686/multiarch/memcpy-ssse3.S
      1955  in ../sysdeps/i386/i686/multiarch/memcpy-ssse3.S
      1956  in ../sysdeps/i386/i686/multiarch/memcpy-ssse3.S
      1957  in ../sysdeps/i386/i686/multiarch/memcpy-ssse3.S
      1958  in ../sysdeps/i386/i686/multiarch/memcpy-ssse3.S
      1959  in ../sysdeps/i386/i686/multiarch/memcpy-ssse3.S
      0xb751da03  <+0x1473>         pop    %ebx
      0xb751da04  <+0x1474

I had the same issue in OpenCV 2.4, using cvCaptureFromFile()/cvQueryFrame(). Converting my AVI to an FLV (using avconv) worked for me.

My guess is that this is an OpenCV bug.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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