Log in

View Full Version : De-Bob and resize HDTV 1080i to SD


Steve56
20th January 2005, 00:11
I have a HDTV 1080i PAL stream that I want to resize to SD 720x576 interlace PAL. The script works, but with a little vertical bobbing:
LoadPlugin("C:\dgmpgdec1012\DGDecode.dll")
LoadPlugin("C:\AviSynth 2.5\plugins\BT709ToBT601.dll")
mpeg2source("I:\konzert euro 1080.d2v")

BT709ToBT601()
ConvertToYUY2()

Crop(0, 0, 0, -8) #Because the stream is 1920x1088 px
SeparateFields()
Lanczos4Resize(720,288)
Weave()
Anyone have a quick fix handy?

TIA!

Steve56

scharfis_brain
20th January 2005, 00:24
LoadPlugin("C:\dgmpgdec1012\DGDecode.dll")
LoadPlugin("TDeint.dll")
LoadPlugin("C:\AviSynth 2.5\plugins\BT709ToBT601.dll")
mpeg2source("I:\konzert euro 1080.d2v")
Crop(0, 0, 0, -8) #Because the stream is 1920x1088 px
TDeint(mode=1,tryweave=false)
BT709ToBT601()
Lanczos4Resize(720,576)
#blur(0,0.3) #uncomment, if you want to reduce interlace flicker on high detailed areas on TV
assumetff().separatefields().selectevery(4,0,3).weave()


if oyu want to gain speed, replace tdeint with

leakkernelbob(order=?,threshold=8)
where ? = 1 or 0 depending on the fieldorder of the stream

Steve56
20th January 2005, 00:49
Thanks very much scharfis_brain!

You were even faster, than I could correct a copy-paste
error in my poor script. :)

Steve56

Steve56
20th January 2005, 02:22
This works really perfect!

As I see in your script a "ConvertToYUY2()" is not necessary there.
TDeint() seems generally more powerfull than TomsMoComp, or?

BTW, to output as progressive SD PAL, I did try something like:
...
...

BT709ToBT601()
ConvertToYUY2()
TomsMoComp(-1,15,0)
Lanczos4Resize(720,576,0,0,1920,1080)
What would you make this script like?

Steve56

scharfis_brain
20th January 2005, 14:25
oh, I forgot converttoyuy2() in my script for interlaced anamorphic PAL-output. Also the correct resolution has to be 704x576. 720x576 will result in a wrong Aspect Ratio.


LoadPlugin("C:\dgmpgdec1012\DGDecode.dll")
LoadPlugin("TDeint.dll")
LoadPlugin("C:\AviSynth 2.5\plugins\BT709ToBT601.dll")
mpeg2source("I:\konzert euro 1080.d2v")
Crop(0, 0, 0, -8) #Because the stream is 1920x1088 px
TDeint(mode=1,tryweave=false)
BT709ToBT601()
Lanczos4Resize(704,576)
converttoyuy2()
#blur(0,0.3) #uncomment, if you want to reduce interlace flicker on high detailed areas on TV
assumetff().separatefields().selectevery(4,0,3).weave()


converttoyuy2() is needed for correct reinterlacing, because the common encoders like tmpgenc or cce are only accepting RGB24 / YUY2. with interlaced YV12 they will run in trouble.

if you want progressive anamorphic PAL output try this:

LoadPlugin("C:\dgmpgdec1012\DGDecode.dll")
LoadPlugin("TDeint.dll")
LoadPlugin("C:\AviSynth 2.5\plugins\BT709ToBT601.dll")
mpeg2source("I:\konzert euro 1080.d2v")
Crop(0, 0, 0, -8) #Because the stream is 1920x1088 px
TDeint(tryweave=false)
BT709ToBT601()
Lanczos4Resize(704,576)

Steve56
20th January 2005, 17:08
Originally posted by scharfis_brain
oh, I forgot converttoyuy2() in my script for interlaced anamorphic PAL-output. Also the correct resolution has to be 704x576. 720x576 will result in a wrong Aspect Ratio.

