Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #################################
- # Macro_Deinterlace.avs, Correct incorrectly resized interlaced video.
- # YUY2.
- #
- # (c) John H. Meyer - July 8, 2014
- #
- # Required:-
- # MVTools (c) Manao, Fizick, Tsp, TSchniede, SEt
- # GScript (c) Gavino.
- # Grunt (c) Gavino.
- # s_ExLogo.avs (c) StainlessS.
- # RT_Stats (c) StainlessS.
- #################################
- #
- Function Macro_Deinterlace(clip clp,int RowStart,int RowStep,Bool "TopRowFirst",Float "dFact",Float "dMin",Int "Amount",Int "Amount2",Bool "Show") {
- # Create two half-height clips from groups of 'ScanStep' rows of pixels
- # Shift one of these clips in time (using motion estimation) halfway between previous frame and current frame
- # Then, reassemble the two half height clips.
- # Finally fix thin lines using S_ExLogo with Amount2 arg and then 2nd pass S_Exlogo with Amount arg.
- # First clip uses 'RowStart' rows from top of original clip, plus rows of height='RowStep' in between.
- # Args:
- # RowStart, Offset to bottom row in scanlines
- # RowStep, size of rows in scanlines
- # TopRowFirst, default False = was originally bottom field first.
- # dFact, default 4.0. (Greater than 1.0). For scene change (1st frame) condition @ n to succeed: dFact*Diff(n-2 -> n-1)+dMin < Diff(n-1 -> n)
- # dMin, default 3.0. (Greater than 0.1). dMin avoids silly numbers (very small) at static scenes detecting false scene changes.
- # Amount, Default 256, 0 -> 256. 0=Switched Off. DeLogo thin lines.
- # Amount2, Default 0, 0 -> 256. 0=Switched Off. Mild greater diameter delogo BEFORE Primary Amount Delogo.
- # Show, Default False. Show metrics.
- #
- # In Metrics (Show=True) shows 'Hint=x.x', is a hint for choosing dFact, valid on frame after scene change.
- ####
- clp
- myName="Macro_Deinterlace: "
- TopRowFirst = Default(TopRowFirst,False) # Was bottom field first (before bad resize).
- dFact = Float(Default(dFact,4.0)) # Scene Change, dFact*Diff(n-2 -> n-1)+dMin < Diff(n-1 -> n)
- dMin = Float(Default(dMin,3.0)) # Scene Change, avoid silly numbers on static scenes
- Amount = Default(Amount,256) # Strength of S_Exlogo mixing, greater more opaque delogo (256 max), 0 = none.
- Amount2= Default(Amount2,0) # Stringth of first mild initial S_ExLogo, 0 = none
- Show=Default(Show,False) # Metrics
- Assert(RowStep < Height/2 && RowStep >= 2,myName+"Illegal RowStep")
- Assert(RowStart >=0 && RowStart <= RowStep,myName+"Illegal RowStart")
- Assert(dFact > 1.0,myName+"Illegal dFact")
- Assert(dMin > 0.1,myName+"Illegal dMin")
- Assert(Amount >= 0 && Amount <= 256,myName+"Illegal Amount")
- Assert(Amount2 >= 0 && Amount2 <= 256,myName+"Illegal Amount2")
- RowStart= (RowStart % RowStep)
- FuncS="""
- Function Fn@@@(clip clp,clip Fix,Float dFact,Float dMin,Amount,Amount2,Bool Show) {
- clp
- n = current_frame # Local variable, quicker
- NotNext = (PrevFrame@@@ + 1 != n) # Init OR, user jumped about ?
- # We detect relative to previous frame (n-1), ie when we are 1st frame AFTER Scene Change
- prevdif = (NotNext) ? RT_YDifference(Last,n=n - 1, delta=-1) : PrevDif@@@ # Diff between current_frame-2 and current_frame - 1
- currdif = RT_YDifference(Last,n=n - 1, delta= 1) # Diff between current_frame-1 and current_frame
- SC = (dFact*prevdif + dMin) < currdif # Scene Change if dFact*prevdiff+dMin < currdif
- dHint = (currdif - dMin) / max(prevdif,0.0001)
- dHint = (dHint < 0.0) ? 0.0 : dHint
- Last = (SC) ? Last : Fix # Conditional Select frame
- (Show) ? RT_Subtitle("%d ] %-5.2f : %-5.2f : \a%c%s\a-: Hint=%-5.2f\ndFact =%-5.2f: dMin=%-5.2f\nAmount=%4d : Amount2=%-3d",
- \ n,prevdif,currdif, (SC)?33:45,(SC) ? "Yes" : "No ",dHint,dFact,dMin,Amount,Amount2) : NOP
- Global PrevDif@@@ = currdif
- Global PrevFrame@@@ = n
- Last
- }
- #######################################
- # Unique Global Variables Initialization
- #######################################
- Global PrevFrame@@@ = -42 # Force Init
- Global PrevDif@@@ = 0.0
- #######################################
- # Init
- #######################################
- BotRow = clp.Crop(0,(RowStart>0)?RowStart:RowStep,-0,RowStep)
- for(y=((RowStart>0)?RowStart:RowStep)+RowStep*2,clp.Height-RowStart,RowStep*2) {
- botRow = BotRow.StackVertical(clp.Crop(0,y,-0,Min(clp.Height-y,RowStep)))
- }
- if(TopRowFirst) { Offset_BotRow = BotRow} # midway between current and next frames
- Else { Offset_BotRow = BotRow.DeleteFrame(BotRow.FrameCount-1).DuplicateFrame(0) } # midway between Previous and current frames
- super_BotRow=MSuper(Offset_BotRow,pel=2)
- vfe_BotRow=manalyse(super_BotRow,truemotion=true,isb=false,delta=1,blksize=8,overlap=4,search=6)
- vbe_BotRow=manalyse(super_BotRow,truemotion=true,isb=true,delta=1,blksize=8,overlap=4,search=6)
- est_BotRow=mflowinter(Offset_BotRow,super_BotRow,vbe_BotRow,vfe_BotRow,time=50,blend=false,mL=100)
- newClip = clp
- for(y=0,est_BotRow.Height-RowStep,RowStep) { # Re-assemble clip with motion compensated bottom row
- newClip=newClip.Overlay(est_BotRow.Crop(0,y,-0,Min(est_BotRow.Height-y,RowStep)),x=0,y=((RowStart>0)?RowStart:RowStep)+y*2)
- }
- Fix=newClip
- if(Amount2 > 0) { # Preparatory Delogo, used before PRIMARY Delogo (More Mild Amount2 setting OR none)
- for(y=RowStart,Fix.height-1,RowStep) {
- Fix = Fix.S_Exlogo(0,y-2,-0,4,BlurMode=5,amount=Amount2)
- }
- }
- if(Amount > 0) { # PRIMARY Delogo of thin lines (best use strong ie max Amount setting)
- for(y=RowStart,Fix.height-1,RowStep) {
- Fix = Fix.S_Exlogo(0,y-1,-0,2,BlurMode=5,amount=Amount)
- }
- }
- #######################################
- # Unique Runtime Call, GScriptClip must be a one-liner:
- #######################################
- ARGS = "Fix,dFact,dMin,Amount,Amount2,Show"
- Last.GScriptClip("Fn@@@(last, "+ARGS+")", local=true, args=ARGS)
- """
- #######################################
- # Unique Identifier Definition
- #######################################
- RT_IncrGlobal("MacroD_InstanceNumber")
- InstS = RT_StrReplace(FuncS,"@@@","_MacroD_"+String(MacroD_InstanceNumber))
- # RT_WriteFile("DEBUG_"+String(MacroD_InstanceNumber)+".TXT","%s",InstS)
- Return GScript(InstS)
- }
- #Import("C:\Program Files\AviSynth 2.5\plugins\s_exlogo.avs")
- #source = AVISource("E:\fs.avi").KillAudio()
- #This is for the deleted storylines featurette on the 20th anniversary Thomas and the Magic Railroad Blu-ray. The encode on the disc was horrible for Shout! Factory's usual standards.
- #This AVISynth script is the best way I've come to fixing it. There's still a few blended frames at scene changes, but it's light-years ahead compared to the original video.
- #This script is designed to work with the featurette ripped directly without re-encoding using MakeMKV. I cannot gaurantee another rip will work with this script.
- #The way I load this into AVISynth is I open the original MKV ripped from the Blu-ray in VirtualDub2.
- #From there, I start the frameserver and load the frameserved video into AVISynth. There may be another more elegant way of getting the file in directly, but I have NOT tested this. Your mileage may vary.
- #This also does IVTC on the clip, so you'll be getting a 1080p video at 23.976 frames per second. You won't be getting true 1080p quality, though. After all, this was initially sourced from an analog video source (likely a VHS Tape) from Britt Allcroft's personal collection.
- #Special thanks to johnmeyer on the Doom9 Forums for pointing me in the right direction for fixing this badly encoded video! This full script was put together by Rico Robbins, aka wizoomer95.
- Import("F:\avs\s_ExLogo.AVS")
- LoadPlugin("F:\avs\GScript_26_32.dll") #Even if you are using AVISynth+, you MUST load the plugin and not rely on the GScript integration. Otherwise, the function will break and this script will result in an error.
- AVIFileSource("C:\Users\Rico Robbins\Videos\video.vdr.avi").KillAudio() #Yes, you want to kill the audio. This is just for processing. Don't worry, we'll dub it back in later in this very script!
- ConvertToYUY2()
- Crop(60,54,-60,-54) #Cropping out the black borders on the original video. Next, we do perform inverse telecine.
- Telecide()
- Decimate()
- #Next comes the magic in this script only akin to gold dust itself...
- ROWSTART= 2
- RowStep = 3
- TOP_ROW_FIRST=False
- AMOUNT = 256
- AMOUNT2= 200
- SHOW=True
- DFACT1=4.0
- DMIN1=3.0
- L=Macro_Deinterlace(ROWSTART,ROWSTEP,TopRowFirst=TOP_ROW_FIRST,dFact=DFACT1,dMin=DMIN1,Amount=AMOUNT,Amount2=AMOUNT2,Show=FALSE) #Originally Show was set to SHOW with StackHorizontal not commented out below for debugging details
- R=Macro_Deinterlace(ROWSTART,ROWSTEP,TopRowFirst=TOP_ROW_FIRST,dFact=4.0,dMin=3.0,Amount=256,Amount2=0,Show=SHOW) #StackHorizontal(L,R)
- FixedVideo = AddBorders(L,60,54,60,54)
- OrigAudio = AVIFileSource("C:\Users\Rico Robbins\Videos\video.vdr.avi").KillVideo()
- AudioDub(FixedVideo,OrigAudio)
- #This will add the borders we cropped up earlier before processing, to restore it to 1920x1080 in resolution. To leave them cropped, comment out the above line and uncomment the line below.
- #AudioDub(L,OrigAudio)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement