In bash
on an Ubuntu 22 LTS system, I have this line to make a timelapse video file from hundreds of collected JPEG images in a folder.
ffmpeg -r 25
-pattern_type glob -i "/some/path/input/*.jpg"
-vf "pad=ceil(iw/2)*2:ceil(ih/2)*2"
-pix_fmt yuvj420p -preset veryslow -qp 0
-movflags +faststart
"/some/path/output/render.mp4"
The input JPEGs are 4K, so the resulting video file in that same resolution, and at high quality (which is desired), renders to a very large video file (~250GB).
Through trial and error, I’ve needed to add the -vf
padding to avoid potential “height not divisible by 2” crashes, and set the pixel format to explicitly use jpeg full colour range yuvj420p
because some of the original JPEG images were making ffmpeg
complain about that.
And since the goal is to eventually use these renders for streaming, -movflags +faststart
was also added.
It’s all seeming to work very well, but just producing very large high quality video files:
So to try address the filesize problem, but sticking to h264, I started reading some tutorials/docs (this one for example) that mentioned running two passes to compress the video more effectively.
This sounded promising, and so to do this all in one step, rather than rendering a video and re-rendering that in two passes to better compress it) I tried this:
ffmpeg -y -r 25
-pattern_type glob -i "/some/path/input/*.jpg"
-vf "pad=ceil(iw/2)*2:ceil(ih/2)*2"
-pix_fmt yuvj420p -preset veryslow -qp 0
-movflags +faststart
-pass 1 -f null /dev/null &&
ffmpeg -r 25
-pattern_type glob -i "/some/path/input/*.jpg"
-vf "pad=ceil(iw/2)*2:ceil(ih/2)*2"
-pix_fmt yuvj420p -preset veryslow -qp 0
-movflags +faststart
-pass 2 -f mp4 "/some/path/output/render.mp4"
But ffmpeg
seems to freak out about the inputs then:
[image2 @ 0x55674a3bc440] Could not open file : /some/path/input/*.jpg
[image2 @ 0x55674a3bc440] Could not find codec parameters for stream 0 (Video: mjpeg, none(bt470bg/unknown/unknown)): unspecified size
Consider increasing the value for the 'analyzeduration' (0) and 'probesize' (5000000) options
Input #0, image2, from '/some/path/input/*.jpg':
Duration: 00:00:00.04, start: 0.000000, bitrate: N/A
Stream #0:0: Video: mjpeg, none(bt470bg/unknown/unknown), 25 fps, 25 tbr, 25 tbn, 25 tbc
Output #0, mp4, to '/dev/null':
Output file #0 does not contain any stream
I’ve tried searching around a bit for if it’s even possible to do two passes with the globbing input method, but haven’t had much luck in finding any documentation or help about it.
So asking here if anyone has any insights? What am I doing wrong? Is this possible?