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 11th April 2020, 16:37   #41  |  Link
Stereodude
Registered User
 
Join Date: Dec 2002
Location: Region 0
Posts: 1,436
Quote:
Originally Posted by bladerunner1982 View Post
Result is version 3 in this folder https://mega.nz/folder/A10lULqT
You made some post processing decisions that I personally wouldn't have made, but that doesn't mean they're wrong. To me it mostly looks like there is a static grain pattern sitting on top of the image much of time that I don't care for.

However, I don't think the MPEG-2 source could be handled much better getting it to 480p24 in a basically automated way. FWIW, you could crop about 4 pixels off the right side at the source filter.

DGDecode_mpeg2source(myvideo, idct=5).crop(0,0,-4,-0)
Stereodude is offline   Reply With Quote
Old 11th April 2020, 20:57   #42  |  Link
bladerunner1982
Registered User
 
Join Date: Apr 2003
Posts: 18
TFM options:
"if PP >= 5 (i.e. using motion adaptation) then TFM will build the mask as usual and only pixels in moving areas will be taken from the frames in clip2."

PP6 = motion-adaptive cubic interpolation deinterlacing... gives to me a sharper picture than PP7 (maybe itīs just my imagination)

And therefore I tend to QTGMC for post processing...MCTemporalDenoise and f3kdb seem to clean to much so there is less detail left for upscaling.

I compared both solutions eye by eye...but tastes differ...

Anyone with a suggestion for a better upscaler?
bladerunner1982 is offline   Reply With Quote
Old 11th April 2020, 22:53   #43  |  Link
Stereodude
Registered User
 
Join Date: Dec 2002
Location: Region 0
Posts: 1,436
Quote:
Originally Posted by bladerunner1982 View Post
TFM options:
"if PP >= 5 (i.e. using motion adaptation) then TFM will build the mask as usual and only pixels in moving areas will be taken from the frames in clip2."

PP6 = motion-adaptive cubic interpolation deinterlacing... gives to me a sharper picture than PP7 (maybe itīs just my imagination)
It's your imagination. The deinterlacing routine isn't used. clip2 is used. The same detection algorithms are used for either.

Quote:
Anyone with a suggestion for a better upscaler?
You could try waifu2x

https://forum.videohelp.com/threads/...fu2x-(AviSynth)

(I haven't tried this)
Stereodude is offline   Reply With Quote
Old 12th April 2020, 01:05   #44  |  Link
Chir
Registered User
 
Join Date: Mar 2020
Posts: 11
So the problem that we have is that some frames need to be reverse telecined and some need to be deinterlaced, but not both. Would that be a correct statement of the problem?

To deal with this, we'd need to create an OVR file (two actually), which if I understand it right, allows us to choose which process to apply to the frame.

If that is a correct statement -- are there any tools to help create the OVR files? Or is this something that you have to step through frame by frame to determine the type and manually create the OVR file?
Chir is offline   Reply With Quote
Old 12th April 2020, 04:43   #45  |  Link
Stereodude
Registered User
 
Join Date: Dec 2002
Location: Region 0
Posts: 1,436
Quote:
Originally Posted by Chir View Post
So the problem that we have is that some frames need to be reverse telecined and some need to be deinterlaced, but not both. Would that be a correct statement of the problem?

To deal with this, we'd need to create an OVR file (two actually), which if I understand it right, allows us to choose which process to apply to the frame.

If that is a correct statement -- are there any tools to help create the OVR files? Or is this something that you have to step through frame by frame to determine the type and manually create the OVR file?
bladerunner1982 and myself have basically hammered out a pretty decent template/theory of handling the episodes.

You want to IVTC all the parts of the original DVD that are encoded as film with a soft pulldown. You still want to IVTC as much of the rest of the video portions as possible. You only want to deinterlace any frames that have residual combing or are interlaced video.

TFM checks for residual combing in a frame and comes up with a number based on how much combing it measures. You set the threshold for how high number that needs to be before it will deinterlace the frame.

You only need an override file when that threshold doesn't work for a section. In S06E01 I found 3 problem areas. 1) At the start of the show "intro", the comet generates a high MIC number despite not being combed. 2) The wormhole opening at the end of the "intro" has combing but doesn't generate a high MIC number. 3) The credits appear to be pure interlaced video.

