Ask Your Question

Slow Processing on Rasberry Pi

asked 2013-03-11 16:10:31 -0600

Shinn gravatar image

I'm building an application that takes two video sources, pulls their frames, and places them one after another in a third video, essentially "interweaving" the frames. I had planned on using the Raspberry Pi for this, but the processing speed is unreasonable; it takes five minutes to produce 5 seconds of video.

Is there something I could do to (significantly) speed up the processing time of the application, beyond switching hardware?

Here's the basics of the code:

int framePerFile = 300; /*Put 300 frames in one video file (about 5sec )*/
int videoFile = 0; /*Current video count.*/

/*Get input videos*/
CvCapture *video1;
if( (video1  = cvCreateFileCapture( argv[1] )) == NULL )
    cout << argv[1] << "could not be opened." << endl;
    return( -2 );

CvCapture *video2;
if( (video2  = cvCreateFileCapture( argv[2] )) == NULL )
    cout << argv[2] << "could not be opened." << endl;
    return( -2 );

/*Get the first frame, and video properties from that frame.*/
IplImage *frame = cvQueryFrame( video1 );
double framePerSec = cvGetCaptureProperty( video1, CV_CAP_PROP_FPS );
double framePerSec2 = cvGetCaptureProperty( video2, CV_CAP_PROP_FPS );
CvSize vidSize = cvSize( (int) cvGetCaptureProperty(video1, CV_CAP_PROP_FRAME_WIDTH),
                         (int) cvGetCaptureProperty(video1, CV_CAP_PROP_FRAME_HEIGHT)

/*Create output file*/
char fileName[50];
int fileNameLength;
fileNameLength = sprintf( fileName, "INTERLACE%03d.h263", videoFile );
cout << "Using OpenCV version: " << CV_VERSION << endl;

/*Create video writer with vidSize of original video.*/
cout << "Frames per sec: " << framePerSec << endl
     << "Frames per sec: " << framePerSec2 << endl;

     CvVideoWriter *writer;
if( (writer = cvCreateVideoWriter( fileName, CV_FOURCC( 'U', '2', '6', '3' ), 60, vidSize )) == NULL )
    cout << "An error occured whilst making the video file." << endl;
    return( -2 );
    cout << "Video creation successful!" << endl;

/*Write frames of input files to ouptut file*/
int currFrame = 0;
while( currFrame < framePerFile )
    frame = cvQueryFrame( video1 );
    if( !frame ) break;
    cvWriteFrame( writer, frame );
    frame = cvQueryFrame( video2 );
    if( !frame ) break;
    cvWriteFrame( writer, frame );

    currFrame += 2;

cout << "Video creation complete." << endl;

cvReleaseVideoWriter( &writer );
cvReleaseCapture( &video1 );
cvReleaseCapture( &video2 );

I've tried a few different codecs, with no noticeable difference. I've also run this on a Core 2 Duo running Ubuntu 12.10 with a processing time of approximately 20 seconds; I realize the Raspberry Pi is a single core processor, but I'm hoping to increase performance to under a minute, regardless.

Written in C++, running on the Raspberry Pi (model B, processor overclocked to 1GHz), using OpenCV 2.4.9.

edit retag flag offensive close merge delete



It is probably the video encoding that is so expensive, this takes time even for high end PCs. Try using a different codec, or just write raw images and process them later

awknaust gravatar imageawknaust ( 2013-03-11 17:31:09 -0600 )edit

Your device has some hardware video processing support. I recommend you to find encoder that uses hardware features if it possible and use it. Video encoding is very time consuming feature for such device if you do not use hardware acceleration.

Alexander Smorkalov gravatar imageAlexander Smorkalov ( 2013-03-12 01:43:40 -0600 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2013-03-12 03:12:07 -0600

sammy gravatar image

Most, if not all, modern systems that deal with video (PCs, smartphones, cameras, etc, have a dedicated processor (graphics card) and/or instruction set to speed up encoding/decoding). Even the cheap point-and-shoot cameras have a video processor.

But Rasberry Pi is so cheap because, in part, it lacks any accelerator extensions. It does not even have the NEON SIMD extension. So, make sure you use the cheapest codec available for the platform.

edit flag offensive delete link more


Right, I was afraid of that. Thanks for the explanation.

Shinn gravatar imageShinn ( 2013-03-12 16:23:35 -0600 )edit

any recommendations for a good minimal system for a single channel of video?

shigeta gravatar imageshigeta ( 2014-08-12 14:49:57 -0600 )edit

Question Tools


Asked: 2013-03-11 16:10:31 -0600

Seen: 3,013 times

Last updated: Mar 12 '13