View Full Version : Automatic letterbox/windowbox detection
zambelli
17th May 2007, 02:29
I'm looking for ideas for a script that would automatically detect letterboxed and windowboxed content and crop it down to the just the active video portion.
An example scenario would be broadcast HDTV content, for example. You could have several cases:
1) Letterboxed movie content with an AR bigger than 1.78:1 (i.e. 1.85:1 or 2.35:1). It uses the full HD width but letterboxes the height.
2) Upscaled SD content. With an aspect ratio of 4:3, it uses the full HD height and windowboxes the width.
3) Upscaled letterboxed SD content. The worst kind. It's letterboxed within a 4:3 window which is in turn windowboxed within the HD window.
I'd like to be able to detect all 3 cases and crop the black bars correctly. Assuming only common content ARs (4:3, 16:9, 1.66:1, 1.85:1, 2.35:1) is fine.
zambelli
17th May 2007, 07:07
OK, so here's what I've got so far:
I can use Crop() and AverageLuma() to check whether an area is predominantly black. A black area should have an average luma <= 16ish (probably a few points extra, to make up for quantization errors).
I can determine how wide the black bars are by recursively calling a function that checks whether the area is black (using the method above) and increments the width of the area by 4 or 16 pixels before calling it again. When the AverageLuma crosses a threshhold (16ish), we exit the function and use the last good dimensions.
Repeat same for left and right or top and bottom.
I don't need to check every frame of the video. I can probably just pick 3 or 4 frames (i.e. 25%, 50% and 75% through) and check each. Majority wins.
So here's where I'm stuck... ConditionalFilter(), ScriptClip() and FrameEvaluate() all work on a per-frame basis. I can't crop every frame to a different size as I go, so I need to be able to detect letterboxing first, make a decision for the whole video, and then return the whole video cropped to the detected dimensions. I'm unclear about the order in which I need to evaluate frames, since conditional filters kind of work backwards.
If anyone can help out... I'd really appreciate it. Thanks!
communist
17th May 2007, 08:41
Hmmm maybe I missed something but that sounds to me like a case for AutoCrop() :)
See http://avisynth.org/warpenterprises/
djmasturbeat
24th March 2011, 03:05
old thread, but what the hell... here goes-
i have tried autocrop in meGui (i know, not quite the same as OP), but using it on the Ghost in the Shell Bluray, which is windowboxed. It completely misses the mark.
it crops from the top of the image a bit and worse, crops nothing off the bottom, where the extra 8 pixels in 1088 produce an awful green band at the very bottom in those 8 pixels, which isn't visible when played as a BD on my PC or StandAlone player... I only see them in the elementary stream after demuxing (i have demuxed it, just to confirm, with a eac3to and megui and tsmuxer and tsmuxergui all to same results, no surprise i guess)
i would be interested in a more automated script for cropping, too, but one that may differ from autocrop used in megui. I honestly am not very experienced at writing avs scripts so any help would be appreciated.
Also, i am trying to make a mini BD from scenes i cut from the movie and then demuxed:
since this is windowboxed, and i am cropping some off (green band at bottom) is there a similar tool to "uncrop mkv" except for (h/x) 264 raw streams, or do i need to mux it into mkv, uncrop it, then mux it back into m2ts? I already have the LPCM audio converted with pcm2tsmu, just curious if i can cut out the extra mux to mkv in future projects like this?
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.