Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 28th July 2012, 17:04   #1  |  Link
sirt
x264 fan
 
sirt's Avatar
 
Join Date: Feb 2011
Location: In the trap
Posts: 458
How to handle a fade applied to hard telecine?

Hello,

It's me again (!) ; What would you do to correct something like this ? Otherwise, I don't know how to call this :horizontal interlaced lines ?




I've tried several filters with no sucess :

Code:
vinverse(sstr=0.4,amnt=255,uv=3,scl=0.25) 
vinverse(sstr=1.6,amnt=255,uv=3,scl=0.25) 
vinverse(sstr=3,amnt=255,uv=3,scl=0.25)
(Depending on how marked are the artefacts)

But I don't get any satisfying result because each variant is either blurred either not corrected enough

Code:
blur(1)
One word comes to my mind : awful !

Code:
QTGMC(preset="slower")
It simply doesn't work well

So I have no idea what more I could do ; I want to delete those lines. It usually works well with vinverse but this time I have no luck.
sirt is offline   Reply With Quote
Old 28th July 2012, 17:48   #2  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,860
Maybe
Code:
blur(amountV=.5)
It almost looks like a purposeful "video effect". I've never seen anything like it as a video problem.
jmac698 is offline   Reply With Quote
Old 28th July 2012, 17:54   #3  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,390
Maybe it's an intended Effect, maybe it's just interlaced content that has been stupidly resized progressively.

In any case, a 1023x682 screenshot tells pretty much nothing.

All screenshots shall be posted at 1:1 original pixels. Always. You shall not resize.
__________________
- We´re at the beginning of the end of mankind´s childhood -

My little flickr gallery. (Yes indeed, I do have hobbies other than digital video!)
Didée is offline   Reply With Quote
Old 28th July 2012, 18:08   #4  |  Link
Wilbert
Moderator
 
Join Date: Nov 2001
Location: Netherlands
Posts: 6,301
It looks a bit like interference. Where did you get the footage from? Try DeFreq for example: http://avisynth.org.ru/defreq/defreq.html
Wilbert is offline   Reply With Quote
Old 28th July 2012, 18:18   #5  |  Link
sirt
x264 fan
 
sirt's Avatar
 
Join Date: Feb 2011
Location: In the trap
Posts: 458
Quote:
Originally Posted by Wilbert View Post
It looks a bit like interference. Where did you get the footage from? Try DeFreq for example: http://avisynth.org.ru/defreq/defreq.html
Thanks for your reply. As explained in another thread, it is another footage I use at my work. Mostly are Uncompressed YUV videos and MPEG2 like that one ; I took several pictures and also made a small sample but it's not possible to share the entire source. Most of this stuff is destined for broadcast or TV channels. I do have to correct the defaults then do encoding tests on them with a new h264 encoder.
sirt is offline   Reply With Quote
Old 28th July 2012, 18:23   #6  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,860
The picture posted created the black lines, they are not in the video. The actual problem is what you might call aliasing. It seems like some of the fields are a blend of two fields. Yes, it looks like the top fields are ok and the bottom fields are a blend of the top and bottom fields.
A quick solution would be to deinterlace with qtgmc.
Another idea is to try a subtraction.

Ok here's what it is, I suppose you would call it a blend deinterlace. There 3 clean progresive frames followed by 2 aliased frames. It seems these came from the original combed frames of a 3:2 pulldown sequence. They've been blended so that the top and bottom fields are one.

Last edited by jmac698; 28th July 2012 at 18:41.
jmac698 is offline   Reply With Quote
Old 28th July 2012, 18:58   #7  |  Link
sirt
x264 fan
 
sirt's Avatar
 
Join Date: Feb 2011
Location: In the trap
Posts: 458
Quote:
Originally Posted by Wilbert View Post
It looks a bit like interference. Where did you get the footage from? Try DeFreq for example: http://avisynth.org.ru/defreq/defreq.html
I've tried something like this but I have no idea how I could parameter DeFreq :

Code:
Defreq(fx=0.0, dx=3.0, fy=63.9, dy=4.0, sharp=8.0, fx2=0.0, dx2=8.0, fy2=0.0, dy2=3.0, sharp2=8.0, show=0, plane=2)
But it doesn't do anything.

Quote:
Originally Posted by jmac698 View Post
The picture posted created the black lines, they are not in the video. The actual problem is what you might call aliasing. It seems like some of the fields are a blend of two fields. Yes, it looks like the top fields are ok and the bottom fields are a blend of the top and bottom fields.
A quick solution would be to deinterlace with qtgmc.
Another idea is to try a subtraction.

