Log in

View Full Version : Trying to perform IVTC using interlace detection


soreepeong
13th December 2016, 16:19
I am trying to perform IVTC of an anime from VHS. The source usually has a fixed pattern, but occasionally a long sequence of interlaced frames appear.
My assumption is that for a telecined video, for each interlaced continuous sequence, one frame has to be a duplicate and should be dropped. That seems to be working so far, but detecting if a frame is interlaced or not happens to be more difficult than I thought.

One of the troubling frame is:
http://i.imgur.com/gftRwC0.png

It is a combed frame, but only IsCombedTIVTC(3) and IsCombed(22) would report that it is, which is way too sensitive. I found that it is usually combed when c_above is above ~250 from ShowCombedIVTC(9), but the value is not exported to AviSynth, and even if I modify the source by adding env->Set(Global)Var into ShowCombedTIVTC::GetFrame, when I try to use the value, it always reports a value for a previous frame.



List of questions:


Is there any good way to determine if a frame of an anime is combed or not? These are example frames: https://imgur.com/a/fmntK
Is there a script for IVTC that will work on this sample? https://www.mediafire.com/?t9vxjn1zypvyihq
It starts with and often has a steady IVTC pattern, but some parts are plain interlaced or progressive more than 5 consecutive frames.
Frame 251 ~ 400 are especially messy: when I just bob that part, for consecutive 5+ frames, the resulting 10 frames are all different.
How do I extract values printed in ShowCombedIVTC()
If I have to modify the plugin source code, which part should I modify?
Is there a way to stabilize a video from VHS source horizontally when some frames are combed, so that IsCombed(TIVTC) doesn't report a frame as combed even when they're in sensitive mode?
Does the idea written below make sense?
Current work: http://pastebin.com/Txgv6b5C (AviSynth script) and http://pastebin.com/aUzKTvdj (output processor coded in PHP)
It only works for converting 30000/1001 fps content into 24000/1001~30000/1001 fps (vfr).
What does it do:

"FieldDetect"
Find which frame is interlaced and determine its parity if it's the first frame of each interlaced sequence, and save it to file "out.txt"
"process.php 1"
Create a deinterlace strategy using "out.txt" and in PHP file, and save the file to "in.txt"
"PrepareDecimation"
Determine how similar is each frame to its previous frame after deinterlace using "in.txt" and save it to another file "in2.txt"
"process.php 2"
Determine which frame to drop and correct timing, assuming:
(1) at most 1 frame is dropped in 5 frames even when all 5 frames are not interlaced
(2) if there is a sequence of continuously interlaced frames, always drop 1 frame
and finally re-time the frames if at least 1 frame is dropped in every 5 frames
If the original sequence was (a b:dropped c d e f) and b-a=c-b=d-c=e-d=f-e, then assign c, d, e new values so that f-e=e-d=d-c=c-a
Save the frames to delete in "df.txt" and timecode v2 into "timecodes.txt"
"Use, DeleteFrame"
copy the content in "df.txt" into the script and encode





Any help will be appreciated!

StainlessS
13th December 2016, 19:08
Maybe qCombed [mod of IsCombed from Decomb plug) is easier to mod, but it is not same as IsCombedTIVTC (or whatever its called)].
http://forum.doom9.org/showthread.php?t=173754&highlight=QCombed

It has 2 functions,
1 ) same as IsCombed() returning metric.
2 ) write list of combed frames to a file.

It is just a runtime function, does not create a filter (as IsCombed, which later destructs filter before return), and may be easier to understand.

soreepeong
13th December 2016, 19:17
http://forum.doom9.org/showthread.php?t=173754&highlight=QCombed

The feature that outputs the list of combed frame sounds great! Thing is, I don't see the file in both mediafire and sendspace; what filename should I look for?

StainlessS
13th December 2016, 20:19
Oops, sorry, posted somewhere as a temp link, here:- http://www.mediafire.com/file/1a7xrcxfpl29rdv/qCombed_v1.02_dll_20161213.zip

EDIT: Above link updated, added Debug arg since last posted in devs forum.

wonkey_monkey
13th December 2016, 23:54
It is a combed frame

I wouldn't call that combed - it's the same pixels in both fields, but that's not what I'd call "combed".

soreepeong
14th December 2016, 02:03
Oops, sorry, posted somewhere as a temp link, here:- http://www.mediafire.com/file/1a7xrcxfpl29rdv/qCombed_v1.02_dll_20161213.zip
EDIT: Above link updated, added Debug arg since last posted in devs forum.

Thank you! I'll try it out.

I wouldn't call that combed - it's the same pixels in both fields, but that's not what I'd call "combed".
Running the following statement in that frame (function "frame" retrieves the frame before/after i frames)
function frame(clip k, int i){
tr = Trim(k, i, 0)
pad = UnalignedSplice(BlankClip(k, length=-i), k)
return ConditionalFilter(tr, pad, tr, String(i), "<", "0")
}
org = AviSource("VHS 10.avi", fourCC="dvsd").AssumeBFF()
org = org.trim(140784, 147645)

combined1 = Weave(org.SeparateFields().frame(-1)).Subtitle("Weave(org.SeparateFields().frame(-1))", x=10, y=10)
combined2 = Weave(org.SeparateFields().frame(1)).Subtitle("Weave(org.SeparateFields().frame(1))", x=10, y=10)
StackVertical(
\StackHorizontal(combined1, combined2, org.frame(2).ShowCombedTIVTC().ScriptClip("Subtitle(String(current_frame+2), x=710, y=10, align=9)")),
\StackHorizontal(org.frame(-1).ShowCombedTIVTC().ScriptClip("Subtitle(String(current_frame-1), x=710, y=10, align=9)"),
\ org.ShowCombedTIVTC().ScriptClip("""Subtitle(String(current_frame) + " (CURRENT)", x=710, y=10, align=9)"""),
\ org.frame(1).ShowCombedTIVTC().ScriptClip("Subtitle(String(current_frame+1), x=710, y=10, align=9)")
\ )
\)
In here, combined2 results in a non-combed image, which would mean the current and its next frame (2836, 2837) are telecined, but the scene has scrolled only one pixel up, effectively bobbing a scene...
http://i.imgur.com/iOG5Tsil.jpg (http://i.imgur.com/iOG5Tsi.jpg)
(Click to see the full image)