Ask Your Question
0

How to save a video in mp4 format

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

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

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 ( 2016-06-01 16:25:08 -0500 )edit

2 answers

Sort by ยป oldest newest most voted
0

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

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
0

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

Tetragramm gravatar image

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

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

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

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

Seen: 18,087 times

Last updated: Jun 03 '16