Ok here's what it is, I suppose you would call it a blend deinterlace. There 3 clean progresive frames followed by 2 aliased frames. It seems these came from the original combed frames of a 3:2 pulldown sequence. They've been blended so that the top and bottom fields are one.
Well when deinterlacing with QTGMC :

Code:
QTGMC(Preset="very slow",TR0=2,TR1=2,TR2=0,Sharpness=0.1,SourceMatch=3,EZKeepGrain=1.4,NoisePreset="faster",EdiMode="NNEDI3",Lossless=2).selectodd()
It result in flickering, so I guess I don't know how to configure it !

EDIT : so i've decided to upload this because it may help you more even though I am reluctant to do this : http://www.sendspace.com/file/6wdv9i

Last edited by sirt; 28th July 2012 at 19:02.
sirt is offline   Reply With Quote
Old 28th July 2012, 19:03   #8  |  Link
Wilbert
Moderator
 
Join Date: Nov 2001
Location: Netherlands
Posts: 6,301
Could you upload the sample somewhere?
Wilbert is offline   Reply With Quote
Old 28th July 2012, 19:06   #9  |  Link
sirt
x264 fan
 
sirt's Avatar
 
Join Date: Feb 2011
Location: In the trap
Posts: 458
Yes, please check my EDIT above. I have forgotten to say the pictures refer to the iVTC result.
sirt is offline   Reply With Quote
Old 28th July 2012, 19:23   #10  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,860
It's fieldblended film->telecine->NTSC
I tried this
Code:
srestore(frate=23.976,omode="pp3")
decimate(cycle=5, quality=0)
It didn't do anything about the 2 of 5 frames that are bad.
I tired Scharfi's manual fix, that didn't work well either.
jmac698 is offline   Reply With Quote
Old 28th July 2012, 19:29   #11  |  Link
sirt
x264 fan
 
sirt's Avatar
 
Join Date: Feb 2011
Location: In the trap
Posts: 458
Thanks jmac698, I have identical result anywhere in the video e.g. anything is corrected.

In fact the only good filter seems to be vinverse (see my settings above) but it is not enough there. When using sstr near 1 or below it blurs too much even if the interference lines are deleted. I think we need something similar to vinverse there
sirt is offline   Reply With Quote
Old 28th July 2012, 19:34   #12  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,860
I don't know what vinverse does, but I understand the problem now.
I think you could use something I made before, which I called DOCI
http://forum.doom9.org/showthread.php?t=158230

Except not that exactly; but modified to work on luma instead of color.

This is the normal 3:2 pulldown pattern:
Code:
t0...t0...t1...t2...t3...t4...t4  top fields of NTSC video
b0...b1...b2...b2...b3...b4...b5  bot fields of NTSC video
cln  lac  lac  cln  cln| cln  lac
t0 means the top field of film frame 0, b0 means the bottom field of film frame 0.

What that means is, NTSC frame 0 has film frame 0 as the top field and film frame 0 as the bottom field.
Since both NTSC fields come from the same film frame, it's a progessive or clean (cln) frame.
Next is a combed or interlaced (lac) frame. The two NTSC fields come from different film frames.

