Targeting a specific filesize with FFmpeg
FFmpeg doesn't have a way to provide a target filesize directly, so you need to work out your target bitrate instead and use 2-pass encoding.
To get the target bitrate (in kilobits) you'll need:
- Target filesize in kilobits (size in GiB × (8 × 1024²))
- Video duration in seconds
Then you provide the video bitrate (filesize ÷ duration) on both passes with the -b:v
option. The first pass is only for analysis, so we can use -an
to ignore the audio tracks. It will write out a .log
and a .log.mbtree
file, both of which can be safely deleted when you're done.
ffmpeg -i input.mkv -b:v 6298k -pass 1 -an -f mp4 /dev/null ffmpeg -i input.mkv -b:v 6298k -pass 2 -c:a aac -ac 2 output.mp4