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 Development
Register FAQ Calendar Today's Posts Search

Reply
 
Thread Tools Search this Thread Display Modes
Old 24th October 2022, 16:58   #1601  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Quote:
Originally Posted by poisondeathray View Post
eg.
Code:
.
.
.
a = last
b = a.bwdif(some settings)

Subtract(a,b)

#Levels(127, 1, 129, 0, 255) # for 8bit
#Levels(511, 1, 513, 0, 1023) # for 10bit
I think that the levels are not quite there, are centered around 128 instead of TV levels center ie 126, (16+235)/2.0=125.5 rounded to 126. Subtract centers on 126 whereas the MT_tools subtract thingy centers on 128.

So something like
Code:
.
.
.
a = last
b = a.bwdif(some settings)

Subtract(a,b)

#Levels(125, 1, 127, 0, 255) # for 8bit
#Levels(503, 1, 505, 0, 1023) # for 10bit : (126*4)-1=503 : (126*4)+1 = 505
EDIT: Also, if a is original and b is filtered, then maybe should use Subtract(b,a) rather than Subtract(a,b), so result will be above mid grey
if filtered is lighter than original, and below mid grey if darker than original (Subtract(a,b) will be opposite).

None of above tested.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 24th October 2022 at 17:04.
StainlessS is offline   Reply With Quote
Old 24th October 2022, 17:57   #1602  |  Link
flossy_cake
Registered User
 
Join Date: Aug 2016
Posts: 609
Thank you for all the help, I'm learning a lot here.

On another note...

Quote:
Originally Posted by hello_hello View Post
There's a ChromaShift plugin, but for YV12 it's 2 pixel increments, or 4 if it's interlaced, or if you're really keen and know the exact shift you can use a resizer to compensate. To shift the chroma of a 1080p video 7.3 pixels to the left (it'd be -7.3 to shift it right).

A = last
MergeChroma(A, A.Spline36Resize(1920,1080, 7.3,0,1920,1080))
Regarding the numbers in bold, according to ChromaShiftSP plugin the values 7.3 and 0 need to be added to them -- is this correct?

I've spent hours trying to understand how the resize crop params work but I can't get my head around whether it's shifting the chroma or if it's actually stretching the chroma out from a fixed point (and if so, which point -- center or a corner?).

edit: just realised I can set the offset to a high value and measure the pixels in photoshop. In this case it seem hello_hello's code is correct: good 50px offset, bad chromashiftSP code

A separate problem I'm dealing with is how to crop n lines off the top and bottom, and then zoom in to hide the black bars while preserving aspect.

For a 720x576 16:9 video (which Avisynth sees as square pixels 720x576 with aspect 1.25:1) I've got this code for cropping 50 off the top and bottom:

Resize(Round(576*(16.0/9.0)), 576, 50*(720.0/576.0), 50, -50*(720.0/576.0), -50)

In other words, if I'm cropping 50 off the top and bottom, then I need to crop 1.25 times more pixels of the left and right in order to main aspect (I have no idea if this is right, it's just my thinking) and then finally stretch to 1024 wide to compensate for anamorphic pixels.

Last edited by flossy_cake; 24th October 2022 at 18:48.
flossy_cake is offline   Reply With Quote
Old 24th October 2022, 19:13   #1603  |  Link
flossy_cake
Registered User
 
Join Date: Aug 2016
Posts: 609
Quote:
Originally Posted by poisondeathray View Post
subtract, or overlay with difference mode . You can use levels to amplify the differences
Hmm which one is correct:

Subtract(ChangeFPS(last,50),BWDIF(field=-2))


Subtract(ChangeFPS(last,50),BWDIF(field=-2))
Levels(127, 1, 129, 0, 255)


clip: https://drive.google.com/file/d/1WfW...ew?usp=sharing

edit: perhaps need a threshold so it wont amplify pixels that barely changed at all?

