Cap output file size with -fs
When the target is a file size, not a duration, the `-fs` flag stops the encode as soon as the output reaches the cap. It is most useful for fitting a video into a service that limits upload size (email, chat, social) without computing the bitrate manually.
The command
ffmpeg -i in.mp4 -fs 100M -c:v libx264 -b:v 2M -c:a aac -b:a 128k out.mp4What it does
The command caps the output at 100 MB. The encoder runs at the specified bitrates until the output reaches 100 MB, then stops. The result is a file that is exactly 100 MB (or just under, depending on the container overhead). For a more precise cap, use a two-pass encode with a target bitrate that matches the desired size: `target_size_MB * 8 / duration_seconds = total_bitrate`.
Requirements
Any input FFmpeg can read. The flag is a no-op for outputs that never reach the cap, so passing `-fs 100M` on a 10 MB file just produces the 10 MB file. The cap is in bytes by default; use `M` for megabytes, `K` for kilobytes, `G` for gigabytes.
Things to avoid
- Expecting an exact size. The cap is a maximum, not a target; the file may be 5-10% smaller than the cap, depending on the encoder's rate control.
- Using `-fs` with a stream copy. Stream copy does not respect the cap because the demuxer reads the source, not the encoded output.
- Forgetting that the cap is in bytes by default. `-fs 100` is 100 bytes, not 100 megabytes.
- Combining `-fs` with `-t`. The first cap reached wins; if the file hits the size cap before the duration cap, the encode stops.