views:

632

answers:

3

I am writing a video using OpenCV on linux machine. I want to read the same video using OpenCV on a windows machine. I am not able to do this using the standard codecs provided in openCV. Can anybody suggest how I can read/write videos across the two platforms?

+1  A: 

I don't think the problem is with OpenCV, I think it is with codecs, as you mentioned. I also don't think OpenCV comes with codecs... double check that you have the proper codecs installed under Windows.

Did you look at the documentation on video codecs?

emddudley
+1  A: 

Yes, you are right.. openCV does not come with codecs .. it uses "ffmpeg" in linux and "Video for windows" in Windows as the backend to read/write videos. I did look at the documentation on video codecs and tried the ideas there but they don't work. Specifically, I am not able to read a video with codec i420/DIB on windows machine. I don't know why.. So i was wondering if anyone else has encountered the same problem or can suggest something new.

+2  A: 

The OpenCV Wiki directly addresses this issue. See http://opencv.willowgarage.com/wiki/VideoCodecs and specifically the heading "Compatibility list."

Unfortunately the only codecs supported on all three platforms (Linux, Windows & OSX) are 'DIB' 'I420' and 'IYUV' which are all uncompressed video codecs and thus make for really huge file sizes.

The wiki also lists some codecs to try that may work on any two platforms but not on all three.

If you decide to use uncompressed video files, you can convert them to something with a smaller filesize once they are on your windows machine using a program like VirtualDub.


Edit: FYI, On Windows I have OpenCV output in Motion-JPEG and then I use VirtualDub in directstream copy mode to resave the file which corrects a bug with the movie's index. These M-JPEG video files then play by default on Mac and Windows.

If I am trying to read video into OpenCV, I often will first convert my video to Cinepak, (using virtual dub, quicktime etc.) and then feed it into OpenCV. I use Cinepak because for some reason Cinepak encoders seem more prevalentthan MJPEG encoders.

AndyL
How do you get opencv to be able to output Motion-JPEG? Mine crashes and says codec not available.
superjoe30
This is the relavent line of code that I use. I'm on Windows XP. `exp->Vid=cvCreateVideoWriter(MovieFileName,CV_FOURCC('M','J','P','G'), 30, cvSize(xdim ,ydim ),0);` I think (although I'm not positive) that the MJPEG encoder comes with OpenCV by default. I always assumed it was OpenCV's MJPEG implementation that was messing up the index file, which is why I have to do a second pass and direct-stream copy with VirtualDub before any other video player will read it.
AndyL