Take the 2-minute tour ×
Video Production Stack Exchange is a question and answer site for engineers, producers, editors, and enthusiasts spanning the fields of video, and media creation. It's 100% free, no registration required.

I have a large set of jpgs that I want to convert to a video losslessly (or, at the very least, very close to losslessly as long as the encoding time isn't much higher than otherwise).

Naively, I would think that there should be some codec that can store each individual jpg frames as-is (without recompression), and perhaps achieve some nice compression by replacing some of the frames by just the information on the delta from the previous frame. In my case there are many sequences of frames which are identical to each other, or that have a tiny difference between them.

Is there some codec and suitable settings for ffmpeg that can achieve this?

share|improve this question
    
Related: avp.stackexchange.com/questions/4642/… –  Friend Of George May 16 '13 at 20:36
    
Also Related: avp.stackexchange.com/questions/7300/… –  Friend Of George May 16 '13 at 20:36
add comment

3 Answers

I have a large set of jpgs that I want to convert to a video losslessly

You can probably just mux the jpg images:

ffmpeg -r 30 -i input%03d.jpg -codec copy output.mkv

Then compare the md5sums of each frame with the framemd5 muxer:

$ ffmpeg -i input%03d.jpg -f framemd5 -
0,          0,          0,        1,   460800, 29bcc2db3726c7dfec1826c5740f603f
0,          1,          1,        1,   460800, b5fdc23d93cbd043dc2b9290dc8378f0
0,          2,          2,        1,   460800, ee0709942f24b458fd2380d134dcb59d
...

$ ffmpeg -i output.mkv -f framemd5 -
0,          0,          0,        1,   460800, 29bcc2db3726c7dfec1826c5740f603f
0,          1,          1,        1,   460800, b5fdc23d93cbd043dc2b9290dc8378f0
0,          2,          2,        1,   460800, ee0709942f24b458fd2380d134dcb59d
...

Note that if you omit -r then ffmpeg will use a default of -r 25 for the input.

Also see image2 demuxer documentation and How do I encode single pictures into movies? on more information of how to provide images as input(s).

share|improve this answer
    
could you please clarify what the two framemd5 commands are supposed to achieve beyond merely listing the hashes? how would I get additional compression when identical frames are thus identified? –  GJ. May 18 '13 at 8:54
    
The hashes were included only to show you that the frames are the same as the individual images, so therefore achieving your requirement of storing "each individual jpg frames as-is (without recompression)". –  LordNeckbeard May 18 '13 at 18:24
add comment

You can create an avi animation as a series of png images ( png is lossless so the jpeg => png conversion should not degrade your pictures ):

if your images a named img_0001.jpg

ffmpeg -r 25 -start_number 1 -f image2 -i "img_%04d.jpg" -vcodec png video.avi

where "25" is the frame rate you want in the resulting video. -start_number is not needed if it is 1, but it is useful if your first video number is not 1.

If you want to encode in mjpeg with highest quality command line is:

ffmpeg -r 25 -start_number 1 -f image2 -i "img_%04d.jpg" -vcodec mjpeg -qscale 1 video.avi

And the beauty of the thing is that you can convert the video back to a series a pictures:

ffmpeg -i video.avi "img_series_%04d.png"
ffmpeg -i video.avi "img_series_%04d.jpg"

etc...

share|improve this answer
    
This doesn't really meet the askers needs. He is looking for a way that the frame can be updated loselessly only when the image changes. This means the same image may be used more than once. Also jpeg by nature isn't lossless as I believe it uses jpeg compression even at max quality. –  AJ Henderson May 17 '13 at 13:17
    
Actually I guess he was willing to have some compression, though I'm not sure how it is going to do on long sequences of the same frame. I still think a variable frame rate presentation format is what is needed though I'm not sure if ffmpeg supports any. –  AJ Henderson May 17 '13 at 13:20
    
CorePNG is able to create P frames also. Usually jpeg is not a lossless compression, and I doubt mjpeg can create P frames. I agree I do not answer the question as it is asked, but I give a solution to have a lossless video with ffmpeg. –  Olivier S May 17 '13 at 18:51
add comment

I don't recall what the formats are, but yes, there are an entire class of codecs that are specifically designed for this kind of presentation graphics kind of thing. They actually store a frame and then store how long the frame is displayed for. They fall under the broader category of variable frame rate video.

Hopefully someone else knows of a particular format you can use. I unfortunately only know they exist, I've not used them personally so I don't recall what the details were.

share|improve this answer
1  
I think this should be a comment rather than an answer by its own. It doesn't really contain any info and doesn't answer a question. –  Eugene S May 17 '13 at 7:46
    
@eugenes yeah, I agree it is borderline. Technically the question asked (in part) if such codecs existed. Since there was no answer yet, I wanted to confirm there were and shine what light I could on the direction. In that sense it is an answer. Just not a complete one. –  AJ Henderson May 17 '13 at 13:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.