OpenCV - Writing an AVI File

Hi all,

I am new to c++ and opencv. I have this code below which tries to take an AVI file, transforms it to grey scale frame by frame and creates a new AVI file. This is code is taken from Learning OpenCV by Gary Bradski. It compiles but it gives run time error and I couldn't solve the problem. Would you please tell me what am I doing wrong?

Best regards,
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "cv.h"
#include "highgui.h"

main( int argc, char* argv[] )
{
    CvCapture* capture = 0;
    capture = cvCreateFileCapture( argv[1] );

    if(!capture)
        { return -1; }

    IplImage *bgr_frame=cvQueryFrame(capture);//Init the video read
    double fps = cvGetCaptureProperty ( capture, CV_CAP_PROP_FPS );

    CvSize size = cvSize( (int)cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH),
                          (int)cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT) );

    // creates video: file to write -- codec that's gonna be used -- frame per second -- size of video frames -- grayscale or not
    CvVideoWriter *writer = cvCreateVideoWriter( argv[2], CV_FOURCC('M','J','P','G'), fps, size, 0 );

    IplImage* logpolar_frame = cvCreateImage( size, IPL_DEPTH_8U, 3 );

    while( (bgr_frame=cvQueryFrame(capture)) != NULL )
    {
        cvLogPolar( bgr_frame,
                    logpolar_frame,
                    cvPoint2D32f(bgr_frame->width/2, bgr_frame->height/2),
                    40,
                    CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS );

        cvWriteFrame( writer, logpolar_frame );

    }//

    cvReleaseVideoWriter( &writer );
    cvReleaseImage( &logpolar_frame );
    cvReleaseCapture( &capture );

    return(0);

}



This is the command window output:



Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.


C:\Users\*******\codeblocks_workspace\CVWorkouts\Newfolder\bin\Debug>CVWorkout_8.exe test.avi out.avi

Output #0, avi, to 'out.avi':
Stream #0.0: Video: mjpeg, yuvj420p, 176x184, q=2-31, 4145 kb/s, 90k tbn, 15
tbc

C:\Users\********\codeblocks_workspace\CVWorkouts\New folder\bin\Debug>
Last edited on
I made a modification to the code: I commented out the cvLogPolar part and compiled it. Now it can take a video and create a new identical copy. So I believe that the problem has to do with that part. Here is the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "cv.h"
#include "highgui.h"

main( int argc, char* argv[] )
{
    CvCapture* capture = 0;
    capture = cvCreateFileCapture( argv[1] );

    if(!capture)
        { return -1; }

    IplImage *bgr_frame=cvQueryFrame(capture);//Init the video read
    double fps = cvGetCaptureProperty ( capture, CV_CAP_PROP_FPS );

    CvSize size = cvSize( (int)cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH),
                          (int)cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT) );

    // creates video: file to write -- codec that's gonna be used -- frame per second -- size of video frames -- grayscale or not
    CvVideoWriter *writer = cvCreateVideoWriter( argv[2], CV_FOURCC('M','J','P','G'), fps, size, 1 );

    IplImage* logpolar_frame = cvCreateImage( size, IPL_DEPTH_8U, 1 );

    while( (bgr_frame=cvQueryFrame(capture)) != NULL )
    {
    /*    cvLogPolar( bgr_frame,
                    logpolar_frame,
                    cvPoint2D32f(bgr_frame->width/2, bgr_frame->height/2),
                    40,
                    CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS );
    */
        cvWriteFrame( writer, bgr_frame );

    }//

    cvReleaseVideoWriter( &writer );
    cvReleaseImage( &logpolar_frame );
    cvReleaseCapture( &capture );

    return(0);

}

Topic archived. No new replies allowed.