What is the best way to losslessly compress MJPEG to MP4?

8

4

I have a few digital camera movies recorded in MJPEG that are taking a few GB of storage space. I would like to better compress them, but losing as little detail as possible, or none.

Since MJPEG doesn't compress across frames, I think that any modern movie codec would do a better job, wouldn't it?

Would the following ffmpeg command do what I expect?

ffmpeg -i input -c:v libx264 -preset veryslow -qp 0 output.mp4

lpacheco

Posted 2016-02-15T13:52:34.703

Reputation: 645

"Since MJPEG doesn't compress across frames" — Do you mean compensate motion in frames? – Quadcubic – 2019-11-10T02:51:40.297

Answers

10

Your command will do it but the chief draw of x264 is the ability to provide high compression while maintaining subjective visual transparency. x264 will be of modest use if you keep to strict lossless mode. I suggest trying the following command:

ffmpeg -i input -c:v libx264 -preset veryslow -crf 18 output.mp4

If you don't like the quality, lower the CRF value.

Gyan

Posted 2016-02-15T13:52:34.703

Reputation: 21 016

Great answer. I'd note that at CRF 18, any further decrease will probably be unnoticeable. CRF 18 is said several times in the documentation that it is virtually lossless, meaning it's as close to the original it's going to get. If you want true lossless, lower it all the way to 0, but you'll probably end up with files larger than the mjpegs.

– 287352 – 2017-04-19T22:41:43.080

0

To store video data in H.264 without losing quality, you'd do:

ffmpeg -i input -c:v libx264 -crf 0 output.mp4

This not only retains the perceptual quality but also doesn't let the video to loose any bit.

Quadcubic

Posted 2016-02-15T13:52:34.703

Reputation: 175