Details of FFMPEG build and OpenCV integration is the same as previous post. Not repeating here.
- Setup MinGW-32 environment.
- Download Ogg, Vorbis and Theora from Xiph.org.
- Configure and Build Ogg, Vorbis and Theora from source - in this order.
- Configure and Build FFMPEG-0.8.2 with --enable-libvorbis and --enable-libtheora enabled.
- Copy the ogg, vorbis and theora archive (.a) to OpenCV, in addition to the updated ffmpeg core libraries. Rebuild opencv_ffmpeg with the new OpenCV library.
- Specify codec with fourcc ('t', 'h', 'e', 'o') and output file extension .ogv in call to VideoWriter::open().
Troubleshooting
- Fourcc for theora used in OpenCV 2.3 is 'theo' not 'ther'
- If theora build ended with error in compiling examples, re-configure with --disable-examples flag. This avoids the error and allows the 'make install' to complete without error, thus copying pkg-config files.
- Use --extra-cflags and --extra-ldflags to specify compile options necessary for ffmpeg to build against the vorbis and theora libraries. The flags could be looked up with pkg-config. (Use PKG_CONFIG_PATH if installed in /usr/local or other non-standard locations).
- FFMPEG 0.8.2 build failed with error in ffplay if --disable-avfilter is specified. Patched with '0001-fix-compilation-error-when-disable-avfilters.patch' (see References)
- The order of ogg, vorbis and theora library specified in opencv_ffmpeg build is important. Will failed with missing symbol link-time error if the common libraries are not specified last (like ogg). It is static build. This is what I used: "-lvorbisenc -lvorbisfile -ltheoraenc -ltheoradec -ltheora -lvorbis -logg"
- Encountered ffmpeg error "Application provided invalid, non monotonically increasing dts to muxer in stream 0". This only happen when I set the output frame rate to certain values such as 5-fps, 15-fps. (Other values might fail, but didn't check). Cross-check with the ffmpeg executable built from the same source. There is no error and the following transcoding succeeded.
$ ./ffmpeg.exe -i-an -vcodec libtheora -f ogg -b 500k -r 15 15fps.ogv
Work-around: Noticed that there is a condition check on AVCodecContext->coded_frame->pts before calling av_rescale_q(). (ffmpeg.c line 1312.) Put the same condition to cap_ffmpeg_impl.h. Problem goes away.
Embed HTML Video
- Apache Configuration: 'AddType' directive to make sure the .ogv is sent to the browser with the intended mime-type.
- Uses <video> tag on HTML to embed inline video.
References
- http://www.html5rocks.com/en/tutorials/video/basics/
- http://diveintohtml5.info/video.html
- Patch for ffmpeg 0.8.2: http://ffmpeg.org/trac/ffmpeg/ticket/400
Amazing.
ReplyDeleteIs there any way that something like this would work for python?
I really want to be able to save ogv files from python.
I have not tried python OpenCV. I would like to think that that python API is wrapper that uses the same OpenCV ffmpeg library as the C++ interface. If that's the case, then my suggestion above should work.
DeleteHello,
ReplyDeleteI want to use Theora for my project but was unable to complete your procedure. Can you provide the ffmpeg dll that you built with theora support?
Thanks
Hi,
ReplyDeleteI have uploaded the DLLs I used for OpenCV 2.2 and 2.4.1. You could get them here: http://www.ge.tt/#!/6BeYnja
The link will expire in a week or two. And that's all I could help. Good luck!
Frankie
I have a question for you. If VideoWriter is set, can I just output Mat without converting it into YUV for ogv? Thanks.
ReplyDeleteJP
I did not do anything special about the colorspace regarding to ogv.
DeleteThank you.
ReplyDeletebut I was unable to complete your procedure. me too,
Can you provide the ffmpeg dll.. plz..
jeonikbeom@daum.net
Here it is: http://www.ge.tt/19Ercol
Deletewhat did you do with ffmpeg dll file
Deletehow did you use dll file
Delete