halfsize

halfsize / comparison

halfsize vs FFmpeg vs HandBrake

They are not three competitors. FFmpeg is the encoder, HandBrake is a GUI in front of it, and halfsize is a wrapper that does the size arithmetic and the quality check. The useful question is not "which is better" but which number do you control: quality or size?

Side by side

-crf-b:v 2-passHandBrakehalfsize
What you controlqualitysizequality (or avg bitrate)size
Hits an exact sizenoclose, after you do the mathsno target-size box since 0.101–3% under, automatically
Resolution decisionmanualmanualmanual (filters only)picked from the budget
Overshoot handlingre-encode and guess againre-encode with a lower bitratethe same loop, in a GUIre-encodes once, then reports
Quality measurementlibvmaf, by handlibvmaf, by handnone built inVMAF + SSIM + a verdict
Installpackage managerpackage manager~150 MB installernpx halfsize
Best atarchives, mastersscripted capsbrowsing, previewing, editing"make this fit 20 MB"

The only axis that matters

Constant quality and constant size are opposites. -crf 23 holds the picture quality and lets the byte count land wherever the content dictates: the same 23 on a talking head and on a fireworks clip can differ by 4×. -b:v 2460k holds the byte rate and lets the quality land wherever the content dictates.

An upload form with a hard cap is a size problem. Every tool below can solve it; only some of them ask you to do the solving.

FFmpeg -crf: right when size does not matter

$ ffmpeg -i input.mp4 -c:v libx264 -crf 23 -preset medium -c:a aac -b:a 128k out.mp4

One pass, no log files, no arithmetic. For a master file or an archive, this is the correct command and you should stop reading. It is the wrong command the moment a form says 20 MB, because you cannot know the output size without encoding it.

FFmpeg two-pass: correct, but you are the missing half

$ ffmpeg -y -i input.mp4 -c:v libx264 -b:v 2460k -pass 1 -an -f mp4 /dev/null
$ ffmpeg -i input.mp4 -c:v libx264 -b:v 2460k -pass 2 -c:a aac -b:a 128k -movflags +faststart out.mp4

To run that correctly you have to:

  1. Probe the duration and the real audio bitrate.
  2. Compute the budget and subtract container overhead.
  3. Decide whether 1080p fits that budget, or whether 720p would look better at the same bytes.
  4. Encode, check the size, and adjust if it overshot.
  5. Measure VMAF to know what it cost.

Steps 1–4 are the whole product. They also break the moment the input changes: the next clip has a different duration, a different audio track, and needs a different bitrate. That is why people end up guessing CRF instead — and why the guess keeps missing.

HandBrake: the same two ideas in a window

HandBrake exposes quality (RF) and average bitrate with 2-Pass Encoding. It lost its target-file-size control in 0.10 back in 2014, so "set the size in HandBrake" describes a version that no longer ships. It is the right tool when you want to scrub through the timeline, pick a range, check a preview frame and queue ten files. It does not compute the budget for you, choose a resolution for you, or tell you what the picture lost.

More detail: HandBrake and the 20 MB cap.

halfsize: it does not encode differently, and that is the point

Underneath, halfsize runs the same libx264/libx265 two-pass encode you would type yourself. The difference is everything that surrounds it:

$ 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

What halfsize does not do

Pick by situation

SituationUseWhy
A form or chat app says 20 MBhalfsizeIt solves for size and proves the quality
Archiving a masterffmpeg -crfQuality is the goal; size is whatever it is
Cutting a clip out firstHandBrake or FFmpeghalfsize does not edit
A script or CI jobhalfsize --jsonPlan, size and VMAF in one document
Hundreds of files overnightffmpeg -crfConstant quality is cheaper than per-file VMAF
A phone video that looks greyhalfsizeHDR is tone-mapped instead of mis-tagged

FAQ

Is halfsize a replacement for HandBrake?

No. HandBrake previews, trims, handles subtitles, chapters and batches; halfsize does one job and skips the rest. If you need to look at the picture before you commit, HandBrake or halfsize --web.

Is halfsize slower than -crf?

Yes, roughly twice as slow plus a quality check, because two passes analyse the file twice. On a 10-minute 1080p clip that is minutes, not hours. The reward is a file that fits on the first try.

Why not just use -fs 20M?

-fs stops writing at the limit and can truncate mid-GOP, leaving a file of the right size that stops playing. It also gives you no control over where bits were spent.

Does H.265 help?

It usually keeps more resolution at the same byte budget, at the cost of playback compatibility. --codec h265 switches the plan; VMAF will show whether it actually helped on your clip.

Can I see what it will do before encoding?

npx halfsize input.mp4 --to 20mb --dry-run prints the bitrate, resolution and warnings in under a second.

Related