So, you make an override file with the frame ranges and what it should do for those ranges.
Code:
13329,13945 -
16383,16504 +
79880,81234 p
I expect these issues will happen in every episode. Of course the frame numbers will vary for each episode.

The second issue is that tdecimate doesn't always make the correct decision on whether to drop a frame restoring 24p or to blend the 30p video section to 24p. The most flagrant area it got wrong was the credits, so I made an override to force them to be treated as video (blended).
Code:
79880,81234 v
I expect this issue will also happen in every episode and the frame numbers will need to be adjusted. I'm also undecided if the wormhole opening at the end of the "intro" should be blended or treated as film, but it's something to consider.

So you want to do something like this:
Code:
source=MPEG2Source("VTS_02_1.d2v", idct=5, moderate_h=40, moderate_v=40, cpu2="xxoooo").crop(0,0,-4,-0)

deint=source.QTGMC( Preset="Slower", InputType=0, SourceMatch=3, Lossless=2, Sharpness=0.2, EZKeepGrain=0.0).SelectEven()

#for testing
#source.tfm(d2v="VTS_02_1.d2v", PP=1, MI=24, clip2=deint, display=true, flags=5)
source.tfm(d2v="VTS_02_1.d2v", PP=7, MI=24, clip2=deint, display=false, flags=5, ovr="D:\DS9S6D1\E01\tfm_ovr.txt")

#for testing
#TDecimate(hybrid = 1, dupThresh=1.5, vidThresh=2.0, display=true)
TDecimate(hybrid = 1, dupThresh=1.5, vidThresh=2.0, display=false, ovr="D:\DS9S6D1\E01\td_ovr.txt")
You can visually inspect what TFM is doing and the see the metrics for each frame by uncommenting the first TFM line and commenting out the 2nd. You can to the same for tdecimate by uncommenting the first tdecimate line and commenting out the 2nd. You check TFM and tdecimate separately.

I do not think you need to go frame by frame. I would think a quick skim of the video sections of the episode will be sufficient. The only portions that are video are fades to and from black, the intro, where text is overlaid on the screen, and the credits. The intro and credits should have the same behavior from episode to episode, just update the frame numbers. Fades in and out of black I would just leave be, which really means the only parts you have to check are the text overlays for a few minutes after the intro where they give the guest actors, director, etc.
Stereodude is offline   Reply With Quote
Old 12th April 2020, 18:54   #46  |  Link
SaurusX
Registered User
 
Join Date: Feb 2017
Posts: 135
The interlaced fade-ins and fade outs can be handled with the smartfade() routine right after the IVTC. I think I pulled it out of the AnimeIVTC script. Might as well get rid of those if you can.

Code:
#based on smartfade v0.2 by martino - Aimed at removing interlaced fades in anime. Uses luma difference between two fields as activation threshold.
#mod by thetoof : removed degrainmedian post-processing, 
#		changed how the fields are blended together (average of 2 nnedi interpolations + contra-sharpening to retain more detail) and 
#		added cache parameter to forward the setting of animeivtc to this function
#		renamed global parameter to something less general than "threshold"

function smartfademod(clip c, float "sfthr", bool "sfshow", int "cache") {
    
global sfthr	= default ( sfthr,  0.4 ) # Threshold for fade detection.
show		= default ( sfshow, false ) # Displays luma difference between fields without processing anything.
cache		= default ( cache,   10 ) # Cache the frames to help seeking and other functions requesting many frames

show ? scriptclip(c, "subtitle(string(abs(	  separatefields().selectodd().averageluma() \
            				- separatefields().selecteven().averageluma())))") : \
       scriptclip(c, "sep = separatefields() \
       avg = sep.selectodd().averageluma() - sep.selecteven().averageluma() \
       abs(avg) > sfthr ? interleave(sep.selecteven(),sep.selectodd()).weave().mcdaa3() : last")

cache<0 ? last : last.RequestLinear(8, cache, 5, false, false)

    return last

}