Last edited by flossy_cake; 24th October 2022 at 19:21.
flossy_cake is offline   Reply With Quote
Old 25th October 2022, 10:55   #1604  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Quote:
perhaps need a threshold so it wont amplify pixels that barely changed at all?
Maybe try
Code:
Th =16 # or whatever
center = 126 # TV else 128 PC levels
Levels(center-Th, 1, center+Th, 0, 255)
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 25th October 2022 at 15:42.
StainlessS is offline   Reply With Quote
Old 25th October 2022, 16:09   #1605  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Quote:
I think that the levels are not quite there,
No, they were right, @PDR, you could've pointed out that I was the one that was wrong
(Levels defaulted to Coring=True, so was correct).

Anyways, I've done this before I twigged that I was the wrong'un.

Code:
BlankClip(pixel_type="YV12")
#ConvertBits(10)

#

TV    = true   # Use True if Subtract TV levels.
Th8   = 16     # Threshold, 1 = Max AMP, > 1 reduce AMP.

###
bpc    = Last.BitsPerComponent()
shift  = bpc - 8
mul    = BitLShift(1,shift)
center = (TV) ? 126 : 128    # 126 TV else 128 PC levels
center = center * mul        # center at current bit depth
Th     = Th8 * mul           # Th at current bit depth
oMax   = BitLShift(1,bpc)-1  # 255 @ 8bit, 1023 @ 10 bit
RT_DebugF("bpc=%d Shift=%d mul=%d Center=%d Th=%d oMax=%d",bpc,shift,mul,center,Th,oMax,Name="LEVELS: ") # Write to DebugView (google it)
Levels(center-Th, 1.0, center+Th, 0, oMax, coring = FALSE)
Sorry PDR
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 25th October 2022 at 16:20.
StainlessS is offline   Reply With Quote
Old 26th October 2022, 19:26   #1606  |  Link
flossy_cake
Registered User
 
Join Date: Aug 2016
Posts: 609
Should TFM() be capable of correctly deinterlacing the cheese slices clip?

Apparently all it needs for perfect progressive reproduction is to weave frame A field 1 with frame B field 2, but I can't get TFM to do that (tried all the modes and setting different cthresh & MI values).

I suspect what's happening is it's just detecting all frames as combed.

I can confirm that MadVR can correctly deinterlace it with its "film" mode deinterlacing which I'm told is madshi's own custom CPU code for detecting cadences aka "field matching" like TFM.
flossy_cake is offline   Reply With Quote
Old 26th October 2022, 19:43   #1607  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,377
Quote:
Originally Posted by flossy_cake View Post
Should TFM() be capable of correctly deinterlacing the cheese slices clip?

Apparently all it needs for perfect progressive reproduction is to weave frame A field 1 with frame B field 2, but I can't get TFM to do that (tried all the modes and setting different cthresh & MI values).

I suspect what's happening is it's just detecting all frames as combed.

I can confirm that MadVR can correctly deinterlace it with its "film" mode deinterlacing which I'm told is madshi's own custom CPU code for detecting cadences aka "field matching" like TFM.
Yes, false positive

When you have patterns such as thin horizontal lines, that situation is always going to be detected as false positive and be deinterlaced. You can disable post processing globally with TFM(pp=0) . Or you can use are overrides or exclusion bands (eg. moving text, lower thirds)

In real life, you're typically not going to encounter thin lines such as test patterns, and in real life, you're going to have to use overrides to get it perfect for non standard content
poisondeathray is offline   Reply With Quote
Old 26th October 2022, 20:44   #1608  |  Link
flossy_cake
Registered User
 
Join Date: Aug 2016
Posts: 609
Ok cool. I always thought that test pattern was kind of ridiculous.

Regarding TDeint though, do you reckon it would work better if it used per-block combing detection? i.e if 16x16 block is combed, then treat only that 16x16 block as combed. Currently it seems to think that means the whole frame should be treated as combed:

Quote:
blockx:
Sets the x-axis size of the window used during combed frame detection. This has to do with the size of the area in which MI number of pixels are required to be detected as combed for a frame to be declared combed.
http://avisynth.nl/index.php/TDeint
The way I'm imagining it, a lower cthresh/MI could be used and false positives could be confined to that 16x16 block instead of writing off the whole frame.
flossy_cake is offline   Reply With Quote
Old 29th October 2022, 03:11   #1609  |  Link
flossy_cake
Registered User
 
