PDA

View Full Version : How can I properly deinterlace this ?


BangoO
22nd September 2004, 00:16
Hi,

I have an HDTV clip (TS file) which I thought was a normal 3:2 1080i file, but it's not at all.
Some frames are progressive, some are interlaced, and it seems to be random...

Here is the link to a a sample:
https://s6.yousendit.com/d.aspx?id=AB7ACE7E01F179D4D07DD84BC14B24B4

What should I do to deinterlace this properly ?
If I don't blend, I get frame repeats and therefore jerky playback.
If I blend, it's smoother but very blurry (of course).

Is there any way to get a proper playback ?

Thx ! ;)

BangoO
24th September 2004, 11:25
The link does not work anymore, so here is the file:
http://perso.wanadoo.fr/bangoo/test.ts

Mug Funky
24th September 2004, 16:06
w00t! thanks for the sample... i haven't been able to play with much HD content.

it's probably a hybrid clip, if so you'll have to find a way that you feel comfortable with - either IVTC and decimate to 23.976 and get some jerky and possible combing in the hybrid bits, or IVTC without decimating and get jerkyness on film bits, or bob the lot of it and end up with a huge file.

i'll give you some more hints when the sample's finished downloading.

[edit]
hmm... this seems to IVTC perfectly allright with just smartdecimate or telecide (smartdecimate being a fair bit faster, which is good for me cause my computer chokes on frames this big).

BangoO
24th September 2004, 17:36
Nope, Telecide does not give something acceptable, to me at least.
I mean, it does its job, but this way the video can't be perfectly smooth, which is the goal.
I tried FieldDeinterlace (or Telecide with blend=true) and it's definitely smoother but then some frames are really blurry.

I don't think there is a solution, but I was asking anyway...

Thx for you answer :)

Aktan
25th September 2004, 06:04
IT() seems to have smooth motion, but there are artifacts. Try it and see if that is good enough.

Edit: Nevermind, it isn't smooth.... and the artifacts might acually be from the source..

scharfis_brain
25th September 2004, 11:20
how do I convert *.ts to *.mpg properly?

hdtvtompeg2 only returns unusable files ?!?

BangoO
25th September 2004, 11:23
You need the 1.09 version to do that, the other one have a bug:
http://perso.wanadoo.fr/bangoo/HDTVtoMPEG2.exe

scharfis_brain
25th September 2004, 12:35
jep. the common speed-up stuff with orphaned fields.
( http://forum.doom9.org/showthread.php?s=&threadid=77798&highlight=fdecimate )

but in your cas, the orphaned fields
bob() -> frame 90 & 91

do have a such bad quality, that no decimator will be able to catch them, exept, you are very patience to knock out the crap-field after the orphaned field out maually.
then you should get an almost fluid 24.72 fps (twenty-four point seven-two)
film.

after using bob() I found out this pattern:

almost 3:2:3:2 ....

and now the anomalities:



Field | remark
------+--------
24 only two instead of
25 three fields

58 only two instead of
59 three fields

90 orphaned field (only one instead of 2 fields)
91 first field of the tripled field after.
this one is damaged, needs to be replaced manually

124 orphaned field (only one instead of 2 fields)
125 first field of the tripled field after.
this one is damaged, needs to be replaced manually

158 orphaned field (only one instead of 2 fields)
159 first field of the tripled field after.
this one is damaged, needs to be replaced manually

189 only two instead of
190 three fields

224 only two instead of
225 three fields


as you can see, the anomalities occur almost in a cycle of every 30 to 34 fields.

maybe there is an automatic way to do this (remove crappy non-decimatable fields).
let me think about it this weekend.

scharfis_brain
25th September 2004, 13:19
I can't believe that!

fdecimate does handle this weird stuff without any jerk!

so, my current script looks like this:

function matchbob(clip c, int "cth", bool "show")
{
show = default(show, false)
global cth = default(cth,6)

ord = c.getparity() ? 1 : 0
odd = c.doubleweave().selectodd().telecide(order=1-ord,post=0)
even = c.telecide(order=ord,post=0)
tel = interleave(even,odd).duplicateframe(0)

analyse = tel.greyscale()

tel = show ? tel.subtitle("fieldmatched") : tel

bobbed = c.TDeint(mode=1, order=ord, mthreshL=8, mthreshC=10,type=1,mtnmode=1)
bobbed = show ? bobbed.subtitle("bobbed") : bobbed

conditionalfilter(analyse,tel,bobbed,"iscombed(cth)","==","false")
}

function doubletelecide (clip c)
{ ord = c.getparity() ? 1 : 0
odd = c.doubleweave().selectodd().telecide(order=1-ord,post=0)
even = c.telecide(order=ord,post=0)
interleave(even,odd).duplicateframe(0)
}

loadplugin("D:\x\dgdecode.dll")
loadplugin("D:\x\tdeint.dll")
loadplugin("D:\x\decomb511.dll")
loadplugin("D:\x\fdecimate.dll")

mpeg2source("test.d2v",iPP=true,CPU=4)
matchbob()
fdecimate(rate=24.71)

BangoO
25th September 2004, 14:07
Thx a lot !

I'm gonna test this as soon as I can :)

BangoO
25th September 2004, 14:17
I'm trying with mpeg2dec3.dll instead of dgdecode.dll, is it a problem ?

I Assume there is no way to get something smooth at 23.976 or 29.97fps ?

scharfis_brain
25th September 2004, 14:51
I'm trying with mpeg2dec3.dll instead of dgdecode.dll, is it a problem ?

no problem

I Assume there is no way to get something smooth at 23.976 or 29.97fps ?

the true framerate is 24.71 fps, so you either have to slowdown this film to 23.976fps or, what I did with my tests:
I speed it up to 25fps, cause the deviation is smaller, than the slowdown to 23.976

btw. what's your destination format? DVD (SAP) or AVI (PC)

BangoO
25th September 2004, 15:28
Destination format is AVI (WM9).

I tried your script on the sample and it's smooth but I see lots of deinterlacing artifacts.
I tried it on another sample from the same source, and there are missing frames :(
I really don't think there is a perfect solution to this king of crap...

scharfis_brain
25th September 2004, 15:42
I tried your script on the sample and it's smooth but I see lots of deinterlacing artifacts.
this is not mine or the scripts fault.

it is the source. it has been upsized from SDTV to HDTV using some kind of
Film -> Telecine -> NTSC -> IVTC -> Upsampling -> HDTV

whereby the NTSC-source (480 lines) had been sped up by dropping fields.

now, the IVTC was completely made crazy by those orphaned fields, resulting in those crappy-quality orphaned fields.

look at the fields using a simple bob(). the crap is already in your source.

I tried it on another sample from the same source, and there are missing frames

hmmm. seems, that they've used a non-constant speedup.
meaning, that you'll need to count the frames & decimate it with individual framerate for eachother scene, which is not of the same speed.

so, if wou are going to AVI-WM0, just leave the video as it is )59.94 Full FPS), using this script:

