Log in

View Full Version : transparent glitch frames


greymouse
8th January 2018, 21:02
can anyone point me in the right direction to detecting these types of frames?

I'm not sure how to pick up these kind of frames, they are just a single frame, which represents the cut between one clip and another, so they are dotted through out my capture

I am currently removing the frames manually, doing a frame by frame edit, but would like to automate the process

https://fs03n4.sendspace.com/dl/292236a3093e9361454042147727f82f/5a53cccf35ffbb14/0lfupe/sample0.bmp

Pic1
https://fs03n4.sendspace.com/dl/292236a3093e9361454042147727f82f/5a53cccf35ffbb14/0lfupe/sample0.bmp

Pic2
https://fs08n1.sendspace.com/dl/953de3d06e3247e03a78804b6cb9d02e/5a53d2cb0ce5f43d/l6mf1q/transparent20.bmp

:thanks:

johnmeyer
8th January 2018, 22:26
I have written several scripts for detecting bad frames. Some of them are designed to find a single blank (i.e., black) frame, something Sony Vegas is notorious for doing during certain types of renders. I have other scripts for detecting and removing photographer flashes. I have another one to detect and remove the "flash frame" that happens with film transferred from amateur movie film, because the shutter on those relatively inexpensive cameras did not instantly come up to speed, resulting in one or more overexposed frames.

The common thread in all these scripts is that the "bad" frame is different from both of its neighbors. This is different from a scene change where the current frame almost perfectly matches the previous frame, but is quite different from the next frame (the one that starts the new scene).

For many situations, all you need is to use YDifference, and when it "blows up" when looking both backwards and forwards from the existing frame, you've found your bad frame. You can then output that frame number to a file and use that list of frame numbers to immediately go to each bad frame and do something, or you can use motion estimation to automatically replace each bad frame.

Here is a script you can try that should get you going.

#Find And (Optionally) Fix Bad Frames
#John Meyer - December 13, 2016
#Rev. 2.0
#Thanks to Gavino and StainlessS for making the script more professional.

#This script detects single bad frames.

#You can configure the script to write, to a file, the frame numbers of all frames which are detected as "bad".
#You can also configure it to automatically replace each bad frame with a new
#frame interpolated from its neighbors.

#This script will fail if the bad frame happens immediately before or after a scene change.
#This script will also fail to find a bad frame if there is more than one bad frame in a row.

#It works very well for finding both blank frames and also "flash" frames (like those caused
#by a photographer's flash). It will also find single frames which have lots of
#static or pixels. It can also find a frame with large x or y displacement from adjacent frames, like
#a film frame that wasn't properly registered in the film gate, or an analog
#video frame that lost vertical sync.

#When using VirtualDub, to create the text file containing the bad frame numbers,
#select "Run Video Analysis Pass" in the VirtualDub File menu. If you are simultaneously
#creating a fixed video file, you don't need to do this because the file will
#be created simultaneously as the fixed video file is created.

#The script uses ratios of the metrics for the current frame to the same metrics
#on the two adjacent frames. Under normal circumstances, the metrics should be quite
#similar, and therefore the ratio should be very near to unity (i.e., 1.00).

#Run through the video with the "METRICS" variable set to "True" and look at the metrics
#in order to determine an optimum threshold value. A larger threshhold will
#catch fewer bad frames, and a lower threshold will eventually create false positives.
#The replacement code works well enough that if you end up replacing a few frames that are
#actually good, you probably won't notice it.


#-----------------------------
loadplugin("C:\Program Files\AviSynth 2.5\plugins\MVTools\mvtools2.dll")

#Control script operation by changing the following values :
#=====================================================================
VideoFile = "E:\fs.avi"
global badthreshold = 2 # Set METRICS=TRUE to determine best value
METRICS = TRUE # TRUE will show Metrics ONLY (i.e., TRUE overrides all other selctions)
SHOWDOT = FALSE # TRUE will add "***" to each replacment frame (for troubleshooting)
REPLACE = TRUE # TRUE will replace each bad frame with a one that is interpolated from adjacent frames
FILEWRITE = TRUE # TRUE will create a file which contains the frame numbers of all bad frames
filename = "E:\Bad.txt" # Set to name and location where you want the frame numbers stored
#=====================================================================

source = AVISource(VideoFile).convertTOYV12().killaudio()

script = """Subtitle("\nPrevious Ratio = " + String( YDifferenceFromPrevious(source) /
\ Max(YDifferenceFromPrevious( selectevery(source, 1, -1)),0.00001) ) +
\ "\nNext Ratio = " + String( YDifferenceToNext(source) /
\ Max(YDifferenceToNext(selectevery(source, 1, 1)),0.00001)), lsp=0)"""
MetClip = Scriptclip(source, script)

FileFixed = (FILEWRITE)
\ ? WriteFileIf(source, filename, "
\ YDifferenceFromPrevious() / Max(YDifferenceFromPrevious( selectevery(1, -1)),0.00001)
\ > badthreshold && YDifferenceToNext() / Max(YDifferenceToNext(selectevery(1, 1)),0.00001)
\ > badthreshold", "current_frame", append = false) : Source

output = (METRICS) ? MetClip : (REPLACE) ? ReplaceBadI(FileFixed,showdot) : FileFixed
return output

#------------------------------

function ReplaceBadI (clip c, bool SHOWDOT)
{
even = c.SeparateFields().SelectEven()
super_even = SHOWDOT ? even.subtitle("***").MSuper(pel=2) : even.MSuper(pel=2)
vfe = manalyse(super_even,truemotion=true,isb=false,delta=2)
vbe = manalyse(super_even,truemotion=true,isb=true,delta=2)
filldrops_e = mflowinter(even,super_even,vbe,vfe,time=50)

odd = c.SeparateFields().SelectOdd()
super_odd = SHOWDOT ? odd.subtitle("***").MSuper(pel=2) : odd.MSuper(pel=2)
vfo = manalyse(super_odd,truemotion=true,isb=false,delta=2)
vbo = manalyse(super_odd,truemotion=true,isb=true,delta=2)
filldrops_o = mflowinter(odd,super_odd,vbo,vfo,time=50)

Interleave(filldrops_e,filldrops_o)
Replacement = Weave()

fixed = ConditionalSelect(c, "
Prev = YDifferenceFromPrevious()
Prev1 = Max(YDifferenceFromPrevious(SelectEvery(1,-1)),0.00001)
Next = YDifferenceToNext()
Next1 = Max(YDifferenceToNext(SelectEvery(1,1)),0.00001)
Prev/Prev1 < badthreshold && Next/Next1 < badthreshold ? 0 : 1", \
c, selectevery(Replacement,1,-1))

return fixed
}

greymouse
9th January 2018, 18:02
:thanks: johnmeyer I'll give it a go today, i've got a steady amount of vhs work to go through so the more I fix up before I do frame by frame fixes will speed things up

greymouse
10th January 2018, 01:09
i've had sometime to test the script, it is detecting the glitched frames quite nicely,

the YDifference is working, showing quite big differences from the previous and next frame with the ratio, but its not yet writing the bad frames to the bad.txt file

i've uploaded a short sample video

https://fs13n3.sendspace.com/dl/2e386d2636eb44b413c19c7fce666421/5a555597688feb55/2nc1t7/Black_Frames_Sample3_Huffy.avi

johnmeyer
10th January 2018, 04:41
It's been a few years since I wrote that script, but I think you have to set METRICS=FALSE in order to write the bad file frame numbers into your file. StainlessS suggested the:output = (METRICS) ? MetClip : (REPLACE) ? ReplaceBadI(FileFixed,showdot) : FileFixedline, and since I don't normally use that syntax, I can't remember if it will do anything when you have the on-screen metrics enabled. Try setting it to false and test it on a few seconds of bad video and see if you get a file.

[edit]I just looked at your video sample. This script won't work on that video because it does not satisfy the conditions stated in the script itself. As state in the script itself, it replaces individual, single bad frames. The glitch in your sample spans six consecutive frames. There is nothing that can be done to fix this.

johnmeyer
10th January 2018, 05:02
I edited your video so that only one of the bad frames remained. Look at the metrics:

http://i177.photobucket.com/albums/w208/johnmeyer/Bad%20Frame%20Metrics_zpsjxbp7ghc.jpg

Note that both metrics are much larger than unity (i.e., one). This is the criteria for taking action (i.e., putting the frame number in a file, or using motion estimation to fix the frame). By contrast, if you look at the metrics on your original, un-edited file, you'll see that you never get BOTH metrics to be large at the same time. This is because there is not a bad frame in isolation. One large metric happens all the time at scene change and similar, normal events.

If you simply want to detect frames that contain lots of snow, I think such a script can be constructed pretty easily, but you will, with your video, end up with many frames in a row, with nothing you can do to fix the problem other than to delete a bunch of frames and create a jump cut. I guess you could insert a cross-fade to hide the jump.

I'm pretty sure that StainlessS' RT_Stats suite of functions has something that can look for the high-contrast snow typical of these glitches.

StainlessS
10th January 2018, 05:37
Nope, dont know what to do with that lot, hand edit what I would do (SawBones/FrameSurgeon, Intepolate).
[EDIT: Although dunno what to do with interlaced interpolate ]

METRICS = TRUE # TRUE will show Metrics ONLY (i.e., TRUE overrides all other selctions)
Metrics overrides all other stuff.

line, and since I don't normally use that syntax,
output = (METRICS) ? MetClip : (REPLACE) ? ReplaceBadI(FileFixed,showdot) : FileFixed
That means, if(Metrics) Then MetClip Else if(Replace) then ReplaceBadI(FileFixed,showdot) Else FileFixed

johnmeyer
10th January 2018, 06:06
StainlessS,

:thanks: Thanks for the tutorial!

greymouse
10th January 2018, 18:00
thanks guys for having a look and explaining the function to me :D