Last edited by SaurusX; 12th April 2020 at 19:31.
SaurusX is offline   Reply With Quote
Old 12th April 2020, 23:00   #47  |  Link
Chir
Registered User
 
Join Date: Mar 2020
Posts: 11
I'm trying to read up and understand so I don't ask too many questions, but I'm a little lost.

I understand what we're trying to do, but I'm struggling to put it all together. I grabbed Season 6, Episode 1 so I could use your examples to learn, but it's not clicking for me.

I started with DVD Decryptor and pulled the epsiode off into a VOB file. I opened the VOB file with DGINDEX and set it to Honor Pulldown flags, then saved the D2V file. I fired up avspmod and pasted the script in that you provided.

I commented things out to do "testing":
Code:
source=MPEG2Source("VTS_02_1.d2v", idct=5, moderate_h=40, moderate_v=40, cpu2="xxoooo").crop(0,0,-4,-0)

deint=source.QTGMC( Preset="Slower", InputType=0, SourceMatch=3, Lossless=2, Sharpness=0.2, EZKeepGrain=0.0).SelectEven()

#for testing
source.tfm(d2v="VTS_02_1.d2v", PP=1, MI=24, clip2=deint, display=true, flags=5)
#source.tfm(d2v="VTS_02_1.d2v", PP=7, MI=24, clip2=deint, display=false, flags=5, ovr="D:\DS9S6D1\E01\tfm_ovr.txt")

#for testing
TDecimate(hybrid = 1, dupThresh=1.5, vidThresh=2.0, display=true)
#TDecimate(hybrid = 1, dupThresh=1.5, vidThresh=2.0, display=false, ovr="D:\DS9S6D1\E01\td_ovr.txt")
When I display the first frame, I the frame, the type of match, and (D2V). I believe this mean that no filters are applied and its just displaying the D2V -- is that correct?

When I get to frame 832 (Kira standing at a control panel, but the start of a Scene change to a CG scene) The (D2V) tag goesaway and it has a MIC=9. At 838, it switches to a Full CG Scnene and goes from Clean Frame to Combed Frame. This continues for frame 1017. I'm assuming this is a frame that TFM detected that it needs to process -- is that correct?


As I progress into the video, I see a few mic values pop up -- but only for a frame or two. I think this is ok, as it appears that a changing scene or lots of movement causes this. However, at 7102 (black screen) the (D2V) indicator goes away again -- is this TFM detecing a frame to process again? It still says CLEAN FRAME with a rather low mic value until frame 7352 (as the comet leaves the screen to the right). You mentioned this part of the video in your comments above, and its where I see problems with my previous attempts -- there is a HUGE jump right here). I'm expecting TFM is picking this up, so I don't need to do anything in the overrride file... is that correct>

You provided a sample ovr for TFM. If I jump to that frame, I'm expecting to see something in the stats change, or something on the screen, that idicates what I'd be looking for to include in the ovr file. At 13329, I see Odo talking to Quark. This appears just after the opening credits are finished (after the cg intro). I don't see anything -- either in the image itself or the TFM debug output that would have clued me in to add this to my ovr file. Any hints at what I should be looking for in these scenes to add them to the override?

I have a hunch that I'm not working with exactly the same media and your examples might be a little off from mine. avspmod claims that I have 81773 frames before decimating.
Chir is offline   Reply With Quote
Old 12th April 2020, 23:41   #48  |  Link
Chir
Registered User
 
Join Date: Mar 2020
Posts: 11
oh, my. I feel like a complete idiot. I had my D2V file pointing to the wrong VOB, so I was actually looking at a different episode...

Time for me to take a break!
Chir is offline   Reply With Quote
Old 13th April 2020, 04:53   #49  |  Link
Stereodude
Registered User
 
Join Date: Dec 2002
Location: Region 0
Posts: 1,436
Quote:
Originally Posted by Chir View Post
When I display the first frame, I the frame, the type of match, and (D2V). I believe this mean that no filters are applied and its just displaying the D2V -- is that correct?
The D2V means TFM is applying an IVTC and assuming the output is progressive (not looking for combing) per the information/flagging in the D2V file. flags=5 forces this behavior (which is desirable here).