crop(0,0,0,-9)
matchbob()
lanczosresize(848,480)
limitedsharpen() #;- didée's function for detail enhancement

BangoO
25th September 2004, 15:48
It has not been upsized, the quality is real HDTV.
But I get your point anyway.

I know the crap is in source, I though that maybe with some magic it could be fixed, but I knew there was no solution :)

I'll try the matchbob and tell you how it looks.

scharfis_brain
25th September 2004, 15:52
It has not been upsized, the quality is real HDTV.

where do you got this information from?


looking at the orphaned fields tells me, that there had been some resizing! (UP-sizing!)

in my tests, I was able to downsize it to lower than 480 lines & upsize it to 1080 again, without any noticeable sharpeness loss.

that's why I recommened 848x480 with limitedsharpen.


before:

http://home.arcor.de/scharfis_brain/samples/bango0-before.png

after:
http://home.arcor.de/scharfis_brain/samples/bango0-after.png

so, I ask you, why is the HDTV-Source not (at least) as sharp as the sharpened and downscaled image ?!?

BangoO
25th September 2004, 18:19
If you prefer the second image to the first one, then we really don't have the same conception of a good image :)
Now, try to watch a movie with the original and the second one resized to 480p on a 1920*1080p display, I bet you'll notice a difference ;)

Anyway, thx a lot for your help and time on this, but I will finally use the FieldDeinterlace() to blend the interlaced frames.
It's the only way to get something barely acceptable...

scharfis_brain
25th September 2004, 18:36
Now, try to watch a movie with the original and the second one resized to 480p on a 1920*1080p display, I bet you'll notice a difference

yeah. my 480p is crisper, than the original 1080p

but, all I wanted to say is, that there is only 480p image information in this sample.

you can easily compare

a=source.crop(0,0,0,-8)
b=a.lanczosresize(848,480).lanczosresize(1920,1080).subtitle("480p")
interleave(a,b)

there is no visible difference between 1080p & 480p!

but, I think, I've oversharpened the image, so the artifacts are enhanced a lot, too.

uh? fielddeinterlace?
blends?
that results in a jerky and ghosty 29.97 fps stream.

why not using matchbob?

it gives you 59.94 fps, that are better compressible and smoother, than a blended 29.97 fps stream!

BangoO
25th September 2004, 18:56
I captured both the 1080 and 1080->480->1080, and I'm sorry but there is definitely a difference, most of it on backgrounds which are much sharper in the 1080.
This is not the finest HDTV transfer, but to me this is definitely HDTV material and not upconvert.

