PDA

View Full Version : auto VOB -> d2v resize/crop script


ivanova
10th November 2003, 23:43
Wrote this last night.
Comments? Improvements?
#ASYNTHER MPEGSource auto PAL 16/9 Anamorphic

DoNotCrop = 0 # Set this to 1 to preview cropping results
vsize = 700.0 - 71.7 # Size of the video in MB (Total movie - Audio)
vwidth = Round(640.0/16)*16 # The width of final video
CropOnlySides = 0 # Crop only the sides in second crop
KeepFromOversizeWidth = 1 # Won't resize width more that cropped width (AR could be wrong)
ShowInfo = 1 # Show info overlay


filename = "%f"
n = Findstr(LCase(filename),".vob")
root = LeftStr(filename,n-1)
(Exist(root+".d2v")) ? NOP : Call(BlankClip,
\ "D:\util\Mpeg2decodefix\DVD2AVIdg.exe -IA=1 -FO=0 -CS=2
\ -AIF="+chr(91)+filename+chr(93)+" -OF="+chr(91)+root+chr(93)+" -exit","-2")

Source = MPEG2Source(root+".d2v",idct=6)
Movie = Source.AutoCrop(mode=DoNotCrop,wmultof=4,hmultof=2,threshold=60,samples=10)
OCWidth = Width(Movie)
OCHeight = Height(Movie)

PAR = (128.0 / 117.0) * (4.0 / 3.0)
CAR = float(Width(Movie)) / float(Height(Movie))
AR = PAR * CAR

FinalWidth = Round(vwidth/16)*16
FinalHeight = Round((vwidth/AR)/16)*16
TWidth = vwidth
THeight = Round(vwidth/AR)
Error = (((float(TWidth)/THeight)-(float(FinalWidth)/FinalHeight))/(float(TWidth)/THeight))*100

MovieAR = float(FinalWidth) / float(FinalHeight)
NewCAR = MovieAR / PAR
NewCropWidth = (DoNotCrop != 0) ? Width(Movie) : Round((Height(Movie) * NewCAR)/4)*4
NewCropHeight= (DoNotCrop != 0 || CropOnlySides == 1) ? Height(Movie) :
\ Round((Width(Movie) / NewCAR)/4)*4
Movie = (NewCAR < CAR) ?
\ Crop(Movie,Round((Width(Movie)-NewCropWidth)/2),0,NewCropWidth,Height(Movie)) :
\ Crop(Movie,0,Round((Height(Movie)-NewCropHeight)/2),Width(Movie),NewCropHeight)


NNCAR = float(Width(Movie)) / float(Height(Movie))
NNAR = PAR * NNCAR
NewTWidth = FinalWidth
NewTHeight = Round(FinalWidth/NNAR)
NewError = (((float(NewTWidth)/NewTHeight)-(float(FinalWidth)/FinalHeight))/
\ (float(NewTWidth)/NewTHeight))*100

bppf=(vsize * 1024.0 * 1024.0 * 8.0) / (float(FinalWidth) * FinalHeight * Framecount(Movie))

FinalWidth = (KeepFromOversizeWidth == 1 && FinalWidth > Width(Movie)) ?
\ Floor(Width(Movie)/16)*16 : FinalWidth

BilinearResize(Movie,FinalWidth,FinalHeight)

(ShowInfo == 1) ? Subtitle(String(FinalWidth)+"x"+String(FinalHeight)+"="+
\ String(FinalWidth*FinalHeight)+" AR = 1:"+
\ String(MovieAR),x=-1,y=20,text_color=$99CCFF) : NOP
(ShowInfo == 1) ? Subtitle("1st Crop 2nd Crop",align=2,y=50) : NOP
(ShowInfo == 1) ? Subtitle(String(OCWidth)+"x"+String(OCHeight)+" "+
\ String(Width(Movie))+"x"+String(Height(Movie)),align=2,y=80) : NOP
(ShowInfo == 1) ? Subtitle("Error : "+String(Error)+"% "+
\ String(NewError)+"% ",align=2,y=110) : NOP
(ShowInfo == 1) ? Subtitle(String(bppf/0.65)+" bppf x 0.65 = "+
\ String(bppf)+" bppf",x=-1,y=150) : NOP
(ShowInfo == 1) ? Subtitle(String(round(vsize/0.65))+" MB x 0.65 = "+
\ String(round(vsize))+" MB",x=-1,y=180) : NOP
(ShowInfo == 1) ? Subtitle(String(round(vsize * 1024.0 /0.65))+" KB x 0.65 = "+
\ String(round(vsize * 1024.0))+" KB",x=-1,y=210) : NOP
(ShowInfo == 1) ? Subtitle(String(round(vsize * 1024.0 * 1024.0/0.65))+" B x 0.65 = "+
\ String(round(vsize * 1024.0 * 1024.0))+" B",x=-1,y=240) : NOP
undot()
TemporalSoften(1,8,12,mode=2,scenechange=15)