Quote:
When I get to frame 832 (Kira standing at a control panel, but the start of a Scene change to a CG scene) The (D2V) tag goesaway and it has a MIC=9. At 838, it switches to a Full CG Scnene and goes from Clean Frame to Combed Frame. This continues for frame 1017. I'm assuming this is a frame that TFM detected that it needs to process -- is that correct?
When D2V disappears you're in a video section of episode and TFM will manually look for a pattern to IVTC. It will also look for combing (possible interlacing) after applying the IVTC. The MIC number is a measure of how much combing it finds.
Stereodude is offline   Reply With Quote
Old 13th April 2020, 14:45   #50  |  Link
bladerunner1982
Registered User
 
Join Date: Apr 2003
Posts: 18
@Chir
Don't worry, I made that error myself...Frame 13329 corresponds to the first VOB file of S06E01 (VTS_02_1.VOB) without any TFM or Tdecimate applied..where the comet is starting. Maybe we should set that file as a reference point
bladerunner1982 is offline   Reply With Quote
Old 13th April 2020, 14:51   #51  |  Link
Stereodude
Registered User
 
Join Date: Dec 2002
Location: Region 0
Posts: 1,436
Quote:
Originally Posted by SaurusX View Post
The interlaced fade-ins and fade outs can be handled with the smartfade() routine right after the IVTC. I think I pulled it out of the AnimeIVTC script. Might as well get rid of those if you can.

Code:
#based on smartfade v0.2 by martino - Aimed at removing interlaced fades in anime. Uses luma difference between two fields as activation threshold.
#mod by thetoof : removed degrainmedian post-processing, 
#		changed how the fields are blended together (average of 2 nnedi interpolations + contra-sharpening to retain more detail) and 
#		added cache parameter to forward the setting of animeivtc to this function
#		renamed global parameter to something less general than "threshold"

function smartfademod(clip c, float "sfthr", bool "sfshow", int "cache") {
    
global sfthr	= default ( sfthr,  0.4 ) # Threshold for fade detection.
show		= default ( sfshow, false ) # Displays luma difference between fields without processing anything.
cache		= default ( cache,   10 ) # Cache the frames to help seeking and other functions requesting many frames

show ? scriptclip(c, "subtitle(string(abs(	  separatefields().selectodd().averageluma() \
            				- separatefields().selecteven().averageluma())))") : \
       scriptclip(c, "sep = separatefields() \
       avg = sep.selectodd().averageluma() - sep.selecteven().averageluma() \
       abs(avg) > sfthr ? interleave(sep.selecteven(),sep.selectodd()).weave().mcdaa3() : last")

cache<0 ? last : last.RequestLinear(8, cache, 5, false, false)

    return last

}
Unless I'm misunderstanding something I don't think works very well. In order to get it to work well on the fades it needs a sfthr value that is low enough it affects lots of non-fading frames.
Stereodude is offline   Reply With Quote
Old 13th April 2020, 16:15   #52  |  Link
SaurusX
Registered User
 
Join Date: Feb 2017
Posts: 135
Quote:
Originally Posted by Stereodude View Post
Unless I'm misunderstanding something I don't think works very well. In order to get it to work well on the fades it needs a sfthr value that is low enough it affects lots of non-fading frames.
It works well enough as-is and makes a noticeable improvement.
SaurusX is offline   Reply With Quote
Old 13th April 2020, 16:35   #53  |  Link
Stereodude
Registered User
 
Join Date: Dec 2002
Location: Region 0
Posts: 1,436
Quote:
Originally Posted by SaurusX View Post
It works well enough as-is and makes a noticeable improvement.
With the default of 0.4?

I'm going to have to disagree with your conclusion. In S06E01 of DS9 the first several fades in and out of black it wouldn't get a single frame. The first one where it would find any affected frames it only gets about 30% of the frames you'd want it to get. And, there are plenty of static scenes where it detects ~.25.

So you have static scenes with no interlaced fading going on with a higher detected value than actual interlaced fades. It doesn't work for this type of content.
Stereodude is offline   Reply With Quote
Old 13th April 2020, 17:55   #54  |  Link
bladerunner1982
Registered User
 
