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:
- Quality (constant RF in HandBrake's wording, CRF in x264's). Same picture quality, size varies by content — often 2–4× between a talking head and a fireworks clip.
- Average bitrate (kbps) with an optional 2-Pass Encoding checkbox. This is the only mode that points at a size, and it is the one to use for an upload cap.
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:
- Video tab → Video Encoder: H.264 (x264).
- Framerate: same as source, constant. Changing it changes the budget.
- Quality → switch to Average Bitrate, type
2460. - Tick 2-Pass Encoding. Optionally tick Turbo first pass — it only affects pass one.
- 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
- Average is not a ceiling. x264 targets a mean over the clip. A 10-second file gives the rate controller almost nothing to average, so it drifts further than a 10-minute one.
- Container overhead is outside your maths. MP4 headers and the moov atom add 1–2%. If you mux to MKV the overhead moves, and the size moves with it.
- HandBrake re-encodes audio. Whatever the Audio tab says happens; a 96 kbps AAC source re-encoded at 160 kbps eats budget you did not plan for. Match the track you measured.
- Filters change the bitrate. Denoise, deinterlace and crop all make the picture easier or harder to encode. A quality preset applied after the size maths invalidates it.
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:
- Computes the budget from the target, including container overhead and the real audio bitrate of this file, instead of a number you worked out by hand.
- Downscales when that looks better than a starved bitrate: 1080p when the budget allows it, 720p or 540p when it does not. Squeezing 1080p into 800 kbps is how a video ends up soft.
- Re-encodes once if the first attempt lands more than 0.5% over, so you do not run the loop.
- Measures VMAF and SSIM, then prints a verdict in words: indistinguishable, slight softening, visible loss.
- Knows the caps:
--for discord,--for wechat,--for whatsapp,--for email,--for outlook,--for twitter.
$ 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:
| Target | Output | Resolution | Video bitrate | VMAF |
|---|---|---|---|---|
| 20 MB | 19.45 MB | 1280×720 | 2.46 Mbps | 88.3 |
| 16 MB | 15.59 MB | 960×540 | 1.94 Mbps | 84.8 |
| 10 MB | 9.77 MB | 960×540 | 1.17 Mbps | 82.9 |
| 5 MB | 4.93 MB | 640×360 | 0.55 Mbps | 72.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.