AutoCrop

From Avisynth wiki
Jump to: navigation, search
Abstract
Author Glenn Bussell, len0x
Version v1.2
Download autocrop12.zip
Category Borders and Cropping
License GPLv2
Discussion Doom9 Thread - Update

Contents

Description

AutoCrop is an AviSynth filter that automatically crops the black borders from a clip. It operates in either preview mode where it overlays the recommended cropping information on the existing clip, or cropping mode where it really crops the clip. It can also ensure width and height are multiples of specified numbers so the cropped clip can be passed to the video compressor of your choice without problems.

Requirements


Syntax and Parameters

AutoCrop takes 12 parameters, but they are all optional so you can just do AutoCrop() to get a feel for how the filter works. Parameters can either be specified in order or by name. I suggest specifying by name, as there are a lot of parameters!

AutoCrop (clip, int "mode", int "wMultOf", int "hMultOf", int "leftAdd", int "topAdd", int "rightAdd", int "bottomAdd", int "threshold", int "samples", int "samplestartframe", int "sampleendframe", float "aspect")


clip   =
Input clip.


int  mode = 1
  • 0 : Crop - Crops the image
  • 1 : Preview - Suggested cropping information is overlayed on the existing clip, including a crop command that you can use to replace AutoCrop with.
  • 2 : Log - Logs the cropping parameters to the file "AutoCrop.log" in the current directory.
  • 3 : Crop & Log - combination of modes 0 and 2


int  wMultOf = 4
int  hMultOf = 2
Ensures that the width of the cropped clip will be a multiple of the number specified. Use this to ensure that clip is a valid for whatever codec you are going to compress with. hMultOf is the same, but for the height.


int  leftAdd = 0
Forces autocrop to crop an additional 'leftAdd' pixels after it completes auto detection. You can use this option in conjunction with wMultOf. Useful for cropping out bad quality lines on the side of VHS captures.
int  topAdd = 0
Forces autocrop to crop an additional 'topAdd' pixels after it completes auto detection. You can use this option in conjunction with hMultOf. Useful for cropping out bad quality lines on the top of VHS captures.
int  rightAdd = 0
Same as leftAdd but for the right side.
int  bottomAdd = 0
Same as topAdd but for the bottom side.


int  threshold = 40
Threshold is the average luminance a line must have before it's considered non blank. For DVD sources values as low as 20 should work reliably. For VHS sources raising the value may be necessary.


int  sample = 5
The number of frames to examine when determining the cropping information. This directly affects the startup time of the filter. This number dramatically effects the amount of time taken for the filter to startup. Increasing the number to 10 will basically double the startup time.


int  samplestartframe = 0
int  sampleendframe = -1
These parameters set the first and last frame to be looked at when determining the cropping parameters. Defaults are the first frame(0) and last frame(-1).
If you want to take the cropping information from a single frame, set samplestartframe and sampleendframe to the same number and samples to be 1


int  aspect = 0
  • -1 : Maintain aspect ratio of the source clip
  • 0 : Aspect is ignored
  • >0 : Aspect ratio will be set to this. For example for a 4:3 aspect ratio you would pass 4.0/3.0 or 1.33333333333. Note that 4/3 won't work since the .0 is needed to tell AviSynth the value is a float.


Examples

AutoCrop with default values:

AviSource("Blah.avi")
AutoCrop(mode=1, wMultOf=4, hMultOf=2, leftAdd=0, topAdd=0, rightAdd=0, bottomAdd=0, \
         threshold=40, samples=5, samplestartframe=0, sampleendframe=-1, aspect=0)


Changelog

Version       Date            Changes
v1.2 01/03/2005 - fixed bug when preview and actual crop values were different - fixed bug when AR was not properly enforced (rounding errors) - threshold 0 ensures that no cropping is done unless necessary for AR - fixed bug when leftAdd and rightAdd parameters were not properly working in YUY2 mode - wMulfOf and hMultOf cannot be zero now - wMultOf is relaxed to be mod2 for YV12 (previously mod4) - added mode=3 which is mode 0 plus mode 2 (cropping and logging at the same time)
v1.1 06/17/2003 - Added ability to set a range of frames to sample for cropping information. - Reduced default number of frames to sample to 5. - Reduced default threshold to 30, this change and the one above should perform give equal or better performance for DVD sources much quicker. - Minor documentation updates.
v1.0 03/09/2003 - A new version of AutoCrop which solves the YV12 cropping problems found in version 0.51.
v0.51 27/02/2003 - New version 0.51 with (hopefully) working wMultOf and hMultOf in YV12 mode.
v0.5 26/02/2003 - This version (finally) adds YV12 support.
v0.4 01/30/2003 - This version of AutoCrop is compiled for AviSynth 2.5 it will not work with any of the 2.0 releases. - The preview argument (which was a boolean) has been removed and replaced with the new mode argument (which is an int) this was to allow for the implementation of the logging mode and the future blanking mode. - Aspect Ratio support. Support for maintaining and setting aspect ratios is included. - Logging mode. Image is left untouched, cropping information is written to the file "AutoCrop.log" in the current directory.
v0.3 11/05/2005 - Setting wMultOf=width now behaves correctly. ie. Just letterboxes the clip. - Debugging information no longer written to disk.
v0.1 11/03/2002 - Initial release for AviSynth 2.0


Archived Downloads

Version Download Mirror
v1.2 autocrop12.zip autocrop12.zip
v1.1 autocrop_25_dll_20030617.zip
v1.0 autocrop_25_dll_20030309.zip
v0.3 autocrop_20_dll_20021105.zip autocrop_20_dll_20021105.zip


External Links




Back to External Filters

Personal tools