Ask Your Question

How to save a video in mp4 format

asked 2016-05-31 04:32:46 -0600

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.

edit retag flag offensive close merge delete


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:

Down load command: youtube-dl -o destiny.mp4 -f 18

keghn gravatar imagekeghn ( 2016-06-01 16:25:08 -0600 )edit

2 answers

Sort by ยป oldest newest most voted

answered 2016-06-03 13:58:46 -0600

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.

edit flag offensive delete link more

answered 2016-06-02 17:52:12 -0600

Tetragramm gravatar image

Try OpenH264, which you can download here:

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

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2016-05-31 04:32:46 -0600

Seen: 24,462 times

Last updated: Jun 03 '16