Yes, you are right, forgot to keep the PAR in mind. So, if I want full 720 px horizontal output, I would lose some of the source's vertical lines.

If my calculation is right, then I would just use 1920x1053 -> 720x576 anamorph.

But for the material I have, it is probably better to go the 704x576 way, so I won't lose any image data vertically.

Steve56

scharfis_brain
20th January 2005, 17:26
Yes, you are right, forgot to keep the PAR in mind. So, if I want full 720 px horizontal output, I would lose some of the source's vertical lines.

If my calculation is right, then I would just use 1920x1053 -> 720x576 anamorph.

uhm no.
720 uses exatly the same res. like 704.
it is just a little bit wider.

you won't see more.

Steve56
20th January 2005, 19:11
Originally posted by scharfis_brain
uhm no.
720 uses exatly the same res. like 704.
it is just a little bit wider.

you won't see more.

PAL (720 rect. px) = 704 active px (incl. 2*1 px overscan) + 2*8 px horizontal blanking

Maybe you understood me wrong, I mean if I watch it, for example, on a Software DVD Player, all the 720 pixels will get displayed, I know that on a normal TV I won't see anything of the analog blank, maybe just a little of the overscan. The calculation is only to have a geometrically valid PAL PAR conversion.

I found a strange thing after the re-interlacing. It looks like the interlace combs have a 2 pixel height, instead of only one. Here is a interlaced output frame:

http://www.macologie.de/konzert-wrong-lace.jpg

The camera is slowly panning down in this scene; if I just look at the deinterlaced frames in the script, they are fine. Mhh, maybe this is just as it should be, and on the TV it will look good.

[EDIT] Ahh, maybe the speed of the vertical movement is just interfering with the interlacing lines, that's maybe why it looks like this!?

Steve56

Steve56
20th January 2005, 23:06
The 2 scripts I now will use look like this:

HDTV 1920x1080i PAL -> SD 704x576 interlace PAL
LoadPlugin("C:\Program Files\dgmpgdec1012\DGDecode.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\TDeint.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\BT709ToBT601.dll")
mpeg2source("I:\konzert euro 1080.d2v")
Trim(2,0) #Because mpeg2 stream starts with open GOP
Crop(0, 0, 0, -8) #Because the source stream is 1920x1088 px
BT709ToBT601()
ConvertToYUY2()
TDeint(mode=1,tryweave=false)
Lanczos4Resize(704,576)
#blur(0,0.3) #uncomment, if you want to reduce interlace flicker on high detailed areas on TV
assumetff().separatefields().selectevery(4,0,3).weave()
HDTV 1920x1080i PAL -> SD 704x576 progressive PAL
LoadPlugin("C:\Program Files\dgmpgdec1012\DGDecode.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\TDeint.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\BT709ToBT601.dll")
mpeg2source("I:\konzert euro 1080.d2v")
Trim(2,0) #Because mpeg2 stream starts with open GOP
Crop(0, 0, 0, -8) #Because the stream is 1920x1088 px
BT709ToBT601()
ConvertToYUY2()
TDeint(tryweave=false)
Lanczos4Resize(704,576)

