-b:v 2M averages 2 Mbit/s over the whole file; add -maxrate 2M -bufsize 4M to cap the peaks, and the average lands about a quarter lower. ReelSDK runs the capped encode for $0.02 per compute minute, under three quarters of a cent for a 28 s video.
Set the video bitrate with ffmpeg
Aim at a file size and two passes land within 2% of it; give CRF 23 the same cap and it averages about 1.6 Mbit/s. ReelSDK runs one ffmpeg command per job, so two-pass stays on your machine: its API refuses -pass.
GuidesUpdated
ffmpeg -i input.mp4 -c:v libx264 -b:v 2M \
-c:a aac -b:a 128k avg.mp4-b:v is a target for the whole file. Hard scenes get more, easy ones less, and the average lands within a fraction of a percent of a 2M target.
Variations
The other commands you will need
Cap the peaks
-maxratesets the ceiling and-bufsizehow much video it is measured over. With the cap equal to the target, hard scenes can't borrow from easy ones, so the average fell about a quarter below the target.capped ffmpeg -i input.mp4 -c:v libx264 -b:v 2M -maxrate 2M -bufsize 4M \ -c:a aac -b:a 128k output.mp4Use a quality target with a ceiling
The FFmpeg H.264 guide suggests this for streaming: aim for CRF 23 and let the encoder raise the CRF where the bitrate would go over the cap. Ours averaged about 1.6 Mbit/s.
crf-capped ffmpeg -i input.mp4 -c:v libx264 -crf 23 -maxrate 2M -bufsize 4M \ -c:a aac -b:a 128k crf-capped.mp4Hit a file size with two passes
The first pass only analyzes the video; the second encodes with what it learned. We aimed at 8 MB and landed 1.6% over. Both passes together took about a quarter longer than one.
two-pass ffmpeg -y -i input.mp4 -c:v libx264 -b:v 2158k -pass 1 -an -f null /dev/null && \ ffmpeg -i input.mp4 -c:v libx264 -b:v 2158k -pass 2 \ -c:a aac -b:a 128k two-pass.mp4
The flags
The flags in these commands
| Flag | What it does | Used here |
|---|---|---|
-b:v 2M | Target average video bitrate, here 2 Mbit/s | Average, capped, two-pass |
-maxrate 2M | Ceiling for the bitrate; needs -bufsize | Capped, CRF capped |
-bufsize 4M | How much video the ceiling is measured over | Capped, CRF capped |
-crf 23 | Quality target instead of a bitrate; 23 is the libx264 default | CRF capped |
-pass 1, -pass 2 | Runs the analysis pass, then the encode that uses its log | Two-pass |
-an -f null /dev/null | Skips the audio and throws away the first pass's output | Two-pass |
-b:a 128k | Audio bitrate; count it when you work out a file size | All |
Sources: FFmpeg H.264 encoding guide, ffmpeg codec options, checked November 2026.
Which one to use
For a fixed quality at whatever size it takes, skip the bitrate and use CRF; the CRF guide measures the sizes. Add -maxrate and -bufsize when a player or a platform limits the bitrate. Use two passes when the file has to fit a size, like an upload limit.
Two-pass doesn't buy quality. The FFmpeg H.264 guide puts it plainly: it gives no better quality than CRF, it only hits a size more accurately. Its other warning is about caps: libx264 does not strictly control the maximum bit rate, so check the result if a hard limit matters.
Work out the bitrate from a file size
Bitrate is file size divided by duration. For 8,000,000 bytes in 28 s: 8,000,000 x 8 / 28 = 2,285,714 bits per second. Take away 128,000 for the audio and 2,157,714 is left for the video, which we rounded to 2158k.
The container and the audio encoder add a little, so leave some room: our file came out 1.6% over. For a hard limit, aim a few percent low.
Bitrates the platforms suggest
YouTube's recommended upload settings give 8 Mbps for 1080p at 24 to 30 fps and 12 Mbps at 48 to 60 fps, and 5 Mbps for 720p. Those are upload numbers: YouTube re-encodes everything, so it asks for more than you'd stream. The same capped encode averaged about 1.8 Mbit/s through the API and under 1.5 on our machine, so measure the output rather than trusting the target.
Without installing ffmpeg
The same command as one API call
Send the same args to POST /v1/ffmpeg with the video's URL in inputs. Each job runs ffmpeg 8.1 on a fresh machine at $0.02 per compute minute, billed per second; this capped encode finished in about 20 seconds and cost under three quarters of a cent. A job runs one ffmpeg command, so two-pass doesn't fit: the API answers -pass with 400 INVALID_REQUEST and args[6]: -pass is not supported.
curl "https://api.reelsdk.com/v1/ffmpeg?wait=60" \
-H "Authorization: Bearer $REELSDK_KEY" \
--json '{
"inputs": {
"input.mp4": "https://api.reelsdk.com/f/lib/out/job_x5wepdaqkop4tepq05xp/video.mp4"
},
"args": [
"-i", "input.mp4", "-c:v", "libx264", "-b:v", "2M", "-maxrate", "2M",
"-bufsize", "4M", "-c:a", "aac", "-b:a", "128k", "output.mp4"
],
"outputs": ["output.mp4"]
}'FAQ
Questions, answered
How do I set the video bitrate in ffmpeg?
Use -b:v, as in ffmpeg -i in.mp4 -c:v libx264 -b:v 2M out.mp4. It's an average target: our 28 s clip came out within a fraction of a percent of 2 Mbit/s.
What does -bufsize do in ffmpeg?
It sets how much video -maxrate is measured over. The FFmpeg H.264 guide's example, -maxrate 1M -bufsize 2M, enforces the 1 Mbit/s rate across each 2 Mbit of video.
How do I make a video a specific file size with ffmpeg?
Work out the video bitrate as size x 8 / duration minus the audio bitrate, then encode in two passes. We aimed at 8 MB with -b:v 2158k and landed 1.6% over.
Is two-pass better than CRF?
Not for quality. The FFmpeg H.264 guide says two-pass gives no better quality than CRF; it hits a file size more accurately.
Can I set the bitrate with an API?
Yes. POST https://api.reelsdk.com/v1/ffmpeg runs ffmpeg 8.1 on a fresh machine per job for $0.02 per compute minute, billed per second, and failed jobs are free. Use one pass with -b:v or -crf plus -maxrate; -pass is refused.
- Choose a CRF value in ffmpegWhat CRF does in libx264, the file size and VMAF score for CRF 18, 23, 28 and 33 on one clip, and how x265's scale differs.
- Compress a video with ffmpegShrink a video with ffmpeg: CRF 28 in x264 or x265, a smaller frame or a slower preset, with the size and quality each one gets you.
- Encode H.265 (HEVC) with ffmpegEncode HEVC with libx265: CRF 28 against x264 CRF 23 on one clip, the hvc1 tag Apple players need, and 10-bit output.
- Change the frame rate with ffmpegConvert a video to 24, 30 or 60 fps with the fps filter, see how -r differs, and make smooth 60 fps with minterpolate.
- Video compressionCompress a video to a size budget in one ffmpeg call: a 129 MB 1080p clip fits a 5 MB target at 4.6 MB, for under 1 cent.
Ready to build?
Ship video from your app today
Your first $0.50 is free, and one key covers every endpoint.
