View Full Version : Finding Leftover Interlaced Frame Numbers in IVTCed Source
Kushami
7th February 2014, 10:53
So I have a weird source. The footage is clearly 24FPS with pulldown: P P P I I ... 3:2. Everywhere.
The problem is, the pattern doesn't continue consistently. Every scene change starts the pattern in a different place. As good as tfm, telecide and such are, they always miss some frames and there are a few still interlaced frames here and there throughout the footage.
Essentially, what I assume happened when they created this cartoon is that they animated the footage in 24fps, then converted it to 30fps interlaced, and THEN edited it on a digital line editor at 30fps and applied effects. Thus breaking the cadence of the pulldown. (The credit sequence has two picture in picture sequences which both had to be ivtced separately and reconstructed...!)
I've almost completely IVTCed this, and I'm hunting and pecking through trying to find any missed frames before I go final with it. (I wrote a function that lets me start tfm or telecide on arbitrary frame amounts and splices the fixed frames in, so I can fix these sections manually.)
I'm wondering if there's a script that I could run on my final footage that could actually go through and report any suspected interlaced frames? I know that if I turn on postprocessing/frame blending in like tfm and whatnot it'll blend a lot of these "problem" frames... I just want something that can dump the suspected frame numbers into a logfile if possible, so I can visually check them and then fix manually if necessary. Since it's a cartoon, the frame blending isn't optimal and it's easy to photoshop the problem frames.
Because of the way this has been edited, there's been about 6 completely unrecoverable frames in all the footage (IE: There's a field without a matching field where they cut a scene change in the middle of the 2 interlaced frames.)
Any help appreciated! As this is a small time commercial project, I'll also throw some special thanks into the credits if I can.
StainlessS
7th February 2014, 12:11
Just a suggestion, others may know better.
You could try something like eg
ScriptClip("""
IsCombed()
\ ? RT_TxtWriteFile(String(current_frame),"Report.txt",append=True)
\ : NOP
""")
Untested, got to dash. (requires RT_Stats, could mod for WriteFile)
manono
7th February 2014, 12:17
...and there are a few still interlaced frames here and there throughout the footage.
You turned off the post processing? PP=0? Why?
I know that if I turn on postprocessing/frame blending in like tfm and whatnot it'll blend a lot of these "problem" frames
It won't blend any of them. Not at default settings anyway. And you can have it post-process/deinterlace with any deinterlacer you like, at any settings you like.
Kushami
7th February 2014, 12:56
Thanks Stainless! I'll try that out in the morning and see if I can get it to work for me. I'll also try any other solutions people give, too.
manono:
I turned it off because the source has a bunch of sequences with very thin lines. There is a very intricate scene in one episode, for instance, where someone does a card trick, and whenever it interpreted this scene with PP set to default (6) it saw the lines of the cards as combed frames and would warp them severely with the interpolation even though they were completely ivtced correctly. I also do not want it to blend or interpolate the frames with no matching fields at the beginning of scenes. I want to fix these by hand.
Turning off PP fixed 90% of the issues in the end. The source is very very clean, so it can see things like mouths and what have you as combed frames sometimes. Because of this, I can't just let it go on its own. I have to check things by hand. It would just be awesome to have something that lets me see what numbers TFM thinks are combed.
Is there a way to make TFM run code whenever it finds a frame like this? I was looking at the parameters, and PP=1 adds 'hints'?
Obviously I'm not a tfm expert, and my scripting is novice at best. I was looking at the data, though, and I was thinking maybe I can use something like the clip2 parameter or OutputDebugString() to output the text when pp=1, but I'm not good enough to understand how to parse/smatch specific text or dump text files at avs scripting yet. Even making it stop Virtualdub and give a caution box would work.
Gavino
7th February 2014, 14:09
ScriptClip("""
IsCombed()
\ ? RT_TxtWriteFile(String(current_frame),"Report.txt",append=True)
\ : NOP
""")
This will give an error since the run-time script of ScriptClip must return a clip.
Replace ScriptClip(...) here by FrameEvaluate(...).
wonkey_monkey
7th February 2014, 18:24
My trick for doing this is to bob, selectevery/odd, overlay the two mode="difference", resize to a thumbnail, then do a load of selecteverys and stacks so you end up displaying, say, 256 frames at a time in a 16x16 grid.
It's not perfect, but any interlaced frames should stick out pretty well.
poisondeathray
7th February 2014, 18:43
It would just be awesome to have something that lets me see what numbers TFM thinks are combed.
Obviously I'm not a tfm expert, and my scripting is novice at best. I was looking at the data, though, and I was thinking maybe I can use something like the clip2 parameter or OutputDebugString() to output the text when pp=1, but I'm not good enough to understand how to parse/smatch specific text or dump text files at avs scripting yet. Even making it stop Virtualdub and give a caution box would work.
If you specify TFM(output="file.txt") , it will print each frame and the matches used . You can use word, notepad etc.. to search for "+" for frame that it thinks are "combed"
It might look something like this:
257 c - [2]
258 p - [2]
259 p - [4]
260 h + [182]
261 c - [3]
262 c - [2]
263 p - [2]
In this example , frame 260 is considered "combed" . I don't know how helpful this will be to you because you need to adjust the detection thresholds or it will often miss small combing (like in mouths) , but setting it to low or search area too small will give you too many false positives and more work to look over
Kushami
7th February 2014, 21:36
StainlessS and Gavino's methods worked great. There were a lot of false positives, but I expected this given the nature of the video. I managed to find 2 combed frames I missed on the first video alone! Thank you so much!
I'm wondering if there's a way to write an avi file using this script that only includes the matches? I figure I can write the frame number onto the video something like this, and then it would be easy for me to spot check each frame.
ScriptClip("""
IsCombed()
\ ? subtitle(String(current_frame), font="georgia", size=55, text_color=$ff0000, align=9).### CODE TO APPEND FRAME TO AVI HERE ? ###
\ : NOP
""")
Alternatively, if that doesn't work, is there perhaps a way to load just the frames output into the report file? I'm imagining some kind of frame delete loop between each frame of each line, but that's way more complicated than I think I can muster. I thought maybe I could deleteframe(current_frame) when there's no matches, but that didn't work unfortunately.
The only other question I have is if there's a method to detect these kinds of frames? In this frame, it misjudged the match because it's close enough to a progressive frame, but it's obviously the wrong output. Iscombed doesn't match it however.
http://i.imgur.com/YJo8Do1.png
I can upload a short sample if need be.
manono
7th February 2014, 22:04
I turned it off because the source has a bunch of sequences with very thin lines.
Then make the CThresh less sensitive, The default is 9. Make it 10, 11, 12.
And, even with that, if you get deinterlaced frames that shouldn't be deinterlaced, make QTGMC the post-processor, or something else, rather than the default TDeint.
Kushami
7th February 2014, 23:14
Manono, lowering the threshold is a good idea, and I'll do that.
The thing is, though, even if I do that, I still have to check for combed frames and mistakes anyway. I don't want to do automatic PP, because usually there's a perfect match it didn't find or otherwise I'll properly repair the frame myself from the half field instead of having it automatically make a new one.
I did work out something instead of a video which seems to work though. Feel free to tell me how to improve this:
global infile = "comb_sample01.avi"
global writefile = String("F:path\")+String(infile)+String(".txt")
avisource(infile)
converttoyuy2()
ScriptClip("""
IsCombed()
\ ? subtitle(String(current_frame), font="georgia", size=55, text_color=$ff0000, align=9).
converttorgb32().ImageWriter("combed/", current_frame, current_frame, "png").converttoyuy2()
\ : subtitle(" ", font="georgia", size=12, text_color=$ff0000, align=9)
""")
FrameEvaluate("""
IsCombed()
\ ? RT_TxtWriteFile(String(current_frame),string(writefile),append=True)
\ : NOP
""")
assumefps(260)
I've also been playing with the threshold trying to get it to detect the above type of frame, though not having much luck.
Kushami
8th February 2014, 06:21
I knew it would flag this sequence. Hahaha.
http://i.imgur.com/wUcekAU.png
I tried lowering the threshhold to detect the above frame with the kid driving the van, too, but I had to lower it to 4 and it essentially would flag pretty much everything at 4...
StainlessS
8th February 2014, 09:50
Here a detector, two separate passes or auto 2 pass.
# Required, GSCript, RT_Stats, FrameSel, DeComb, plugins
infile = "comb_sample01.avi"
Report = "Report.txt"
SHOWCOMBED = True # Show combed, else show non-Combed (DO NOT need to re-create report after alter this)
TWOPASSES = False # If True AUTO creates report.txt and then returns as for SHOWCOMBED
CREATE = True # If TWOPASSES==False, then True creates Report.txt or False returns frames as for SHOWCOMED (already created via CREATE==True)
THRESHOLD = 20 # 20 default for IsCombed()
FSSHOW=True # Extra info from FrameSel()
avisource(infile)
# RequestLinear().tfm() # EDIT: or should it be tfm().RequestLinear()
GScript("""
if(TWOPASSES || CREATE) {
# Create report file containing frame numbers (may take some time)
Exist(Report) ? RT_FileDelete(Report) : NOP
for(current_frame=0,Framecount()-1) {
if(IsCombed(Threshold=THRESHOLD)) { # could perhaps mod for IsCombedTIVTC
RT_TxtWriteFile(String(current_frame),Report,append=True)
}
}
if(!TWOPASSES) {
RT_Subtitle((Exist(Report)) ? "Report is created, Set CREATE=False" : "No Combed Frames Found")
}
}
if(TWOPASSES || !CREATE) {
Assert(Exist(Report),Report + " Does NOT Exist, (No Combed Frames Found)")
LAB=ShowFrameNumber(font="georgia", size=55, text_color=(SHOWCOMBED)?$FF0000:$00FF00)
FrameSel(LAB, cmd=Report,show=FSSHOW,reject = !SHOWCOMBED) # Return COMBED/NON-COMBED Frames (RED/GREEN)
}
""")
Return Last
EDIT: FrameSel plugin here:- http://forum.doom9.org/showthread.php?t=167971
StainlessS
8th February 2014, 12:04
Here, another way you can use FrameSel Plug
infile = "comb_sample01.avi"
Report = "Report.txt"
ORDER=1 # 1=Top Field First, 0 = Bottom Field First
SHARP=False
THRESHOLD=10
SHOW=True # Shows which frames were repaired
avisource(infile)
ORIGINAL=Last # ORIGINAL BEFORE eg tfm
# tfm().RequestLinear()
Assert(Exist(Report),Report + " Does NOT Exist, (No Combed Frames Found)")
# LeakKernelDeint YUY2/YV12/RGB
# order=0 is bottom field first, MUST be set
# Sharp=true/false(false). Better vertical resolution and sharper.
# Threshold=0-255(10) Motion threshold to detect combing.
DEINT=LeakKernelDeint(ORIGINAL,order=ORDER,sharp=SHARP,threshold=THRESHOLD,map=false) # Deinterlace ALL ORIGINAL frames (can use temporal deinterlacer)
REPAIRED=FrameSel(DEINT,cmd=Report,show=False,reject=False) # Get REPAIRED COMBED Frames ONLY
FrameRep(Last,REPAIRED,cmd=Report,show=SHOW) # Put repaired frames back from whence they came
# (but in tfm clip rather than original clip)
Return Last
EDITED:
Kushami
10th February 2014, 10:30
Wow, this is amazing. Can't wait to try this out. Thanks, Stainless. It's even better than what I ended up making.
StainlessS
11th February 2014, 16:34
As an afterthought, it might provide better results if you deinterlace on the tfm clip rather than the original,
I dont have any suitable test clips, and rarely play with weird NTSC stuff. Give both ways a try.
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.