Anyway... I'll try the matchbob again tonight or tomorrow, maybe I did something wrong then...

And, oh yes, you applied far too much sharpness to your second 480p capture :)

scharfis_brain
25th September 2004, 19:10
it's up to you, what you're doing with your videos :)

I've mad a short test.
both times I used XVid with a constant quant of 4 and a frame size of 848x480.
(okay if you want to keep HDTV, go for 1280x720p, but I wouldno go higher, cause it would be waste)

fielddeinterlace(blend=true).lanczosresize(848,480)

resulted in jerky 29.97 fps with 1756 kBytes

matchbob().lanczosresize(848,480)

resulted in 59.95 fps with 1516 kBytes, which is 16 % less size while retaining the smooth motion!

BangoO
25th September 2004, 20:03
I do 720p, and I agree that doing 1080p is a waste ;)
The point here is to keep a quality close to the original for 1/3 1/2 of the original size.

I'll try your script again and get back at you sometimes tomorrow.

BangoO
25th September 2004, 23:51
Ok you are right, matchbob() is the best solution for this file.
Thx a lot for your help ;)

scharfis_brain
25th September 2004, 23:56
one last semi-ontopic-question:

which series/film is this sample from?

EDIT: btw. there is some idae in my mind, that could help a little bit on those 3-2-3-1-3-2-3 places in the videos (where the bad encoded fields are)

a 3-2-3-1-3-2-3 place (the number represents the dupe-count) results in a short jerk.

my idea i to break up the
3-2-3-1-3-2-3 pattern to a
3-2-3-2-2-2-3 pattern by modifying matchbob().

this should result in a more smooth video at these places and also should gain compressibility a bit, because the (defective) orphaned is shown twice and the first field of the following triple (which is also an defective one) gets deleted.

if you should wish this functionality, I would implement it. If not, just forget about it.

BangoO
26th September 2004, 14:03
This is a sample from Final Destination 2.

About the new implementation of matchbob, if you think it will be better and if it's not too long to implement, I would really like it ;)

BangoO
29th September 2004, 10:11
scharfis_brain ? ;)

scharfis_brain
29th September 2004, 14:43
here it is. Have fun.

function bangoOmatchbob(clip c, int "cth", bool "show")
{
show = default(show, false)
global cth = default(cth,6)

ord = c.getparity() ? 1 : 0
odd = c.doubleweave().selectodd().telecide(order=1-ord,post=0)
even = c.telecide(order=ord,post=0)
tel = interleave(even,odd).duplicateframe(0)

analyse = tel.greyscale()

global tel = show ? tel.subtitle("fieldmatched") : tel

global bobbed = c.tdeint(mode=1)
global bobbed = show ? bobbed.subtitle("bobbed") : bobbed

global an2=analyse
global an1=an2.duplicateframe(0)
global an0=an1.duplicateframe(0)
global an3=an2.deleteframe(0)
global an4=an3.deleteframe(0)

x0=scriptclip(an0,"cy ? bobbed : cx ? bobbed.duplicateframe(0) : cz ? bobbed : tel")
x1=x0.frameevaluate("")
x2=x1.frameevaluate("cz = c2")
x3=x2.frameevaluate("cy = (c1==false && c2==true && c3==true && c4==false) ? true : false")
x4=x3.frameevaluate("cx = (c0==false && c1==true && c2==true && c3==false) ? true : false")
x5=x4.frameevaluate("c4=an4.iscombed(cth)")
x6=x5.frameevaluate("c3=an3.iscombed(cth)")
x7=x6.frameevaluate("c2=an2.iscombed(cth)")
x8=x7.frameevaluate("c1=an1.iscombed(cth)")
x8.frameevaluate("c0=an0.iscombed(cth)")

}

BangoO
29th September 2004, 15:03
Once again, thx a LOT ;)
I'll test that as soon as I can.

BangoO
29th September 2004, 15:33
By the way, if you have 5 minutes, could you explain the script ?
I'm curious to know what it does exactly, and how it does it :)

scharfis_brain
29th September 2004, 15:51
then normal matchbob works this way:

1) it tries to match the fields.
(like telecide. but here with full framerate!)

2) if that fails (combing visible), it falls back to bobbing deintlacing

the modified matchbob works this way:

if an orphaned field is present, the output of the fullframerate fieldmatching ( 1) )

has always two frames being combed, surrounded by non combed (progressive frames)

those two combed frames are getting replaced with the orphaned field (it gets showed twice)

but note: use this bangoOmatchbob() only with your kind of video (orphaned fields in an else 2:3 pulldowned video)

BangoO
29th September 2004, 23:53
Thx !