Log in

View Full Version : it's possible? (detecting black frames)


nexus_013
10th July 2019, 04:26
it's possible to replace the black frames of this video with the image before the black frame automatically?

the video:
https://youtu.be/44HHbQ-V8IY?t=68

newbie in avisynth any help is appreciated

johnmeyer
10th July 2019, 04:37
I have half a dozen scripts that do exactly this. At one point I decided to make one of them into a proper, generalized script and posted it here:

Finding individual "bad" frames in video; save frame number; or repair (https://forum.doom9.org/showthread.php?p=1789509)

Your video has a LOT of blank frames. I didn't walk through it frame-by-frame to see if you have any place where there are two blank frames in a row. If you have that, you'll have to do some manual fixes. However, if the video on either side of the blank frame has good, valid video, the script I created can often create near-perfect results.

nexus_013
10th July 2019, 07:43
I am new in avisynth
I think I managed to use your script but I did not see any differences
maybe I do not know how to use it
thank you anyway ;)

StainlessS
10th July 2019, 10:45
Colorbars # comment out to add you clip
#AviSource("...")

ConvertToYV12 # Just to make sure

LIMITHI = 32.0 # Below is black
SHOW=True # Set False when happy that LimitHi is set correctly (leave limitLo set at 0.0 for black frames).
############
ORG=Last
TweenFrames(LimitLo=0.0,LimitHi=LIMITHI,Show=SHOW) # Fix Black frames PROGRESSIVE, black as here less or equal to 32.0


(SHOW) ? StackVertical(ORG.Scriptclip("""RT_Subtitle("AverageLuma=%.3f",RT_AverageLuma)""").TSub("Original",True),Last.TSub("Fix")) : NOP

return Last

Function TweenFrames(clip c,float "LimitLo",float "LimitHi",bool "show") {
# TweenFrames() by StainlessS
# PROGRESSIVE.
# Replace isolated bad frames eg Black or White with a frame tweened from those either side using MvTools, and RT_Stats.
# LimitLo: is minimum luma value of frame to replace. Allows select, eg black/White.
# LimitHi: is maximum luma value of frame to replace.
# Show: Puts indicator on fixed frames.
c
LimitLo=Float(Default(LimitLo,200.0)) # Average Luma greater or equal to this eligible for replacement
LimitHi=Float(Default(LimitHi,255.0)) # Average Luma lesser or equal to this eligible for replacement
show=Default(show,False)
Prev=DeleteFrame(FrameCount-1).DuplicateFrame(0)
super = Prev.MSuper()
backward_vectors = MAnalyse(super, isb = true,truemotion=true, delta=2)
forward_vectors = MAnalyse(super, isb = false,truemotion=true, delta=2)
inter = Prev.MFlowInter(super, backward_vectors, forward_vectors, time=50, ml=70)
inter = (show) ? inter.Subtitle("FRAME FIXED") : inter
CondS="""
ave=RT_AverageLuma()
prv=RT_YDifference(delta=-1)
nxt=RT_YDifference(delta=1)
alt=RT_YDifference(current_frame-1,delta=2)
clpn=(ave>=LimitLo && ave<=LimitHi && alt < prv && alt < nxt) ? 1 : 0
# RT_Debug(String(current_frame)+"]","Ave="+String(ave),"Prv="+String(prv),"Nxt="+String(nxt),"Alt="+String(alt),"ClpN="+String(clpn))
clpn
"""
CondS=RT_StrReplaceMulti(CondS,"LimitLo"+Chr(10)+"LimitHi",String(LimitLo)+Chr(10)+String(LimitHi))
ConditionalSelect(Last,CondS,Last,inter) # Fix bad frames
return Last
}

# Stack Overhead Subtitle Text, with optional FrameNumber shown.
Function TSub(clip c,string Tit,Bool "ShowFrameNo",Int "Col"){
c.BlankClip(height=20,Color=Default(Col,0))
(Default(ShowFrameNo,False))?ScriptClip("""Subtitle(String(current_frame,"%.f] """+Tit+""""))"""):Trim(0,-1).Subtitle(Tit)
Return StackVertical(c).AudioDubEx(c)
}

Requires RT_Stats and Mvtools2
EDIT: Make show=false when happy.

johnmeyer
10th July 2019, 15:10
I am new in avisynth
I think I managed to use your script but I did not see any differences
maybe I do not know how to use it
thank you anyway ;)Try using these settings:

global badthreshold = 1.5 # Set METRICS=TRUE to determine best value
METRICS = FALSE # TRUE will show Metrics ONLY (i.e., TRUE overrides all other selctions)
SHOWDOT = TRUE # 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 = FALSE # TRUE will create a file which contains the frame numbers of all bad framesBy lowering the "badthreshold" you will get more replacements. By setting SHOWDOT to TRUE you will get an asterisk in the upper left corner whenever a frame is replaced by a synthesized frame. If you don't see any asterisks, then you probably don't have the MVTools2 plugin loaded.

nexus_013
10th July 2019, 20:26
is working moderately well
#This script will also fail to find a bad frame if there is more than one bad frame in a row. (maybe that's my case)

@StainlessS I'm going to try it later

StainlessS
10th July 2019, 21:51
Yep, both mine and Johns scripts are for single frame repair, what is max repair length ?
(does it have audio ?)

johnmeyer
10th July 2019, 21:54
Yep, both mine and Johns scripts are for single frame repair, what is max repair length ?
(does it have audio ?)Didn't you create a script for repairing video that had more than one bad frame in a row?

nexus_013
10th July 2019, 23:09
yes
thanks johnmeyer/StainlessS
problem solved