Ask Your Question
0

How to save a video in mp4 format

asked May 31 '16

lm35 gravatar image

Currently I am saving my video using VideoWriter oVideoWriter0(/home/MyVideo0.mp4", CV_FOURCC('M','P','4','2'), 20, frameSize);

But when I run the code (in C++) I am getting error message as

[mp4 @ 0x3b887c0] track 0: could not find tag, codec not currently supported in container

I have already installed ffmpeg. My machine has got Ubuntu 14.04. I wanted to save video file either as mp4 or WebM.

Can someone help me.

Preview: (hide)

Comments

Try CV_FOURCC('A','V','C','1'). I youtube-dl downloaded a video in the mp4 format and then ran it through a identification program and it it came back A V C 1.

Sixteen line down: http://www.ftyps.com/

Down load command: youtube-dl -o destiny.mp4 -f 18 https://www.youtube.com/watch?v=9ZyQK...

keghn gravatar imagekeghn (Jun 1 '16)edit

2 answers

Sort by » oldest newest most voted
0

answered Jun 3 '16

dtmoodie gravatar image

If you have opencv compiled with gstreamer you can try a gstreamer pipeline like the following (not tested, approximately what you would need to do):

std::string pipeline = "appsrc ! videoconvert ! avenc_h264 ! matroskamux ! filesink location=test.mp4";
cv::VideoWriter cam(pipeline);
cam << image;

Quick explanation of what's going on. VideoWriter can be constructed with a gstreamer pipeline string that will use the gstreamer backend for encoding and muxing your file. The pipeline consists of the following elements:

appsrc <-- entrance of the opencv mat into the gstreamer pipeline
videoconver <--- convert rgb8 packed raw image into YUV for encoding
avenc_h264 <---- encode the video into an h264 format
matroskamux <---- mux the video into an mp4 compatible format
filesink <---- save to disk

I can verify and update when I get to my desktop.

Preview: (hide)
0

answered Jun 2 '16

Tetragramm gravatar image

Try OpenH264, which you can download here: https://github.com/cisco/openh264/rel...

Then use the 'X','2','6','4' FourCC.

Preview: (hide)

Question Tools

1 follower

Stats

Asked: May 31 '16

Seen: 25,186 times

Last updated: Jun 03 '16