Join Date: Apr 2003
Posts: 18
How about this dirty tweak?

Code:
function smartfademod_ds9(clip c, float "sfthr", bool "sfshow", int "cache") {
    
global sfthr	= default ( sfthr,  0.4 ) # Threshold for fade detection.
show		= default ( sfshow, false ) # Displays luma difference between fields without processing anything.
cache		= default ( cache,   10 ) # Cache the frames to help seeking and other functions requesting many frames

show ? scriptclip(c, "subtitle(string(LumaDifference(separatefields().selectodd().crop(150,180,-150,-16),separatefields().selecteven().crop(150,180,-150,-16))))") : \
       scriptclip(c, "sep = separatefields() \
       diff = LumaDifference(sep.selectodd().crop(150,180,-150,-16),sep.selecteven().crop(150,180,-150,-16)) \
       abs(diff) > sfthr ? interleave(sep.selecteven(),sep.selectodd()).weave().mcdaa3() : last")

cache<0 ? last : last.RequestLinear(8, cache, 5, false, false)

    return last

}
It looks only in the parts of the half-frame, in which the credits are and calculates the absolute Luma difference in it. Then use a sfthr of maybe 1.2...
bladerunner1982 is offline   Reply With Quote
Old 13th April 2020, 18:25   #55  |  Link
Stereodude
Registered User
 
Join Date: Dec 2002
Location: Region 0
Posts: 1,436
Quote:
Originally Posted by bladerunner1982 View Post
How about this dirty tweak?

Code:
function smartfademod_ds9(clip c, float "sfthr", bool "sfshow", int "cache") {
    
global sfthr	= default ( sfthr,  0.4 ) # Threshold for fade detection.
show		= default ( sfshow, false ) # Displays luma difference between fields without processing anything.
cache		= default ( cache,   10 ) # Cache the frames to help seeking and other functions requesting many frames

show ? scriptclip(c, "subtitle(string(LumaDifference(separatefields().selectodd().crop(150,180,-150,-16),separatefields().selecteven().crop(150,180,-150,-16))))") : \
       scriptclip(c, "sep = separatefields() \
       diff = LumaDifference(sep.selectodd().crop(150,180,-150,-16),sep.selecteven().crop(150,180,-150,-16)) \
       abs(diff) > sfthr ? interleave(sep.selecteven(),sep.selectodd()).weave().mcdaa3() : last")

cache<0 ? last : last.RequestLinear(8, cache, 5, false, false)

    return last

}
It looks only in the parts of the half-frame, in which the credits are and calculates the absolute Luma difference in it. Then use a sfthr of maybe 1.2...
I wasn't looking at text, just the video fading in and out of any black (like at commercial breaks). Unless the text is faded into black I would think that leaving it alone is the better option compared to deinterlacing the entire progressive frame degrading it for the sake of the text.
Stereodude is offline   Reply With Quote
Old 14th April 2020, 01:38   #56  |  Link
Chir
Registered User
 
Join Date: Mar 2020
Posts: 11
@Stereodude

A couple questions, if you don't mind. I'm still struggling how I'm supposed to identify the frames that I need to add to the OVR files, and I think I might have identified them. I just want to run it by you.

You gave me the following script -- one to test, and one for production.
Quote:
#for testing
source.tfm(d2v="VTS_02_1.d2v", PP=1, MI=24, clip2=deint, display=true, flags=5)
#source.tfm(d2v="VTS_02_1.d2v", PP=7, MI=24, clip2=deint, display=false, flags=5, ovr="D:\DS9S6D1\E01\tfm_ovr.txt")
Everything looks prety good with the display on, and no override files -- so I flip over to the production one and things start to go south. I end up seeing, during transitions, weird effects -- like portions of the images are blacked out or leftover from the previous frames. It looks like this happens during really quick, brief scene changes. Are these the frames that should get added to the OVR file?



UPDATE:
I think I figured this out. Going over the docs for TFM, I stumbled across the cthresh parameter. It defaults to 9, and suggested values are from 8-12 -- I had to bump it up to 25.

Last edited by Chir; 14th April 2020 at 02:20.
Chir is offline   Reply With Quote
Old 14th April 2020, 02:36   #57  |  Link
Stereodude
Registered User
 
