halfsize

halfsize / HandBrake target size

HandBrake: can it hit an exact size?

No. HandBrake asks for a quality level or an average bitrate, and neither is a byte count. Here is what its average-bitrate box actually does, how to land under a 20 MB cap with it, and where the last few percent goes.

The target-size box left HandBrake in 0.10

Older versions had a Target file size control. It was removed in 0.10 (2014) because it was honest about its own limits: the encoder cannot know the byte count until it has finished, so the number moved anyway, and users read the miss as a bug. What is left in the Video tab is:

If a guide tells you to "set target size in HandBrake", it is describing a version that stopped shipping twelve years ago.

Turn a size into a bitrate, then type it in

The arithmetic is the same one FFmpeg needs, because it is the same encoder underneath:

video_kbps = (target_bytes × 8 ÷ seconds) ÷ 1000 − audio_kbps − container_overhead

A 60-second clip at 20 MB (20,000,000 bytes) is 2.67 Mbps total. Subtract 128 kbps of AAC and roughly 1.5% for the MP4 container, and the video stream has about 2.46 Mbps ≈ 2460 kbps.

In HandBrake, for that file:

  1. Video tab → Video Encoder: H.264 (x264).
  2. Framerate: same as source, constant. Changing it changes the budget.
  3. Quality → switch to Average Bitrate, type 2460.
  4. Tick 2-Pass Encoding. Optionally tick Turbo first pass — it only affects pass one.
  5. Audio tab: AAC, 128 kbps. This is the number you subtracted above, so do not leave it on "Auto" and hope.

One pass would have to guess how complex the next scene is. Two passes analyse the whole file first, then spend the budget where the picture needs it — the same reason the FFmpeg version of this guide runs -pass 1 and -pass 2.

Why it still lands at 20.3 MB

Landing 1–3% under the cap is the correct outcome. 19.45 MB is accepted everywhere; 20.01 MB is rejected by the same form.

The loop everyone runs instead

Encode → check the file size in Explorer → go back to the bitrate box → drop it by 5% → encode again. It converges, usually in two or three attempts, and each attempt is a full encode. The part that never gets answered is whether the file that finally fits still looks like the source.

HandBrake does not measure that for you: there is no VMAF or SSIM number on the queue or in the log. You can produce one afterwards with FFmpeg's libvmaf filter, which means keeping FFmpeg around next to HandBrake anyway.

What halfsize does differently

Same encoder, same two passes — the difference is that the bookkeeping is not yours:

$ npx halfsize input.mp4 --to 20mb

  target     20.0 MB
  plan       H.264  1280x720  2.46 Mbps  audio 128 kbps  2-pass
  scale      1920x1080 → 1280x720
  output     input.20mb.mp4

  136 MB  →  19.45 MB   7.0x smaller   2.7% under target
  VMAF 88.3   SSIM 0.971   slight softening

Measured results

60-second 1080p30 source at 18 Mbps, halfsize defaults, one laptop:

TargetOutputResolutionVideo bitrateVMAF
20 MB19.45 MB1280×7202.46 Mbps88.3
16 MB15.59 MB960×5401.94 Mbps84.8
10 MB9.77 MB960×5401.17 Mbps82.9
5 MB4.93 MB640×3600.55 Mbps72.0

What this table is not: a HandBrake benchmark. HandBrake wraps the same x264 build, so at the same preset, tune and bitrate the output is within a few percent — but we have not measured it here, and a made-up comparison row would be worse than no row.

FAQ

Does HandBrake have a target file size option?

Not since 0.10 (2014). Average bitrate plus 2-pass is the closest thing, and it still aims at an average rather than a hard ceiling.

Which is better, quality mode or average bitrate?

Quality mode for archives, average bitrate for a cap. Quality mode spends bits where the picture needs them but gives no size guarantee; average bitrate gives you a size estimate at the cost of a slightly less efficient bit allocation.

Can HandBrake tell me how much quality I lost?

Not by itself. HandBrake has no VMAF/SSIM report. You measure it afterwards with FFmpeg's libvmaf, which halfsize does automatically as part of the same command.

HandBrake vs FFmpeg: same output?

Both can drive x264. HandBrake adds its own defaults for filters, audio and container, and rounds the bitrate to whole kbps, so identical settings rarely produce identical files. The 1–3% under target behaviour is the same.

Is there a GUI for halfsize?

Yes, a local web app: npx halfsize --web. It opens on 127.0.0.1, takes a drag-and-drop, and never uploads anything.

Related