Cheatsheet Pages / FFmpeg Cheatsheet
How to encode a video to an exact file size — two-pass FFmpeg
The file must be exactly X MB — for example an upload limit — and a single pass cannot promise that.
ffmpeg -y -i input.mp4 -c:v libx264 -b:v 1M -pass 1 -an -f null /dev/null && \
ffmpeg -i input.mp4 -c:v libx264 -b:v 1M -pass 2 -c:a aac -b:a 128k output.mp4
# -an = no audio on pass 1; /dev/null discards the first-pass output
Good to know
-an drops audio on pass 1; the first-pass output goes to /dev/null, only the statistics matter.
