How to add encoders/codec to opencv - c++

So I am trying to use opencv VideoWriter but the thing is it only has about 5 codec options and does not have the codecs I would like to use such as HFYU (which support an alpha channel).
I want to know what exactly I need to do to get opencv to be able to use more codecs.
The codecs I can currently see (when passing -1 to videowriter) are:
Intel IYUV codec
Intel IYUV codec
Microsoft RLE
Microsoft Video 1
Lagarith Lossless Codec
Full Frames (Uncompressed)
Thanks in advance.

Related

OpenCV VideoCapture using H.264 Camera

I've got an embedded linux device with a USB Camera attached which provides an MJPEG as well as an H.264 stream. Until now, I used the MJPEG stream (device index 0) to initialize my VideoCapture object and to read frames from the camera. The problem is that the CPU of the device isn't exactly powerful, so decoding utilizes a lot of it, which is why I want to use the H.264 stream (device index 2) that the camera already provides. However, OpenCV refuses to accept this format at all.
Aug 23 08:08:17: VIDEOIO ERROR: V4L2: Pixel format of incoming image is unsupported by OpenCV
Aug 23 08:08:17: VIDEOIO ERROR: V4L: can't open camera by index 2
After several online searches I found that you can hint OpenCV to accept H.264 streams by setting the FourCC value of the object cap.set(CAP_PROP_FOURCC, VideoWriter::fourcc('H', '2', '6', '4'));, but this didn't do the trick.
I also tried "avc1", which didn't work as well.
Is there any way how I can use the native H.264 stream of the camera using OpenCV or am I stuck with MJPEG?

Encoding uncompressed avi using RAWVIDEO codec and RGB24

I coded an encoder using FFMPEG (c++). The requirements for this encoder are:
The output format should be uncompressed avi,
Preferably using RGB24/YUV444 pixel format since we do not want chroma subsampling.
Most standard players should support the format (windows media player (WMP), VLC)
Using the encoder I wrote, I can write a number of file types right now:
Lossless H.264 encoded video using the YUV420p pixel format and AVI container. (Obviously not uncompressed and chroma subsampled, however both WMP and VLC play without any problem.)
MPEG4 encoded video using the YUV420p pixel format and AVI container.(Obviously not uncompressed and chroma subsampled, however both WMP and VLC play without any problem.)
AYUV encoded video using the YUVA444P pixel format. (uncompressed as far as I understand and not chroma subsampled. However, VLC does not play this.)
FFV1 encoded video using the YUV444P pixel format. (lossless, and not chroma subsampled. However, WMP does not play this.)
The above is derived from this very usefull post.
So I am now looking into the RAWVIDEO encoder from FFMPEG. I can't get this to work and neither can I find an example in the FFMPEG documentation on how to use this encoder for writing video. Can somebody point me in the right direction or supply sample code for this?
Also, if there is another direction I should follow to meet my requirements feel free to point me to it.
Thanks in advance

what is the 4 char id for mpeg decoder in opencv

I want to create a mpeg4 stream whith the following specs:
Container mp4.mov m4v
Resolution 1920 X 1080
Codec h264 main profile 4.1
I am wondering what CV_FOURCC and file extension should I use?
Any help appreciated.
I am using C++
In general where can find the fourcc for any coded?
If you read a file, you don't need to specify any codec.
If you write to a file, I think you need to specify X264. Full list of FOURCC codes avaliable here.
Some of the common fourCC codes used with OpenCV are mentioned here
http://opencv.willowgarage.com/wiki/documentation/cpp/highgui/VideoWriter
Here is a much longer list of the FOURCC codes of other codecs.
http://www.fourcc.org/codecs.php
Since you want to use H264, you can use H264 or X264 as the FOURCC codes.

How to encode series of images into VP8 using WebM VP8 Encoder API? (C/C++)

How to transcode RGB images into VP8 frames (Keyframe + some dependent frames)?
So I created some images how to turn tham into VP8 now?
The easiest way to go is to use ffmpeg.
The latest release of ffmpeg (0.6) now supports the VP8 codec, and building it is now easy.
Then, ffmpeg makes it simple to gather individual frames into a movive. Here is a tutorial, but you can google for more results.
First, you need a codec library for VP8:
http://www.webmproject.org/code/build-prerequisites/
Using libvpx API you can then encode your RGB frames into VP8 frames.

FFMpeg encoding RGB images to H264

I'm developing a DirectShow filter which has 2 input pins (1 for audio, 1 for video). I'm using libavcodec/libavformat/libavutil of FFMpeg for encoding the video to H264, audio to AAC and mux it/stream using RTP. So far I was able to encode video and audio correctly using libavcodec but now I see that FFMpeg seems to support RTP muxing too. Unfortunatelly, I can't find any example code which shows how to perform H264 encoding and RTP muxing. Does anybody know good samples?
Try checking out the code in HandBrake. Specifically, this file muxmp4.c, which was a jem I found working with FFMpeg / RTP. Be sure and use av_interleaved_write_frame() and the extradata fields correctly. Those were some key differences I remember for RTP.
Still, I had some stability issues with RTP/RTSP with FFMpeg, (I'm sure it's getting better). I had much better luck with live555, and you can look at the code in VLC and MPlayer for good examples on how to use it.