Shrink a video's file size
Shrinks a video's file size with libx264's CRF quality setting, trading a small, controllable amount of quality for a much smaller file.
Last updated
ffmpeg -i input.mp4 -c:v libx264 -crf 28 -preset slow -c:a aac -b:a 128k output.mp4
How it works
-crf 28 is the main lever: libx264's Constant Rate Factor scale runs roughly 0 (lossless, huge) to 51 (unwatchable), with 23 as the encoder's own default and 28 landing noticeably smaller with only mild, hard-to-spot quality loss on most content — lower the number for a closer-to-source result, raise it for a smaller file. -preset slow tells the encoder to spend more time searching for a more efficient encoding at that same CRF, which shrinks the file further without changing the quality target — it trades encode time for compression efficiency, not quality for size directly.
-c:a aac -b:a 128k re-encodes the audio track to a fixed 128kbps AAC stream instead of leaving it untouched — video re-encodes typically re-encode the audio too by default at whatever bitrate ffmpeg happens to choose, so stating it explicitly keeps the audio size predictable alongside the video savings.
Watch out for
- →The CRF number is codec-specific and doesn't transfer directly: 28 on libx264 is roughly comparable to 32–33 on libx265 for similar perceived quality — don't reuse the same value if you switch -c:v to libx265.
- →-preset only trades encode SPEED for compression efficiency at a given CRF, it doesn't change the target quality — ultrafast finishes almost instantly with a somewhat larger file at the same CRF; veryslow squeezes out the smallest file but can take many times longer.
- →This always re-encodes, so it's inherently lossy — re-running it on an already-compressed file compounds the quality loss each time; keep the original if you might need to re-derive it later.