[FFmpeg-user] Can you encode lossless Motion JPEG 2000 videos with ffmpeg using the right command line arguments?

David Rice daverice at mac.com
Tue Jun 19 04:05:31 CEST 2012

On Jun 18, 2012, at 9:17 PM, Gabri Nurtinaz Shally wrote:

> On Jun 19, 2012 8:00 AM, "Shyamal Chandra" <shyamalc at gmail.com> wrote:
>> Hi,
>> Can you encode lossless Motion JPEG videos with ffmpeg using the right
>> command line arguments?
>> I want to convert an uncompressed AVI into a lossless Motion JPEG 2000.
> yes, you can, since mjpeg can be found in "ffmpeg -codecs" output. you can
> try:
> ffmpeg -i yourfile.avi -vcodec mjpeg -acodec copy output.mkv
> FYI, JPEG itself is a lossy format, so overall it is not a lossless video.
> for me, i'll choose h264 for same bitrate.

Motion JPEG is a lossy codec.
Motion JPEG 2000 is a container format primarily (or perhaps solely?) for containing jpeg2000 encodings.
jpeg2000 is a codec that could be used in either lossy or lossless modes.

Since you're interested in lossless encoding, I presume you're interested in Motion JPEG 2000 and/or jpeg2000. FFmpeg does not support writing Motion JPEG 2000 files but can read them. If you need Motion JPEG2000 you could look at frames_to_mj2 in http://code.google.com/p/openjpeg/. FFmpeg can encode lossless jpeg2000 with either its included, but experimental, jpeg2000 codec (listed as 'j2k') or via libopenjpeg if you compile it with --enable-libopenjpeg.
If you compile with openjpeg you could try:
ffmpeg -i file.avi -map 0 -c:v libopenjpeg -c:a copy lossless.mov

If not, then try:
ffmpeg -i file.avi -map 0 -c:v j2k -strict experimental -c:a copy output.mov

Note that the j2k and libopenjpeg versions of the jpeg2000 encoder support different sets of pixel formats. For instance libopenjpeg can encode yuv410p but the j2k codec would format this to yuv444p. If your goal is to losslessly encode the source video so that both the source and resulting lossless file decode to the same pixels then watch ffmpeg's reporting closely. You could also use ffmpeg's framemd5 format to make sure that the source and lossless version decode to the same values. From the example above, these two commands should yield the same result:
ffmpeg -i file.avi -map 0:v:0 -f framemd5 file.avi.framemd5
ffmpeg -i output.mov -map 0:v:0 -f framemd5 output.mov.framemd5


More information about the ffmpeg-user mailing list