Join Date: Aug 2016
Posts: 609
I can't seem to detect any difference between:

TDeint(tryWeave=true, full=true)
TDeint(tryWeave=true, full=false)

In both cases it seems to perform combed frame detection according to cthresh,MI,blockx,blocky etc., and returns the full frame if it wasn't detected as combed.

Is my understanding correct, or should there be some difference between the two?
flossy_cake is offline   Reply With Quote
Old 5th November 2022, 03:58   #1610  |  Link
flossy_cake
Registered User
 
Join Date: Aug 2016
Posts: 609
I've been getting into NTSC DVDs a bit lately, but was disappointed to find a few of them appear to be using "soft telecine" where the actual frames seem to be stored in the MPEG2 stream as 23.976p. This sounds great in theory as it wouldn't need any deinterlacing, but I'm finding a few of them have these split-second combing artefacts on scene changes. Annoyingly just enough to produce a visual annoyance that can't be ignored.

What's the best way to deal with this kind of content -- TFM? Decimate? Can it handle these split-second combing artefacts or are they too short to be detected? Keeping in mind this is "soft telecine" not "hard telecine" (the latter being 23.976p living inside a 29.97i stream using the 3:2 pattern -- this is not that).

Also does anyone know what is actually happening with these artefacts -- are they "baked into" the 23.976p image, or is the MPEG2 stream actually changing to 29.97i mid-stream (i.e variable framerate, which MediaInfo reports is true for all of these DVDs).

Of course I could just throw BWDIF at it, but then I'd be wasting half res on anything that moves.

And sadly DXVA deint chokes on "soft telecine" -- produces constant bob artefacts. I don't think it knows the stream is 23.976p and is trying to treat is as hard telecine 29.97i or something.

And MadVRs own "film" deint also cannot detect and repair these split-second combing artefacts either, so it looks like I'll need an Avisynth solution.
flossy_cake is offline   Reply With Quote
Old 5th November 2022, 13:12   #1611  |  Link
Emulgator
Big Bit Savings Now !
 
Emulgator's Avatar
 
Join Date: Feb 2007
Location: close to the wall
Posts: 1,545
Use DGIndex and watch what pulldown results it throws: 100%film, 98,57%film, etc.
Inspect the .d2v index file with Editor.
If the content stems from film there shouldn't be any pulldown transitions.
If you find them these places got to be repaired and left as 23,976p.
Video (credits, VFX) on top of film: there are lots of suggestions, I would go dgmpgdec, QTGMC to 59,94p
If content is animation any valid MPEG-2 pulldown pattern could have been used to match intended animation flow:
The same, dgmpgdec, QTGMC to 59,94p.

I have still a Sponge Bob sample floating around, and it has been discussed here in doom9
__________________
"To bypass shortcuts and find suffering...is called QUALity" (Die toten Augen von Friedrichshain)
"Data reduction ? Yep, Sir. We're that issue working on. Synce invntoin uf lingöage..."
Emulgator is offline   Reply With Quote
Old 6th November 2022, 01:33   #1612  |  Link
flossy_cake
Registered User
 
Join Date: Aug 2016
Posts: 609
Here is a clip of soft telecine 24p containing 2 problematic scene cuts: https://drive.google.com/file/d/1dwa...usp=share_link

For some reason DirectShowSource won't open the file on my system, but FFmpegSource2 and LWLibavVideoSource will. Their parameters rffmode and repeat seem to affect whether they will output it natively as 24p or convert to 60i using the repeat flags stored in the stream. LAV Video Decoder seems to use repeat flags to convert it to 60p and doesn't seem to offer a choice.

edit: actually after more testing, MadVR's film mode deint seems to be handling those combed frame transitions perfectly. DXVA almost gets it right but interpolates those ones and jumps back a field for some reason. Not sure why I was having trouble with it before.

edit: it seems LWLibavVideoSource documentation is wrong: the repeat param seems to default to true or perhaps some auto setting, since not setting it results in repeat fields mode. Setting it to false actually causes the video to play back way too fast at 30fps.

