Can I save H.264/5 data to MP4 without transcoding?

asked 2019-05-15 15:25:59 -0600

I would like to use OpenCV's VideoCapture/VideoWriter to write video stream data (H.264/5) to an MP4 file without encoding/decoding. I can do this with ffmpeg like so:

$ ffmpeg -i <rtsp_url> -vcodec copy -y -rtsp_transport tcp <output_mp4>

How would I do the equivalent using OpenCV? There doesn't seem to be a "Four CC" option for "straight copy without transcoding".

BTW this has also come up for another user on StackOverflow with almost the same use case as mine.

Thanks in advance for any comments or suggestions, I appreciate your help.

edit retag flag offensive close merge delete


To clarify I am asking how I can use VideoWriter or some other OpenCV class to write the file without it going through the process of encoding the data according to the "fourcc" codec argument. For example, maybe there's a fourcc value that will trigger the writer to store the raw data into the MP4 file as-is without any encoding?

James Adams gravatar imageJames Adams ( 2019-05-16 09:05:43 -0600 )edit

In the OpenCV (4.1.0) documentation for VideoWriter is this:

If FFMPEG is enabled, using codec=0; fps=0; you can create an uncompressed (raw) video file.

However, there is no "codec" argument/parameter. Do they instead mean fourcc=0?

I have tried this (fourcc=0; fps=0;) without success via the Python API, perhaps there's more to it that's not yet in the documentation?

James Adams gravatar imageJames Adams ( 2019-05-16 09:12:29 -0600 )edit