Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Development

Reply
 
Thread Tools Search this Thread Display Modes
Old 19th January 2010, 08:20   #1  |  Link
Lam3rD
Registered User
 
Join Date: Oct 2009
Posts: 47
LameAutoCrop 1.0 (another autocrop during playback)

Background: I wasn't really happy stability of the image with the integrated auto-crop in ffdshow and I decided to try and write alternative script, that should perform better. Later on AutoCropR showed up, but I wasn't too happy with it either, so I decided to share my alternative here. Although it's not 100% perfect it does pretty decent job and delivers much more stable image.

Target videos: SD/ED MPEG-2 (DVD, SVCD, VCD, DVB/ATSC with non-square pixels).
Target displays: Screens, wider than the video file.
Filter Type: Spatial-only
Method: Auto-cropping vertically to fit it on your screen, but only if needed. It only has 2 possible states - 4/3 and your screen aspect ratio giving it great stability.

Source: (there is also some help in the AVSI put as an attachment)
Code:
Function LameAutoCrop(clip clp, int mode, int OverCrop, int Tresh, float DAR)
{
	Mode  =  Default(Mode,3)       #Screen shape 3=16/9 | 2=16/10 | 4=3/2
	OC    =  Default(OverCrop,4)   #Crop from all sides: 0, 4, 8, 12, 16
	Tresh =  Default(Tresh,28)     #Sensitivity for black (20~50)
	DAR   =  Default(DAR,1.33333)  #Video aspect ratio
	OC=(OC%2==0)?OC:0
	Mode=(Mode>3&&DAR>1.4)?Mode-3:Mode
	clp
	PlanB=(width==720)&&(mode==2||mode==3)
	Orig=last
	IsWider=(DAR<(16.0/(12-Mode)))
	TBCrop=(last.height/24)*Mode+OC 
	CutSize=Orig.height-round((last.height/24)*Mode/4)*4
	TH=Orig.height-TBCrop*2
	TW=round((Orig.width-OC*2)*(12-Mode)/48)*4
	BarSize=(PlanB)?(mode==3)?120:72:round((last.width-2*oc-TW)/4)*2
	CrOrig=(PlanB)?Orig.crop(OC,TBCrop,-OC,-TBCrop).Spline36Resize(orig.width+2*BarSize-OC*2,orig.height-OC*2)
        \:Orig.crop(OC,TBCrop,-OC,-TBCrop)
        CrOrig1=Orig.crop(OC,OC,-OC,-OC)
	cropsize=round(Orig.width/12)*2
	BottomCut=Orig.crop(cropsize,CutSize,-cropsize,-12)
	TopCut=Orig.crop(cropsize,12,-cropsize,-CutSize)#.invert
	TestClp=stackvertical(TopCut,BottomCut).greyscale().ColorYUV(off_y=-Tresh)
	NonCr=(IsWider)?(PlanB)?Orig.crop(OC,OC,-OC,-OC).AddBorders(BarSize,0,BarSize,0):Orig.crop(OC,OC,-OC,-OC).LanczosResize(TW,TH).AddBorders(BarSize,0,BarSize,0):CrOrig
	IsWider?ConditionalFilter(TestClp,CrOrig,NonCr,"AverageLuma()","<","0.0005"):CrOrig1
	#overlay(last,testclp.invert,x=(last.width/4-testclp.width/4)*2)
}
Usage (in ffdshow):
AR=float(ffdshow_dar_x)/float(ffdshow_dar_y)
LameAutoCrop(int Mode,int OverCrop,int Treshold,AR)
Usage (in regular script)
LameAutoCrop(Mode,OverCrop,Treshold,video Aspect Ratio)

Mode/OverCrop and Treshold are all explained in the AVSI, but basically
Mode is the result of the following equation screen shape=16/(12-m). Mode 2 is 16/10, mode 3 is 16/9.

Overcrop defines how many pixels you want removed from all sides. 4-8 is fine with ITU-mastered videos, it's not much harmful as there is usually nothing important on the end of the image anyways.

Treshold (lol I realize I made a typo) - Is "black sensitivity", my balance between false positive and negative is around 24-28. With TV levels under 16 wouldn't detect anything. With PC levels it will. The higher it is the more likely it is to get false positive, the lower it is the higher the chance for false negative.

A little preview how it works with 3 different 4/3 music videos, which have scenes with different aspect ratio.
http://www.youtube.com/watch?v=_6PhuUBdZwE
Note how it switches from "Touch from inside" to "Touch from outside"
Attached Files
File Type: zip LameAutoCrop.zip (2.4 KB, 74 views)
__________________
"The significant problems we face cannot be solved at the same level of thinking we were at when we created them."
-- Albert Einstein
Lam3rD is offline   Reply With Quote
Reply

Tags
autocrop

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 15:28.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.