A separate issue is that because Avisynth outputs square pixels I have to scale it to 720x540 but that offsets the field lines which makes it impossible to do MadVR or DXVA deint which happen after Avisynth.

Last edited by flossy_cake; 6th November 2022 at 02:26.
flossy_cake is offline   Reply With Quote
Old 6th November 2022, 02:37   #1613  |  Link
flossy_cake
Registered User
 
Join Date: Aug 2016
Posts: 609
So this seems to work perfectly for handling the problematic combed transitions:

Code:
LWLibavVideoSource(clip)
TFM()
TDecimate()
LanczosResize(720,540)
But as I feared TFM() is having issues with combed frame detection (note the aliasing on the table edges -- the sequence is 24p soft telecine and contains no combing artefacts)



I'll have to play around with the thresholds to see if it can be improved, but my experience with TDeint seems to imply it's going to be difficult and/or need per-scene thresholding.

edit: PP=0 seems to help with that.

Last edited by flossy_cake; 6th November 2022 at 11:11.
flossy_cake is offline   Reply With Quote
Old 6th November 2022, 03:55   #1614  |  Link
kedautinh12
Registered User
 
Join Date: Jan 2018
Posts: 2,156
Quote:
Originally Posted by flossy_cake View Post
So this seems to work perfectly for handling the problematic combed transitions:

Code:
LWLibavVideoSource(clip)
TFM()
TDecimate()
LanczosResize(720,540)
But as I feared TFM() is having issues with combed frame detection (note the aliasing on the table edges)


I'll have to play around with the thresholds to see if it can be improved, but my experience with TDeint seems to imply it's going to be difficult and/or need per-scene thresholding.

edit: PP=0 seems to help with that.
you can try:
Quote:
ex_bob(nnedi3=true).SelectEven()
https://github.com/Dogway/Avisynth-S...%2B.avsi#L1486

or:
Quote:
QTGMC(Preset="Very Slow", Sharpness=0).SelectEven()
kedautinh12 is offline   Reply With Quote
Old 6th November 2022, 19:18   #1615  |  Link
Emulgator
Big Bit Savings Now !
 
Emulgator's Avatar
 
Join Date: Feb 2007
Location: close to the wall
Posts: 1,545
How has the .mkv been obtained ?
Throwing it at VirtualDub2 gets repeated frames and the mentioned combs.
MPEG2Source sees FINISHED 95.69% FILM
Flagging borked or DVD borked ?
I would suggest to go back to the .vob and work from there.
__________________
"To bypass shortcuts and find suffering...is called QUALity" (Die toten Augen von Friedrichshain)
"Data reduction ? Yep, Sir. We're that issue working on. Synce invntoin uf lingöage..."

Last edited by Emulgator; 7th November 2022 at 15:26. Reason: (had wrongly called DGSource)
Emulgator is offline   Reply With Quote
Old 6th November 2022, 20:02   #1616  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Quote:
go back to the .vob and work from there.
+1

