View Full Version : Lossless conversion MJPEG to MPEG-4/AVC
john3voltas
31st January 2015, 19:12
Hello.
I have a small Panasonic DMC-S3 camera that can record small video clips using MJPEG.
Resulting clips are usually bad because this camera lacks an optical stabilizer but the worst part is most my other devices (such as my TV's) lack MJPEG compatibility.
So I was looking for a way to retain all (or at least most) quality in the videos and convert them to MPEG4-AVC or something else that my devices can decode.
All my PC's these days only run Linux so it would be great if I could do it with Avidemux or something similar. That is, if it's even possible...
Asmodian
1st February 2015, 04:55
Lossless obviously cannot happen at a similar size. For lossless you could simply use ffmpeg to crf 0. However, this would probably be less compatible and larger than mjpeg.
The best you can do for your goal is use ffmpeg to transcode to H.264 and use a low crf value so the quality looks pretty much the same but not lossless.
Ghitulescu
1st February 2015, 10:44
very simplistic, M_JPEG is to video what JPEG is for photos. It's not lossless.
If ou want to retain the level of quality, you have a few alternatives, but none is suitable for "other devices" that "play something else". :) . You can use these formats to edit them (stabilize, enhance etc.) then convert the videos to a format of your choice, most likely MP4/AVCHD/MKV with video as H.264.
john3voltas
2nd February 2015, 13:48
Lossless obviously cannot happen at a similar size.
Is that so? Is MJPEG so efficient regarding disk usage or is there a different reason?
The best you can do for your goal is use ffmpeg to transcode to H.264 and use a low crf value so the quality looks pretty much the same but not lossless.
But not lossless. :(
Well, if it's my only option...
very simplistic, M_JPEG is to video what JPEG is for photos. It's not lossless.
I didn't say that MJPEG is lossless. What I mean is I am looking for a way to convert from MJPEG to some other codec in a way that I don't loose quality, that's all.
If ou want to retain the level of quality, you have a few alternatives, but none is suitable for "other devices" that "play something else". :)
Not sure if I follow you correctly. Could you please name some of those alternatives?
You can use these formats to edit them (stabilize, enhance etc.) then convert the videos to a format of your choice, most likely MP4/AVCHD/MKV with video as H.264.
This sounds like a good option. Just need to know what are those alternatives that you were referring to.
Ghitulescu
2nd February 2015, 15:39
... convert them to MPEG4-AVC or something else that my devices can decode...
Not sure if I follow you correctly. Could you please name some of those alternatives?
How would I know what are your devices and what they can decode? Or somebody else...
foxyshadis
3rd February 2015, 00:41
There's no such thing as lossless conversion of MJPEG to anything else, except a much larger lossless codec. If it was lossless, it probably wouldn't give you any more compression!
Video encoding is all about balancing quality, file size, your time, and decoder capability, and there are no holy grails of perfection. The best you can do is find the best balance for you, which sounds like it'll be very high quality -- x264 can easily provide perceptually-lossless at a fraction of the size of MJPEG (meaning you'll have to zoom in and use contrast-enhancing tools just to find any difference at all).
However, you wouldn't want to use any of this until you're done editing. Do all of your stabilizing and editing first, either into a lossless format (not another round of MJPEG!) or a script, then encode.
Asmodian
3rd February 2015, 05:05
Is that so? Is MJPEG so efficient regarding disk usage or is there a different reason?
The transcoding section at Wikipedia's Generation Loss (http://en.wikipedia.org/wiki/Generation_loss) article is a good explanation. Note that all the consumer use high compression formats are neither idempotent nor scalable though editing formats might be.
Basically it is a problem caused by the next compression method adding its own new artifacts on top of the mjpeg artifacts.
hello_hello
6th February 2015, 03:59
Is that so? Is MJPEG so efficient regarding disk usage or is there a different reason?
Think of it this way. If you decode an MP3 to wave file the wave file is going to be much larger. You can compress the wave file losslessly, ie flac, but it's still going to be much larger than the original MP3. Going from MP3 to flac would produce the same result, and could be likened to a mjpeg to lossless AVC conversion (or any other lossless format).
If you convert mjpeg to AVC at a high quality, but lossy, you could probably reduce the file size, or at least not increase it, without any quality loss being noticeable. Kind of like converting an MP3 to MP3, or an MP3 to AC3. But similarly each conversion is not exactly the same as the original (lossy). Try converting MP3 to MP3 to MP3 etc and it'll probably only take a few conversions before you can hear the difference, not matter how high the quality.
I see no reason why it couldn't be done with Avidemux, but I don't use it much myself. For lossless x264 you need to use Constant Quantiser single pass encoding with a quantiser of zero.
Normally though, you'd probably use the Constant Rate Factor single pass encoding method. The lower the value the higher the quality, but try a value of 18 to begin with. It's considered to be where the output is mostly "transparent".
(If the GUI is the same as the Windows version, in the x264 encoder configuration, untick "use advanced configuration" and pick a speed preset. Medium is the default. There's no need to get carried away with the slowest speed presets.
http://mewiki.project357.com/wiki/X264_Settings#Ratecontrol
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.