Tool

Black Bar Auto-Detect and Crop Value Calculator

To cut off the black bars above and below widescreen video, or on the left and right of 4:3 video, you need a crop=w:h:x:y value. Pick a file and the tool grabs frames from several places in the video, measures the bar thickness, filters out false detections from dark scenes, and gives you the values in ffmpeg and HandBrake format. The video is read only inside this browser.

After changing a setting, pick the file again to analyze it anew. The video is not sent anywhere.

How are the values decided?

  1. Sample times: The first and last 5% of the video are skipped, and one frame is taken at each of the evenly spaced points (8, 12, 20 or 30) in the rest. This is meant to avoid sections such as opening logos and end credits, where the bars can look different.
  2. Measuring the bar thickness: The frame is converted to brightness, and the first row (or column) that has pixels brighter than the black threshold (24 by default) in at least 1% of its length (minimum 2 pixels) is treated as the edge of the picture. Top, bottom, left and right are counted separately. Large video such as 4K is read downscaled by a whole-number factor and the values are multiplied back to the original size, so the values get coarser by that much.
  3. Excluding dark scenes: If fewer than 3% of the pixels in the whole frame are brighter than the threshold, the frame is dropped as ‘too dark’ and does not vote. In a dark scene the edge of the picture also looks black, so the bars are measured thicker than they really are.
  4. Voting: For each of top, bottom, left and right, the tool picks the value on which the most frames land within ±2 px, and on a tie uses the value that crops less. If you choose ‘Conservative’, it uses the value that crops the least among the usable frames.
  5. Rounding to even numbers: In 4:2:0 video the color information is in units of 2 pixels horizontally and vertically, so odd crop values tend to cause trouble. The bar thickness is rounded down to an even number (cropping slightly less) so that the width and height also come out even.

How do you use the result?

  • ffmpeg: Use the generated command as is, or lift just the crop=… out of -vf and put it into another command. When you combine it with other filters (such as scale), putting crop first is usually the way to go. To assemble a full command, see the ffmpeg command builder, and for CRF see the CRF recommender. The -crf 20 in the command is just an example value.
  • HandBrake: Switch the crop to ‘Custom’ and enter the same numbers for top, bottom, left and right. On the command line the format is --crop top:bottom:left:right; the crop options can differ by version, so check with HandBrakeCLI --help. HandBrake has its own automatic crop, but the values from this tool are useful when you want to check separately what was detected, or use the same values for many files.
  • Cross-check with cropdetect: Below the tool you get a cropdetect command with your file name in it. If the crop=w:h:x:y lines in its output differ a lot from this tool’s values, the scenes in that section may be unusual. Change the -ss time and run it at a few places.
  • Multiple-of-16 alternative: If the width and height are not multiples of 16, codecs that work in 16×16 blocks, such as H.264, pad the edge blocks. This site has no numbers showing that this affects quality much, so you can usually use the recommended values as they are. Pick the alternative when you worry about compatibility with older devices or editing software.

How much file size does cropping save?

The tool shows the percentage of pixels removed (arithmetic on the picture area) in the result. But that does not mean the file size, or the bitrate needed for the same quality, shrinks by the same percentage. Pure black bars have no motion and no texture, so they are an area that compresses very efficiently, and removing them may not save that much. This site has not measured file size or VMAF before and after cropping, so it gives no figure for the savings. How quality turns out at a given number of bits per pixel can be seen on the measured curve in the bits-per-pixel judge. To compare before and after on your own video, encode twice with the same CRF and measure the file size. Note that VMAF cannot be compared directly when the frame sizes differ, so you need to align both to the same region before measuring.

Watch out in these cases

  • Videos whose aspect ratio changes from scene to scene: Some films and documentaries use more of the screen in only some scenes. Cropping with a single value cuts off the top and bottom of those scenes. The tool warns you when it finds such frames, and lets you choose the ‘Conservative’ value.
  • Videos with subtitles or logos inside the bars: If a subtitle or a broadcaster logo sitting on the bars is bright, that row is read as content. In that case the crop value comes out smaller. If the subtitles are inside the bars, cropping removes them too, so check what you need them for.
  • Blurry bars: In old or heavily compressed sources the bar edges are smeared, so the values wobble by a few pixels. Try raising the black threshold to 32 or 48. The downside is that it may treat the edges of dark scenes as bars more often.
  • Videos with many scene changes, such as variety shows and commercials, are more stable with 20 to 30 samples. More samples take more time.

Limitations worth knowing

  • This verdict follows rules this site chose. The brightness threshold, the 1% rule, the 3% criterion and the ±2 px vote are not values whose accuracy was verified on a set of real videos. Check the result once with the preview rectangle and with cropdetect before using it.
  • Video that the browser cannot open (HEVC, MKV, ProRes and so on depend on the browser and device) cannot be analyzed. You can see which codecs your browser opens in Codec Support Check. In that case, use ffmpeg’s cropdetect directly.
  • The size the browser sees can differ from the size stored in the file (width and height in ffprobe). That is the case for non-square-pixel video such as DVD, and for phone video with rotation metadata. In those cases, enter the ffprobe values in the ‘Stored resolution’ fields in the tool to convert. For rotated video, the orientation ffmpeg sees may differ from the one the browser sees, so be sure to check the result.
  • Brightness is calculated from the picture read as 8-bit. HDR and 10-bit video are also read by on-screen brightness, so the ‘black threshold’ number does not correspond directly to the source’s bit depth. The black-level difference between limited range and full range is not taken into account either.
  • Cropping re-encodes the video once (it cannot be used together with -c copy). Quality, file size and time were not measured.
  • The video file is not sent to a server, and this tool does not modify or save the file. When the analysis finishes, the temporary address the browser was using is released.