[ros-users] cvCaptureFromAVI returns NULL

Nicholas Butko nbutko at ucsd.edu
Mon Sep 13 21:35:11 UTC 2010


This usually happens with videos using a codec that is not understood by whatever backend you are using. 

Unfortunately, there are videos that can be processed by OpenCV on OSX that can't be processed on Windows, and vice versa, and same for linux. 

FFMPEG should allow you to process many codecs, but certainly not all of them. If the problem persists after compiling WITH_FFMPEG=ON, maybe try re-encoding your video. 

--Nick 



On Sep 13, 2010, at 2:24 PM, beepbeep wrote:

> 
> Hello,
> 
> I've been trying to get the following code working. It's a standard code to
> read AVI files from here:
> http://nashruddin.com/How_to_Play_AVI_Files_with_OpenCV
> 
> Eventually, I want to send this to a camera display in Rviz. 
> 
> #include <ros/ros.h>
> #include "sensor_msgs/Image.h"
> #include "image_transport/image_transport.h"
> #include "cv_bridge/CvBridge.h"
> #include <opencv/cv.h>
> #include <opencv/highgui.h>
> 
> int main( int argc, char** argv )
> {
>          IplImage  *frame;
>          int key;
>           //assert( argc == 2 );
>          CvCapture *capture =
> cvCaptureFromAVI("/home/harish/Desktop/movie.avi");
> 	  printf("Hello1");
>          if( !capture ) 
>          {
> 	  printf("Hello2");	
>          return 1;    
>          } 
>          int fps = ( int )cvGetCaptureProperty( capture, CV_CAP_PROP_FPS );
>          cvNamedWindow( "video", 0 );
>          while( key != 'q' ) {
>              frame = cvQueryFrame( capture );
>              if( !frame ) break;
>              cvShowImage( "video", frame );
>              key = cvWaitKey( 1000 / fps );
>          }
> 
>          cvReleaseCapture( &capture );
>          cvDestroyWindow( "video" );
>          return 0;
>      }
> 
> For some reason, cvCaptureFromAVI returns NULL, because Hello2 is printed in
> the output. 
> The file movie.avi is stored in the bin folder, src folder, and package
> folder as well. I've also tried an absolute path to my Desktop.
> 
> The interesting thing is that the code executes perfectly if compiled using
> g++ in the regular way, independent of ROS. But using rosmake, or just make,
> something happens, and cvCaptureFromAVI returns NULL during execution.
> 
> Any ideas? According to a friend, possibly something to do with rosmake or
> the makefiles is creating trouble..
> 
> Thanks.
> 
> 
> 
> 
> 
> 
> 
> -- 
> View this message in context: http://ros-users.122217.n3.nabble.com/cvCaptureFromAVI-returns-NULL-tp1468798p1468798.html
> Sent from the ROS-Users mailing list archive at Nabble.com.
> _______________________________________________
> ros-users mailing list
> ros-users at code.ros.org
> https://code.ros.org/mailman/listinfo/ros-users




More information about the ros-users mailing list