I did use ConvertToYUY2() in both scripts, because if not, then I always see color-smearing (checked script's output in VirtualDubMod).

Thanks again for your help Scharfis Brain!

Steve56

scharfis_brain
21st January 2005, 00:28
Do never ever alter the colorspace before deinterlacing!

As I said before: encoders (vdub, too!) to not like interlaced YV12-colorspace. so you need to convert to yuy2.

but do this after the deinterlacing!

HDTV 1920x1080i PAL -> SD 704x576 interlace PAL

LoadPlugin("C:\Program Files\dgmpgdec1012\DGDecode.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\TDeint.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\BT709ToBT601.dll")
mpeg2source("I:\konzert euro 1080.d2v")
Trim(2,0) #Because mpeg2 stream starts with open GOP
Crop(0, 0, 0, -8) #Because the source stream is 1920x1088 px
BT709ToBT601()
TDeint(mode=1,tryweave=false)
converttoyuy2()
Lanczos4Resize(704,576)
#blur(0,0.3) #uncomment, if you want to reduce interlace flicker on high detailed areas on TV
assumetff().separatefields().selectevery(4,0,3).weave()

HDTV 1920x1080i PAL -> SD 704x576 progressive PAL
LoadPlugin("C:\Program Files\dgmpgdec1012\DGDecode.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\TDeint.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\BT709ToBT601.dll")
mpeg2source("I:\konzert euro 1080.d2v")
Trim(2,0) #Because mpeg2 stream starts with open GOP
Crop(0, 0, 0, -8) #Because the stream is 1920x1088 px
BT709ToBT601()
TDeint(tryweave=false)
ConvertToYUY2()
Lanczos4Resize(704,576)

Steve56
21st January 2005, 01:25
Originally posted by scharfis_brain
Do never ever alter the colorspace before deinterlacing!

As I said before: encoders (vdub, too!) to not like interlaced YV12-colorspace. so you need to convert to yuy2.

but do this after the deinterlacing!
Ok, looks the same to me in VDubMod. Is this only a matter of speed, or is there a more serious reason for deinterlacing first? I thought YV12 -> YUY2 is a "upconversion", so nothing get's lost?

Steve56

Steve56
21st January 2005, 04:05
Sorry scharfis_brain, after a closer look I have to say, that there is more color-smearing visible when ConvertToYUY2() is used after deinterlacing. I will post VDubMod screenshots later.

Steve56

Steve56
21st January 2005, 14:03
ConvertToYUY2() before deinterlace:
http://www.macologie.de/ConvertToYUY2-first.jpg

ConvertToYUY2() after deinterlace:
http://www.macologie.de/ConvertToYUY2-last.jpg

Steve56

scharfis_brain
21st January 2005, 14:18
1) actually the second image shows MORE and PRECISE chroma information, while the first one is smeared (look at the nose. it has chroma where none should be!).

2) this is caused by the wrong chorma upsampling you've used.
you used progressive chorma upsampling with interlaced content. that will destroy all the chroma.

3) chroma upsampling acutally IS lossy. especially when it comes to interlaced upsampling.
with the untouced interlaced-YV12 video a deinterlacer is able to restore the chroma information completely in static scenes.
but if the chroma has bee upsamples interlaced before deinterlacing, the static areas cannot be restored properly anymore.

trust me. my way is the correct one.

Didée
21st January 2005, 14:23
Originally posted by scharfis_brain
trust me. my way is the correct one.
/*continues admiring holy scharfis_brain*/

:D

Steve56
21st January 2005, 14:40
I had no doubt about your knowledge. ;)

As it seems, I just did a wrong interpretation of the resulting images.

To better understand the screenshots, one could say that the first one has a more softened color variation, on some parts on the full image it even looks like the colors diminish into gray. Whereas the second image shows some natural "color-artifacts" because of the poor original quality, but is still closer to the source than the other one (keeping the colors as good as possible and doesn't just throw them away).

Does this explanation cut it?

Then I assume doing the ConvertToYUY2() after deinterlacing is also better than doing it before with ConvertToYUY2(interlaced=true)?

Steve56

scharfis_brain
21st January 2005, 15:13
Originally posted by Didée
/*continues admiring holy scharfis_brain*/
:D

I am drinking some coffee to realize myself
that the first addicted victims
of my interlacing-sect are praying to me.

(Hard shock. But feels good :p
hm. I should really start taking fees)



Originally posted by Steve56
I had no doubt about your knowledge. ;)

Never doubted that ;)

As it seems, I just did a wrong interpretation of the resulting images.
[.....]
Does this explanation cut it?

jep it does. the 'wrong' image (the first one) looks a little bit more equalized/blurred/smoothed which means that it is more pleasant for our eyes.

Then I assume doing the ConvertToYUY2() after deinterlacing is also better than doing it before with ConvertToYUY2(interlaced=true)?

You are very right!
this is the best way to turn interlaced YV12 to YUY2