5

I'm attempting to take a set of images taken at 1-second intervals to form a timelapse video. I figured this would be easy with ffmpeg, but i'm running into cryptic errors.

All the images are yuv420 jpegs, taken from an android camera. They're saved as individual jpegs in a folder, they're all identically sized and formatted. They are named as a sequence of 7-digit names, starting at zero (so "0000000.jpg" to "0001000.jpg", as an example).

This is my string (folder names redacted for clarity):

avconv -r 1 -f image2 -i %07d.jpg -vcodec libx264 -crf 18 -preset slower video.mp4

Seems great, i see plenty of posts from people who say that works for them.

However ffmpeg gives me this (bold indicates error)

ffmpeg version 0.8.5-6:0.8.5-1, Copyright (c) 2000-2012 the Libav developers
  built on Jan 13 2013 12:05:48 with gcc 4.7.2
*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.
[mjpeg @ 0x233aea0] overread 8
Input #0, image2, from '%07d.jpg':
  Duration: 00:00:00.04, start: 0.000000, bitrate: N/A
    Stream #0.0: Video: mjpeg, yuvj420p, 640x480 [PAR 1:1 DAR 4:3], 25 tbr, 25 tbn, 25 tbc
File 'video.mp4' already exists. Overwrite ? [y/N] y
[buffer @ 0x233b340] w:640 h:480 pixfmt:yuvj420p
[libx264 @ 0x2339fa0] using SAR=1/1
[libx264 @ 0x2339fa0] using cpu capabilities: MMX2 SSE2Fast FastShuffle SSEMisalign LZCNT
[libx264 @ 0x2339fa0] profile Main, level 3.1
[libx264 @ 0x2339fa0] 264 - core 123 r2189 35cf912 - H.264/MPEG-4 AVC codec - Copyleft 2003-2012 - http://www.videolan.org/x264.html - options: cabac=1 ref=8 deblock=1:0:0 analyse=0x1:0x131 me=umh subme=9 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=2 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=0 b_adapt=2 b_bias=0 direct=3 weightb=0 open_gop=1 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=60 rc=crf mbtree=1 crf=18.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.25 aq=1:1.00
Output #0, mp4, to 'video.mp4':
  Metadata:
    encoder         : Lavf53.21.1
    Stream #0.0: Video: libx264, yuvj420p, 640x480 [PAR 1:1 DAR 4:3], q=-1--1, 25 tbn, 25 tbc
Stream mapping:
  Stream #0.0 -> #0.0
Press ctrl-c to stop encoding
[mjpeg @ 0x233aea0] overread 8
frame=    0 fps=  0 q=0.0 Lsize=       0kB time=10000000000.00 bitrate=   0.0kbits/s    
video:0kB audio:0kB global headers:0kB muxing overhead 610.000000%

The import lines (which show up in red) are the ones that say "[mjpeg @ 0x233aea0] overread 8".

This makes me think that perhaps it's trying to read the images as motion jpegs instead of plain jpeg files, and is failing somehow. I've tried with/without "-f image2", with the same result. And i've also tried using avconv, with the same result.

I should note that the images are valid, and if i convert them all to *.png (a costly and time-consuming process) the whole thing works. But i'd prefer to just be able to use the jpegs, without an intermediate conversion. After all, that's what ffmpeg is for, transcoding.

Does anyone have a good way to convert *.jpg to video using ffmpeg?

6
  • First of all thank you for posting the complete output. You're not using FFmpeg, really—you're using a "crippled" and outdated version called ffmpeg from Libav (an FFmpeg fork) that was shipped with Ubuntu. Instead of that, please use a recent static build from their downloads page, or compile it yourself, then try again. Could very well be a bug that was long fixed. Note that MJPEG is fine as decoder.
    – slhck
    Commented Mar 2, 2013 at 21:37
  • By the way: The "overread" error stems from the MJPEG decoder finding too many bits after reading the image block by block. Could also be that the images aren't properly formatted. Could you maybe try re-saving the JPG files, e.g. with ImageMagick's convert <input> <output>?
    – slhck
    Commented Mar 2, 2013 at 21:41
  • Thanks for the tip about libav vs ffmpeg! I've run a subsonic server off the same box, and always had odd troubles with properly transcoding some files. After cleaning off avconv/libav/ffmpeg, and reinstalling the official version, all that is gone. However, the error still remains. Is it possible that the images are formatted incorrectly, if they display fine with browsers/image editors? I'm installing imagemagick as we speak to test further
    – Knetic
    Commented Mar 2, 2013 at 21:53
  • Given that I've never had problems such as this I can only imagine it's the images themselves being the culprit. If you want you could give us the link to one or two images to test (unaltered, i.e. uploaded in an archive)?
    – slhck
    Commented Mar 2, 2013 at 21:55
  • That was it! After mogrify'ing the jpegs and getting the proper ffmpeg, the frames are transcoded to video just like they should be. I think you must have been right about the images being weirdly encoded, because there is a little grey bar at the bottom right of every image, which i assume must be leftover from some improper encoding. If you like, you can post what you said to an answer, and i'll accept it.
    – Knetic
    Commented Mar 2, 2013 at 22:24

1 Answer 1

6

[mjpeg @ 0x233aea0] overread 8 is an error that is thrown when ffmpeg tries to read a JPEG image (or a frame from an MJPEG stream) block-by-block, but there are still leftover bits.

In that case, even though your images might be showing fine in other viewers, it's something FFmpeg can't (or won't) handle. To fix this you need to re-save the images, either as PNGs as you tried before, or as JPEGs. You can do that kind of batch conversion with ImageMagick, for example:

for f in *.JPG; do mogrify "$f"; done

This would re-save the JPEG files under the same name. Note that you'll lose quality in that process, so it's not ideal and I'd go with PNGs as intermediates as they're lossless.

By the way: It's always a good idea to use the latest version of FFmpeg, which you can download as a static build (just download, extract, use), or compile yourself. The packages that come with Ubuntu are always outdated, and – depending on your Ubuntu version – not even the "real" FFmpeg, but the Libav fork (which is fine to use, but one should know the difference).

Don't forget that the images need to have sequential names when you use the %07d.jpg syntax for ffmpeg, without missing numbers. See also the documentation on the image2 muxer for more options.

1
  • 1
    I believe you could also use mogrify -format jpg *.JPG as an alternative to the for loop (but those are always useful), and for others who may not be familiar mogrify (also see -path option) will overwrite the original files as opposed to convert.
    – llogan
    Commented Mar 3, 2013 at 1:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .