24

I try to record a Video with the OpenCV Framework an would like to save that into an Matroska(mkv) Container together with some additional data streams.

First I thought using FFmpeg is the way that. But while looking into the OpenCV Sourcecode and searching in the web I found GStreamer.

Because the documentation in GStreamer is much better than the FFmpeg documentation I would prefer using this Framework.

In my understanding GStreamer is primarily used for Streaming, but could also rncode and mux video data.

Is there any disadvantage when using GStreamer instead of FFmpeg?

Thanks in advance Horst

3 Answers 3

24

I try to record a Video with the OpenCV Framework an would like to save that into an Matroska(mkv)

I don't think OpenCV can store video as MKV,

together with some additional data streams.

OpenCV doesn't provide features for this operation.

An easy workaround is to simply call ffmpeg's or gstreamer's cmd-line application to do the conversion for you.

GStreamer has indeed a decent documentation and it can also do the job. The obvious disadvantage is that if you know how to work with FFmpeg, changing to GStreamer will require some extra time to understand how it works since both have completely different APIs: GStreamer architecture was inspired by DirectShow and Quicktime.

The advantage is that GStreamer (besides being cross-platform as well) is used on several big projects and getting to know GStreamer will certainly add a great skill to your programming arsenal.

1
  • 2
    OpenCV builds its data output storing on the concept and pattern of proxies. You can use a Ffmpeg proxy, a Gstreamer proxy, or even an images proxy, sort of a zero proxy that works with (possibly among others) JPEG images. Look it at this paste of the cvCreateVideoWriter function. For instance me use to configure a vanilla OpenCV without big deal of a configuration with many proxies, and just work with images and do the video multiplexing and demultiplexing invoking Ffmpeg externally.
    – 1737973
    May 20, 2014 at 14:09
3

You can use an OpenCv VideoWriter using either ffmpeg or gstreamer backend and compare. For example (you may adapt to your platform plugins and video mode):

# Using ffmpeg backend
cv::VideoWriter ffmpeg_h264_writer ("test-ffmpeg-h264-writer.mkv",
   cv::CAP_FFMPEG,
   cv::VideoWriter::fourcc ('X', '2', '6', '4'),
   fps,
   cv::Size (width, height));

# Using gstreamer backend:
cv::VideoWriter gst_omxh264_writer ("appsrc ! queue ! videoconvert ! video/x-raw,format=I420 ! queue ! omxh264enc ! video/x-h264,format=byte-stream ! matroskamux ! filesink location=test-gstreamer-omxh264-writer.mkv ",
   cv::CAP_GSTREAMER,
   0,
   fps, 
   cv::Size (width, height));

where width and height are integer values and fps is a float value.

0

I see no disadvantage using gstreamer. In fact the way I see is gstreamer is a framework not just as a tool or a single purpose library. You can use it to develop your own plugins that can seamlessly hook into gstreamer pipeline.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.