Join Date: Dec 2002
Location: Region 0
Posts: 1,436
Quote:
Originally Posted by Chir View Post
@Stereodude

A couple questions, if you don't mind. I'm still struggling how I'm supposed to identify the frames that I need to add to the OVR files, and I think I might have identified them. I just want to run it by you.

You gave me the following script -- one to test, and one for production.


Everything looks prety good with the display on, and no override files -- so I flip over to the production one and things start to go south. I end up seeing, during transitions, weird effects -- like portions of the images are blacked out or leftover from the previous frames. It looks like this happens during really quick, brief scene changes. Are these the frames that should get added to the OVR file?
Can you give me a frame number where you see this? Is it repeatable?

Are you sure your deinterlaced video from QTGMC is working correctly? You can check this by putting deint at the bottom of your script so that it returns that instead of the output from tdecimate.

Also, for almost the entire episode if both tdecimate lines are commented out you should have one duplicated frame out of every 5. This is normal and expected. tdecimate will remove this duplicated frame and that's how you get 23.976fps content from it.

You shouldn't have to add much of anything to the ovr file for S06E01. I've subsequently looked at the intro more closely and the metrics and have a somewhat different idea on how to treat it that addresses all the fades and largely doesn't rely on the MI to kill off combed frames (since it missed some and flagged some that it shouldn't have).

I'd use this override:
Code:
;intro higher MI override
13331,16497 i 45

;comet override
13331,13947 -

;14243 DS9 title first frame where visible - for alignment

;fade in intro
14717,14786 +----

;fade in intro
15097,15171 +----

;fade in intro
15472,15541 +----

;fade in intro
15821,15872 +-++-

;fade in intro
16145,16186 ----+

;wormhole open override
16382,164502 +

;override for title fade in
17069 -

;override for title fade in
18203 -

;override for title fade in
18478 -

;override for title fade in
18982 -

;override for title fade in
19843 -

;credits override
79880,81234 p
You can use a simple spreadsheet to adjust the frame numbers in the override for the intro for another episode by using the frame number where the DS9 title is first visible to calculate an offset.

Quote:
I was also wondering why PP=1 was in the test line and PP=7 was in the production line. Was that just a mistype?
PP=1 calculates the MIC, but doesn't replace any part of the frame. PP=7 uses some parts of the deinterlaced video. It's not a typo. It's intentional so you can see if the source actual has interlacing that should be replaced or not. If you use 7 (or 6) in that line part of the frame will be replaced and you won't be able to see if it should have been or not.

edit: You should not have to change cthresh. Something else much be wrong and that's not the right fix.

Last edited by Stereodude; 14th April 2020 at 14:21.
Stereodude is offline   Reply With Quote
Old 14th April 2020, 03:52   #58  |  Link
Chir
Registered User
 
Join Date: Mar 2020
Posts: 11
You were spot on with my QTGMC not working. It was returning a mostly black screen. Once I fixed that, the issue went away.

I'm off to play around with your ovr file and see if I can pick up on your method!



I so appreciate all the help and patience!!!
Chir is offline   Reply With Quote
Old 14th April 2020, 04:36   #59  |  Link
Stereodude
Registered User
 
Join Date: Dec 2002
Location: Region 0
Posts: 1,436
Oh, you'll want to change the MI in your TFM call to: MI=33. Otherwise there are two frames, 898 and 900, that need to be added to the override file with a -.
Stereodude is offline   Reply With Quote
Old 14th April 2020, 14:20   #60  |  Link
Stereodude
Registered User
 
Join Date: Dec 2002
Location: Region 0
Posts: 1,436
I've been trying to apply the same processing method to S06E02 and S06E03. S06E02 is largely no issue. S06E03 is a bit more complicated. In it most of the space VFX shots will need to forced (as not combed) in order to avoid false positives and the MIC calculation of quite a few of the video segment after the intro throw high MIC values and will have to be forced (as not combed).

Also, I found a mistake or two in the "intro" portion of the override file I posted last night for S06E01 that I've fixed.
Stereodude 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 22:24.


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