Your problem is that in this frame, the two fields are blended. This means
NTSC top field=(t0+b1)
NTSC bot field=(t0+b1)
Since they are both the same value, it makes a tall pixel, which looks blocky. (I wouldn't call them lines)
The solution is to use a subtraction.
We must recreate film frame 1.

The answer is the equation:
b1=(t0+b1)-t0
t1=(t1+b2)-b2
This means to separatefields, then subtract the first blended frame, top field from the last top field. This becomes a new bottom field.
For the 2nd blended frame, subtract the bottom field from the next bottom field. This becomes a new top field.
Erase the two blended frames, and replace with the new frame.
Now you have only 4 of the 5 frames, and the framerate is now 23.976fps, and you've recovered the film frames.
You could then do your job of encoding it directly to AVC. Otherwise, for mpeg you should encode with soft telecine.

Last edited by jmac698; 28th July 2012 at 19:50.
jmac698 is offline   Reply With Quote
Old 28th July 2012, 20:02   #13  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,860
First version, not finished
--
First bug, is subtracting rec601 levels luma correctly.
--
Ok, can't finish this right now.
Code:
MPEG2Source("C:\project001a\aliasing sample\awful.d2v")
#Reconstruction of field-blended film to pulldown to NTSC filter by jmac698 (unblendfilm2telecine)
#v0.1
#Field-blended deinterlacing of telecined video leads to two bad looking frames out of every 5
#This filter will correct the problem
#the original film frames are output.  The input is 29.97 and the output is 23.976
#Known issues: still a bit of garbage left, non-adaptive - but can use editing to make it work for real, restored color has lost 1bit of accuracy,
#Set the phase here, the filter works on a fixed pattern

trim(2,0)
destroyed=last
#reconstruct frames
restored=unblendfilm2telecine
#Show the ivtc'd video; compare against non-restored version
restored.simpleivtc
Crop(0, 64, -0, -64)

function restoreluma(clip destroyed, clip clean) {
  #restores merged chroma from destoyed by subtracting clean, one of the mergee's
  #destroyed=(clean+unknown)/2, unkown=(destroyed-clean/2)*2
  #First, remove luma offset of 16
  destroyed=destroyed.tweak(bright=-16)
  clean=clean.tweak(bright=-16)
  Overlay(destroyed, clean.tweak(cont=.5), mode="Difference", pc_range=true).tweak(bright=-128).tweak(cont=2).tweak(bright=16)
  #now merge with existing luma
  #note: there is no precision loss compared with d*2-c because d and c are always even;
  #  because the destruction was d=(c+unknown)/2
  mergechroma(last,destroyed)
}

function unblendfilm2telecine(clip in) {
  #Expects and returns a frame based clip
  #Restore destroyed chroma; four fields out of 10
  #note that if the pulldown pattern is distrupted, you may have to trim/edit the output
  #Extract all the fields
  #Need f1, f3, f4, f6 to reconstruct
  #Output 0,1,0,newf3,newf4,7,6,7,8,9
  #Note: I considered using DoubleWeave, but that doesn't give me the combinations two fields apart which I need
  in.assumetff.separatefields
  f0=selectevery(10,0)
  f1=selectevery(10,1)
  f2=selectevery(10,2)
  f3=selectevery(10,3)
  f4=selectevery(10,4)
  f5=selectevery(10,5)
  f6=selectevery(10,6)
  f7=selectevery(10,7)
  f8=selectevery(10,8)
  f9=selectevery(10,9)
  newf3=restoreluma(f3,f1)#new 1bot
  newf4=restoreluma(f4,f6)#new 1top
  interleave(f0,f1,f0,newf3,newf4,f7,f6,f7,f8,f9)
  weave
}

function simpleivtc(clip in) {
  #IVTC for a fixed 3:2 pulldown pattern, non-adaptive, returns 4/5 framerate clip (i.e. 24fps from 30fps)
  in.swapfields.doubleweave
  pulldown(0,3)
}

Last edited by jmac698; 28th July 2012 at 20:27.
jmac698 is offline   Reply With Quote
Old 28th July 2012, 20:19   #14  |  Link
sirt
x264 fan
 
sirt's Avatar
 
Join Date: Feb 2011
Location: In the trap
Posts: 458
Thanks a lot for your explanations. But I am not able to do that myself I think.

I went to your DOCI post and I savec your script in an AVS file. Then I wanted to apply Demo() but it shows something that I don't understand ; I don't know how to your script.

I also tried your last script but with no success, it seems it highlights problematic frames.

EDIT : Didée made some function called "vinverse2" in my previous Dot crawl thread :

Code:
function Vinverse2(clip clp, float "sstr", int "amnt", int "uv")
{
uv   = default(uv,3)
sstr = default(sstr,2.7)
amnt = default(amnt,255)
uv2  = (uv==2) ? 1 : uv
STR  = string(sstr)
AMN  = string(amnt)
vblur  = clp.sbrV()
vblurD = mt_MakeDiff(clp,vblur,U=uv2,V=uv2)
Vshrp  = mt_LutXY(vblur,vblur.mt_convolution("1","1 2 1"),expr="x x y - "+STR+" * +",U=uv2,V=uv2)
VshrpD = mt_MakeDiff(Vshrp,vblur,U=uv2,V=uv2)
VlimD  = mt_LutXY(VshrpD,VblurD,expr="x 128 - y 128 - * 0 < x 128 - abs y 128 - abs < x y ? 128 - 0.25 * 128 + x 128 - abs y 128 - abs < x y ? ?",U=uv2,V=uv2)
mt_AddDiff(Vblur,VlimD,U=uv,V=uv)
(amnt>254) ? last : (amnt==0) ? clp : mt_LutXY(clp,last,expr="x "+AMN+" + y < x "+AMN+" + x "+AMN+" - y > x "+AMN+" - y ? ?",U=uv,V=uv) 
return(last)
}

function sbr(clip o) {
rg11=o.removegrain(11)
rg11D=mt_makediff(o,rg11)
rg11DD=mt_makediff(rg11D,rg11D.removegrain(11)).mt_lutxy(rg11D,"x 128 - y 128 - * 0 < 128 x 128 - abs y 128 - abs < x y ? ?")
o.mt_makediff(rg11DD,U=2,V=2)
}

function sbrV(clip o) {
rg11=o.mt_convolution("1","1 2 1")
rg11D=mt_makediff(o,rg11)
rg11DD=mt_makediff(rg11D,rg11D.mt_convolution("1","1 2 1")).mt_lutxy(rg11D,"x 128 - y 128 - * 0 < 128 x 128 - abs y 128 - abs < x y ? ?")
o.mt_makediff(rg11DD,U=2,V=2)
}
It is similar to vinverse and call solve some frames.

Last edited by sirt; 28th July 2012 at 20:26.
sirt is offline   Reply With Quote
Old 28th July 2012, 20:30   #15  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,860
vinverse is for removing combing, that's not the problem, but if it helps it's just a coincidence.
I'd like to prove if my script works or not but I don't have time right now.
jmac698 is offline   Reply With Quote
Old 28th July 2012, 20:32   #16  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,390
I don't see anything "blended" in this sample. The problem is that the fades were done after the telecine. I.e. those same-(24p)frame fields that are spread between two 30i frames have different brightness because of that, and don't fit together anymore.

Words too complicated. Diagram!

Code:
a b b c d     < fields
a b c d d     < fields

8 6 4 2 0     < brightness (due to fading)
Frame c cannot be IVTC'ed without artifacts, since the present fields of c have different brightness.

Also, an IVTC filter will have a hard time to do "correct" matching in the first place.

Not to speak of the multiple fieldorder transitions in the sample. "Broken", that is.
__________________
- We´re at the beginning of the end of mankind´s childhood -

My little flickr gallery. (Yes indeed, I do have hobbies other than digital video!)
Didée is offline   Reply With Quote
Old 28th July 2012, 20:32   #17  |  Link
sirt
x264 fan
 
sirt's Avatar
 
Join Date: Feb 2011
Location: In the trap
Posts: 458
No worries I will also try on my own some things and report the potential results there. Thanks for your time spent on this.
sirt is offline   Reply With Quote
Old 28th July 2012, 20:42   #18  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,860
Didée
Thanks for pointing this out, however with my technique the frame c can still be recovered, just use different coeficients.
You say it's not blended, but I'm not using the term properly. I don't believe that a current and previous frame is blended, but two fields in one frame are spatially blended. You can also consider this as blended of two adjacent fields temporally.
Also, if my model is correct, the blends are easy to find; it's any frame where the top and bottom fields equal each other.
You can quickly see that my model is pretty close by subtracting adjacent fields; if there's results that are nearly neutral grey, then the two fields were almost equal.
jmac698 is offline   Reply With Quote
Old 28th July 2012, 20:43   #19  |  Link
sirt
x264 fan
 
sirt's Avatar
 
Join Date: Feb 2011
Location: In the trap
Posts: 458
Quote:
Originally Posted by Didée View Post
I don't see anything "blended" in this sample. The problem is that the fades were done after the telecine. I.e. those same-(24p)frame fields that are spread between two 30i frames have different brightness because of that, and don't fit together anymore.

Words too complicated. Diagram!

Code:
a b b c d     < fields
a b c d d     < fields

8 6 4 2 0     < brightness (due to fading)
Frame c cannot be IVTC'ed without artifacts, since the present fields of c have different brightness.

Also, an IVTC filter will have a hard time to do "correct" matching in the first place.

Not to speak of the multiple fieldorder transitions in the sample. "Broken", that is.
Thanks for having checked this Didée. What do you mean by "broken" ? Isn't there anyhting to do ? I'm surprised jmac698 infers vinverse and also your vinverse2 are not excepted filters to use there in spite of the fact they give an acceptable result on some frames. It is probably some kind of "luck" I guess.
sirt is offline   Reply With Quote
Old 28th July 2012, 20:49   #20  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,860
My theory doesn't seem right. I looked at a subtracted fields. There does seem to be some pattern however.
jmac698 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:13.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2018, vBulletin Solutions Inc.