If its DVD VOB, then better use DGIndex [EDIT Mpeg2Source(d2v] and TFM(d2v=d2v_Filename), DGSource dont work with d2v arg. [EDIT: or rather, TFM, dont work with d2v=dgi_Filename]
(you sometimes get mid frame edits (edits split on 2nd field) and Perverse Telecine where progressive fields split across frames.)

TFM on VOB will also announce presence of illegal field transitions with d2v arg. [throw error]
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 7th November 2022 at 10:30.
StainlessS is offline   Reply With Quote
Old 6th November 2022, 21:17   #1617  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,377
Quote:
Originally Posted by flossy_cake View Post
So this seems to work perfectly for handling the problematic combed transitions:

Code:
LWLibavVideoSource(clip)
TFM()
TDecimate()
LanczosResize(720,540)
But as I feared TFM() is having issues with combed frame detection (note the aliasing on the table edges -- the sequence is 24p soft telecine and contains no combing artefacts)

<snip>

I'll have to play around with the thresholds to see if it can be improved, but my experience with TDeint seems to imply it's going to be difficult and/or need per-scene thresholding.

edit: PP=0 seems to help with that.
Yes, you just have to tweak the parameters for your source

Leaving PP=0 will leave combed frames (scene transitions, orphan fields - fields 220, 490 that have unique full content , but missing their "partner" field pair) , because this is not a 100% soft pulldown source (decimated frame numbers 88, 196 will be combed -ie. the frame before the next scene)

You can use display=true to debug MI , cthresh values. eg. The grid pattern of yellow laundry basket might elicit false positive comb detection because it "looks" like combing. (or any scene that looks like combing, maybe some types of horizontal venetian window blinds).

e.g you can see MI values going as high as 166 in the laundry scene. But the true combed frames have mic of 246 and 228. So if you set mi>166 but <228 eg. mi=170, you should catch everything in this clip (you'd have to check the rest of the DVD to see if those settings are ok), and the orphaned fields will be deinterlaced properly, while not deinterlacing the progressive content frames

DGSource("soft telecine.dgi")
TFM(mi=170, clip2=QTGMC().SelectEven(), display=true)
TDecimate()
poisondeathray is offline   Reply With Quote
Old 7th November 2022, 02:16   #1618  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,829
Quote:
Originally Posted by flossy_cake View Post
But as I feared TFM() is having issues with combed frame detection (note the aliasing on the table edges -- the sequence is 24p soft telecine and contains no combing artefacts)
That doesn't quite make sense because as you said, if it's soft telecine there should be no combing to detect. That looks like some sort of production mess.

It's been mentioned already but after remuxing the MKV as a TS file and opening it with DGIndex:

Frame Rate: 29.970030 fps
Video Type: Film 95.90%
Frame Type: Progressive
Coding Type: B
Colorimetry: BT.470-2 B,G*
Frame Structure: Frame
Field Order:
Coded Number: 256
Playback Number: 2
Frame Repeats: 0
Field Repeats: 0

According to DGIndex (and MediaInfo) it's been encoded as progressive, but given the hard telecine, I assume it should have been encoded as interlaced?

Even without using QTGMC to de-interlace, this fixes 90% of it, but it creates a blended frame on at least one scene change (I only checked one).

TFM(pp=5)
TDecimate()

Last edited by hello_hello; 7th November 2022 at 02:43.
hello_hello is offline   Reply With Quote
Old 7th November 2022, 05:01   #1619  |  Link
flossy_cake
Registered User
 
Join Date: Aug 2016
Posts: 609
Quote:
Originally Posted by hello_hello View Post
That doesn't quite make sense because as you said, if it's soft telecine there should be no combing to detect. That looks like some sort of production mess.
Indeed there shouldn't be, but TFM incorrectly detects there are because of the stippled patterns on various objects in the scene. Disabling TFM and stepping through each frame at a time shows no combing artefacts on that motion sequence. But what I learned recently was that this is only happening because the source filter is disobeying the repeat field flags -- if they are obeyed then I see the expect pattern of 2 combed frames followed by 3 progressive frames.

Quote:
Originally Posted by Emulgator View Post
How has the .mkv been obtained ?
I bought the DVD discs the other day and used MakeMKV to remux it to mkv. So there hasn't been any transcoding (I expect it to be just the original MPEG2 stream living inside mkv file) but I'm not sure if the mkv container uses timecodes as well which could be interfering with it somehow. The snippet was then extracted using XMediaRecode in "copy" mode -- again avoiding any transcoding, but still possible that it could be altering metadata or timecodes in the original mkv file. In theory it shouldn't.

In any case that clip is definitely soft telecine 24p, not 30i or 30p. The earlier seasons of that same show seem to be using hard telecine.

Last edited by flossy_cake; 7th November 2022 at 05:09.
flossy_cake is offline   Reply With Quote
Old 7th November 2022, 05:29   #1620  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
DGIndex Mpeg2Source(d2v) on a DVD VOB d2v would do it better, gives TFM more to work with.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 7th November 2022 at 10:31.
StainlessS is offline   Reply With Quote
Reply

Tags
tdeint, tivtc


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 04:23.


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