Two-pass encoding for target file size
compression
// what it does
Runs a two-pass encode to hit a specific average bitrate (-b:v 1M) accurately. Pass 1 analyzes the whole file and writes stats to a log, discarding output via -f null /dev/null; pass 2 reads that log and allocates the bit budget across scenes for better quality than single-pass at the same size. Use this when the deliverable has a hard size cap and you compute the bitrate from target_size / duration.
// shell
$ ffmpeg -i input.mp4 -c:v libx264 -b:v 1M -pass 1 -f null /dev/null$ ffmpeg -i input.mp4 -c:v libx264 -b:v 1M -pass 2 output.mp4// gotcha
Both passes must use identical encoding settings or the stats are meaningless, and pass 1 writes ffmpeg2pass-0.log (plus a .mbtree file) in the working directory that you should clean up. On Windows the pass-1 null sink is -f null NUL, not /dev/null.