-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

average
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

  1. Cap the peaks

    -maxrate sets the ceiling and -bufsize how 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.mp4
  2. Use 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.mp4
  3. Hit 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

The flags in these commands
FlagWhat it doesUsed here
-b:v 2MTarget average video bitrate, here 2 Mbit/sAverage, capped, two-pass
-maxrate 2MCeiling for the bitrate; needs -bufsizeCapped, CRF capped
-bufsize 4MHow much video the ceiling is measured overCapped, CRF capped
-crf 23Quality target instead of a bitrate; 23 is the libx264 defaultCRF capped
-pass 1, -pass 2Runs the analysis pass, then the encode that uses its logTwo-pass
-an -f null /dev/nullSkips the audio and throws away the first pass's outputTwo-pass
-b:a 128kAudio bitrate; count it when you work out a file sizeAll

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.

terminalTry it
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"]
  }'
output.mp4 from the API: -b:v 2M with -maxrate 2M -bufsize 4M averaged about 1.8 Mbit/s, about 6.8 MB.Input: video.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.

Ready to build?

Ship video from your app today

Your first $0.50 is free, and one key covers every endpoint.

Moonlit lake with a lit cabin under the mountains