Quantcast Problem with custom script in Avisynth to stabilize video? - digitalFAQ Forum
Go Back    Forum > Digital Video > Video Project Help > Restore, Filter, Improve Quality

Reply
 
LinkBack Thread Tools
  #1  
03-07-2018, 11:27 AM
benzio benzio is offline
Free Member
 
Join Date: Dec 2017
Posts: 18
Thanked 0 Times in 0 Posts
Hello!
I would like to stabilize an interlaced video in this way: I want to avoid the single fields shifted up or down, probabily due to tracking problems in the vcr.

My idea is this:
I separate the fields first, and then if a frame shifted UP, DOWN, LEFT or RIGHT has an average difference from the previous two frames and the next two frames always lesser than the difference of the actual frame and the previous/next frames, then the frame has to be shifted in that direction by one pixel. And I would go recursive to have a radius of possible movement.

I created this function and I cannot tell what's happening. Sometimes it working (but only if the radius is 1), sometimes gives an error, sometimes makes virtualdub crash, and sometimes shifts the frame in the wrong direction when the radius is greater than one.
I'm getting mad about this!

I believe that is a variable scope problem (?) but i'm not sure about this.

Could you help me to spot the problem in my code please?



Code:
VIDEO1 = avisource("F:\DEVCR1_3 (piccol).AVI").assumeTFF().killaudio()
video = VIDEO1.SeparateFields()
video.removeTrackingSpikes(3)

function removeTrackingSpikes(clip source, int radius){
newvideo = pointresize(source, source.width,source.height*2).converttoyv12()

olddifferenceplus1 = Overlay(newvideo, trim(newvideo,1,0), mode="subtract").grayscale()
olddifferenceplus2 = Overlay(newvideo, trim(newvideo,2,0), mode="subtract").grayscale()
olddifferenceminus1 = Overlay(newvideo, trim(newvideo,0,1)+newvideo, mode="subtract").grayscale()
olddifferenceminus2 = Overlay(newvideo, trim(newvideo,0,2)+newvideo, mode="subtract").grayscale()

verticalminus1 = pointresize(newvideo, newvideo.width, newvideo.height, 0, -2)
newdifferenceplusb1 = Overlay(verticalminus1, trim(newvideo,1,0), mode="subtract").grayscale()
newdifferenceplusb2 = Overlay(verticalminus1, trim(newvideo,2,0), mode="subtract").grayscale()
newdifferenceminusb1 = Overlay(verticalminus1, trim(newvideo,0,1)+newvideo, mode="subtract").grayscale()
newdifferenceminusb2 = Overlay(verticalminus1, trim(newvideo,0,2)+newvideo, mode="subtract").grayscale()
newvideo = conditionalfilter(newvideo, verticalminus1, newvideo, "newdifferenceplusb1.averageLuma()+0.5 < olddifferenceplus1.averageLuma() && newdifferenceplusb2.averageLuma()+0.5 < olddifferenceplus2.averageLuma() && newdifferenceminusb1.averageLuma()+0.5 < olddifferenceminus1.averageLuma() && newdifferenceminusb2.averageLuma()+0.5 < olddifferenceminus2.averageLuma()", "equals", "true")

verticalplus1 = pointresize(newvideo, newvideo.width, newvideo.height, 0, 2)
newdifferenceplusb1 = Overlay(verticalplus1, trim(newvideo,1,0), mode="subtract").grayscale()
newdifferenceplusb2 = Overlay(verticalplus1, trim(newvideo,2,0), mode="subtract").grayscale()
newdifferenceminusb1 = Overlay(verticalplus1, trim(newvideo,0,1)+newvideo, mode="subtract").grayscale()
newdifferenceminusb2 = Overlay(verticalplus1, trim(newvideo,0,2)+newvideo, mode="subtract").grayscale()
newvideo = conditionalfilter(newvideo, verticalplus1, newvideo, "newdifferenceplusb1.averageLuma()+0.5 < olddifferenceplus1.averageLuma() && newdifferenceplusb2.averageLuma()+0.5 < olddifferenceplus2.averageLuma() && newdifferenceminusb1.averageLuma()+0.5 < olddifferenceminus1.averageLuma() && newdifferenceminusb2.averageLuma()+0.5 < olddifferenceminus2.averageLuma()", "equals", "true")

horizontalminus1 = pointresize(newvideo, newvideo.width, newvideo.height, -2, 0)
newdifferenceplusc1 = Overlay(horizontalminus1, trim(newvideo,1,0), mode="subtract").grayscale()
newdifferenceplusc2 = Overlay(horizontalminus1, trim(newvideo,2,0), mode="subtract").grayscale()
newdifferenceminusc1 = Overlay(horizontalminus1, trim(newvideo,0,1)+newvideo, mode="subtract").grayscale()
newdifferenceminusc2 = Overlay(horizontalminus1, trim(newvideo,0,2)+newvideo, mode="subtract").grayscale()
newvideo = conditionalfilter(newvideo, horizontalminus1, newvideo, "newdifferenceplusc1.averageLuma()+0.5 < olddifferenceplus1.averageLuma() && newdifferenceplusc2.averageLuma()+0.5 < olddifferenceplus2.averageLuma() && newdifferenceminusc1.averageLuma()+0.5 < olddifferenceminus1.averageLuma() && newdifferenceminusc2.averageLuma()+0.5 < olddifferenceminus2.averageLuma()", "equals", "true")

horizontalplus1 = pointresize(newvideo, newvideo.width, newvideo.height, 2, 0)
newdifferenceplusd1 = Overlay(horizontalplus1, trim(newvideo,1,0), mode="subtract").grayscale()
newdifferenceplusd2 = Overlay(horizontalplus1, trim(newvideo,2,0), mode="subtract").grayscale()
newdifferenceminusd1 = Overlay(horizontalplus1, trim(newvideo,0,1)+newvideo, mode="subtract").grayscale()
newdifferenceminusd2 = Overlay(horizontalplus1, trim(newvideo,0,2)+newvideo, mode="subtract").grayscale()
newvideo = conditionalfilter(newvideo, horizontalplus1, newvideo, "newdifferenceplusd1.averageLuma()+0.5 < olddifferenceplus1.averageLuma() && newdifferenceplusd2.averageLuma()+0.5 < olddifferenceplus2.averageLuma() && newdifferenceminusd1.averageLuma()+0.5 < olddifferenceminus1.averageLuma() && newdifferenceminusd2.averageLuma()+0.5 < olddifferenceminus2.averageLuma()", "equals", "true")

newvideo = newvideo.converttoyuy2().pointresize(newvideo.width,newvideo.height/2)

return (radius == 1) ? newvideo :  removeTrackingSpikes(newvideo, radius-1)
}
Reply With Quote
Someday, 12:01 PM
admin's Avatar
Ads / Sponsors
 
Join Date: ∞
Posts: 42
Thanks: ∞
Thanked 42 Times in 42 Posts
Reply




Tags
interlaced, stabilize

Similar Threads
Thread Thread Starter Forum Replies Last Post
VCR simulator script, Avisynth fake VHS look! jmac698 Restore, Filter, Improve Quality 1 02-12-2018 06:17 AM
Avisynth script to fix offset interlacing? lordsmurf Restore, Filter, Improve Quality 4 02-10-2018 05:34 PM
Stabilize VHS video captured without full-frame TBC? benzio Restore, Filter, Improve Quality 11 02-02-2018 10:50 PM
Avisynth script for QTGMC, encode x264 - no video after deinterlace? mo418 Capture, Record, Transfer 18 09-16-2015 01:06 PM

Thread Tools



 
All times are GMT -5. The time now is 10:21 AM