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 30th June 2008, 06:24   #1  |  Link
florinandrei
Registered User
 
Join Date: Jul 2006
Posts: 120
HD 1080i to DVD (all interlaced) - how?

I have an AVCHD file (.m2ts) that I want to convert to DVD. I use HCenc as the MPEG2 encoder, because it offers excellent quality.

The source is 1080i (interlaced, top field first), 29.97 frames / sec.
The destination is DVD, so it's 480i (interlaced), 29.97 frames / sec.

So it's an interlaced-to-interlaced conversion.

First off, I did a straight MPEG2 encoding, no resizing:

Code:
DirectShowSource("E:\video\birthday\STREAM\00000.MTS")
ConvertToYV12()
This worked fine. It produced an MPEG2 stream that was obviously too large (the encoder cannot resize) but looked OK. I opened it up in a player (VLC), hit Play, then Pause. Due to the jaggies on the moving objects, I deduced that the interlacing was preserved correctly. Cool. Now I needed to scale the image down to 720x480.

Code:
DirectShowSource("E:\video\birthday\STREAM\00000.MTS")
LanczosResize(720, 480)
ConvertToYV12()
That looks weird. It's like the moving objects consist of two "ghost" images on top of each other. Like a bad deinterlacer.

I tried a few options, like SeparateFields(), AssumeTFF(), to no avail.

So the problem is to scale down 1080i to 480i, at the same frame rate, while preserving interlacing. What is the "magic incantation" to do that?

By the way, at the end of the file, HCenc just hangs, "this program is not responding", so I have to kill it. Could be HCenc's fault, could be AviSynth's. Any ideas?
florinandrei is offline   Reply With Quote
Old 30th June 2008, 08:08   #2  |  Link
hanfrunz
Registered User
 
hanfrunz's Avatar
 
Join Date: Feb 2002
Location: Germany
Posts: 540
Hello florinandrei,

please try something like this:
DirectShowSource("E:\video\birthday\STREAM\00000.MTS")
SeparateFields()
LanczosResize(720, 240)
Weave()

hanfrunz
hanfrunz is offline   Reply With Quote
Old 30th June 2008, 08:10   #3  |  Link
themostestultimategenius
Kwon BoA
 
themostestultimategenius's Avatar
 
Join Date: Feb 2007
Location: Singapore
Posts: 83
You have to deinterlace before resizing.

Code:
DirectShowSource("File")
mcbob() #If you can spare the time. If not, use some other bobber.
Spline36Resize(720,480)
Weave()
Someone please correct the script if it's wrong.
__________________
Jeremy Clarkson - Getting fat is just evolution

Last edited by themostestultimategenius; 30th June 2008 at 08:13.
themostestultimategenius is offline   Reply With Quote
Old 30th June 2008, 08:41   #4  |  Link
Blue_MiSfit
Derek Prestegard IRL
 
Blue_MiSfit's Avatar
 
Join Date: Nov 2003
Location: Los Angeles
Posts: 5,986
You don't _have_ to bob before resizing - separating fields and resizing to 720x240 will work, but the bobbed version will probably look better

~MiSfit
__________________
These are all my personal statements, not those of my employer :)
Blue_MiSfit is offline   Reply With Quote
Old 30th June 2008, 11:24   #5  |  Link
Alex_ander
Registered User
 
Alex_ander's Avatar
 
Join Date: Apr 2008
Location: St. Petersburg, Russia
Posts: 334
Quote:
Originally Posted by themostestultimategenius View Post
You have to deinterlace before resizing.

Code:
DirectShowSource("File")
mcbob() #If you can spare the time. If not, use some other bobber.
Spline36Resize(720,480)
Weave()
Someone please correct the script if it's wrong.
After bobbing the video has double frame rate and is frame based progressive.
To re-interlace it, one wants to use half of fields from it, like this:

Code:
LoadPlugin("path\LeakKernelDeint.dll")
DirectShowSource("path\video.mts")# better to use DGIndex project for mpegs
LeakKernelBob(order=1)# order=1 is for TFF input video
LanczosResize(720,480)
AssumeTFF()# the assumed order will force outputting TFF
SeparateFields()
SelectEvery(4,0,3)
Weave()
The previously suggested 'separate fields + resize' method (then SelectEven) would work good for progressive target video (in case the original video is not too sharp).
Alex_ander is offline   Reply With Quote
Old 30th June 2008, 12:01   #6  |  Link
halsboss
likes to tinker
 
Join Date: Jan 2004
Location: girt by sea
Posts: 635
http://forum.doom9.org/showthread.php?t=136109
halsboss is offline   Reply With Quote
Old 1st July 2008, 01:14   #7  |  Link
florinandrei
Registered User
 
Join Date: Jul 2006
Posts: 120
Quote:
Originally Posted by themostestultimategenius View Post
You have to deinterlace before resizing.
I actually wanted to do tests first and then post a reply, but I'll post first, because it's an important issue to me:

Deinterlace before resizing sounds scary. I hope I don't have to do that. I definitely don't want to deinterlace, because, based on my previous experience with deinterlace/reinterlace filters with other applications, this always degrades the image.
My goal is to preserve the fluidity of the motion in pristine quality, and the way I understand the process now, that can't be done if I deinterlace/reinterlace.
Remember, both the source and the destination are interlaced: 1080i and 480i. So I will do my best to find a method to not deinterlace. After all, I came to AviSynth after being disappointed with some commercial software which seems to deinterlace when there's no need to.

Please correct me if I'm wrong.

P.S.: I will do tests as soon as I can.
florinandrei is offline   Reply With Quote
Old 1st July 2008, 01:41   #8  |  Link
Blue_MiSfit
Derek Prestegard IRL
 
Blue_MiSfit's Avatar
 
Join Date: Nov 2003
Location: Los Angeles
Posts: 5,986
there's a difference between "normal" (half rate) deinterlacing, and bob deinterlacing.

Bobbing preserves all temporal information, so 1080i bobbed becomes 1080p60. Then, you can scale these 60fps down to 720x480, separate it into fields, throw away half the info, and re-interlace down to 480i

You can do all this without deinterlacing, but smart bobbing first will give better results - namely less aliasing etc due to spatial alignment I think.

~MiSfit
__________________
These are all my personal statements, not those of my employer :)
Blue_MiSfit is offline   Reply With Quote
Old 1st July 2008, 03:10   #9  |  Link
florinandrei
Registered User
 
Join Date: Jul 2006
Posts: 120
I used this script:

Code:
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\LeakKernelDeint.dll")
DirectShowSource("E:\video\birthday\STREAM\00000.MTS")
LeakKernelBob(order=1)
LanczosResize(720,480)
AssumeTFF()
SeparateFields()
SelectEvery(4,0,3)
Weave()
ConvertToYV12()
I opened the result in VLC, the jaggies looked normal for a 480i. So far so good.

I generated the audio track, multiplexed, authored a very simple DVD image, burned it. It played just fine on the TV, although that test might be less relevant, since there are quite a few layers of processing on the PS3 and the HD screen which may mask issues with the DVD. But it looked good, no ghosting, no huge jaggies due to field order reversal (but I guess the PS3 would try and hide those), motion was fluid, etc.

So I guess this is it?

Any suggestions I could use to improve it? Remember, I am trying to convert 1080i TFF to 480i and keep everything interlaced, with fluid motion and crisp images.
florinandrei is offline   Reply With Quote
Old 1st July 2008, 03:17   #10  |  Link
henryho_hk
Registered User
 
Join Date: Mar 2004
Posts: 889
Have you tried the "InterlacedResize()" function in SimpleResize.dll ?

Edit(1): Unfortunately, is it said to be broken for YV12.

Edit(2): You probably need to apply some field shift correction for the separate-resize-combine method, as suggested in http://forum.doom9.org/showthread.ph...339#post594339

Last edited by henryho_hk; 1st July 2008 at 03:28.
henryho_hk is offline   Reply With Quote
Old 1st July 2008, 04:43   #11  |  Link
florinandrei
Registered User
 
Join Date: Jul 2006
Posts: 120
Quote:
Originally Posted by henryho_hk View Post
Have you tried the "InterlacedResize()" function in SimpleResize.dll ?

Edit(1): Unfortunately, is it said to be broken for YV12.
But it shouldn't matter, since ConvertToYV12() is applied after that, right?
florinandrei is offline   Reply With Quote
Old 1st July 2008, 06:05   #12  |  Link
henryho_hk
Registered User
 
Join Date: Mar 2004
Posts: 889
For best result, we need a motion-sensitive(compensated?) ConvertToYUY2 and ConvertToYV12.

BTW, nnedi+tmm+tdeint is a nice bobber too:

TFF Clips:
inp=src.nnedi(field=3)
emk=src.tmm(mode=1,order=1)
src.tdeint(mode=1,order=1,type=1,edeint=inp,emask=emk)

BFF Clips:
inp=src.nnedi(field=2)
emk=src.tmm(mode=1,order=0)
src.tdeint(mode=1,order=0,type=1,edeint=inp,emask=emk)
henryho_hk is offline   Reply With Quote
Old 1st July 2008, 07:15   #13  |  Link
Blue_MiSfit
Derek Prestegard IRL
 
Blue_MiSfit's Avatar
 
Join Date: Nov 2003
Location: Los Angeles
Posts: 5,986
Yes! Please use TDeint+TMM+NNEDI!

LeakKernelBob is prety out of date

~MiSfit
__________________
These are all my personal statements, not those of my employer :)
Blue_MiSfit is offline   Reply With Quote
Old 1st July 2008, 09:23   #14  |  Link
florinandrei
Registered User
 
Join Date: Jul 2006
Posts: 120
Quote:
Originally Posted by henryho_hk View Post
Edit(2): You probably need to apply some field shift correction for the separate-resize-combine method, as suggested in http://forum.doom9.org/showthread.ph...339#post594339
So how about this:

Code:
Global NewHeight=480
Global NewWidth=720

DirectShowSource("E:\video\birthday\STREAM\00000.MTS")

AssumeTFF()
SeparateFields()

Shift=(Height()/Float(NewHeight/2)-1.0)*0.25

Tf=SelectEven().LanczosResize(NewWidth, NewHeight/2, 0, -Shift, Width(), Height())
Bf=SelectOdd().LanczosResize(NewWidth, NewHeight/2, 0, Shift, Width(), Height())
Interleave(Tf, Bf)
Weave()

ConvertToYV12(Interlaced=True)
Visually, it looks better. Those tiny but strange ripples on top of rising/falling oblique objects are gone.
The minimum bitrate and the average bitrate on the encoder have decreased. The encoder has an easier job to do. Not sure if this is a good sign or bad. I don't care about final file size, there's plenty of room left over on the DVD.

It's still a bit blurry. But perhaps this is not objectively true, perhaps I'm unconsciously comparing it with the HD master. Also, the PS3 is doing a lot of processing to convert the 480i to 1080p for the display - I know it's doing a lot of things because the upsampled standard-def (at least the commercial progressive material) looks unnaturally good in most cases. So that might interfere. These things are best verified on true 480i displays and players.

Tomorrow, or when I have time, I'll have to start drawing diagrams and verify whether those formulas that I copy/pasted in the new script are geometrically correct. Of course, the fact that I don't know squat about AviSynth doesn't help - I'm learning it as I go, and it kind of keeps me back. Only now I'm starting to realize the vast possibilities opened by AviSynth's scripting language.
florinandrei is offline   Reply With Quote
Old 1st July 2008, 09:56   #15  |  Link
2Bdecided
Registered User
 
Join Date: Dec 2002
Location: UK
Posts: 1,673
Quote:
Originally Posted by Blue_MiSfit View Post
Yes! Please use TDeint+TMM+NNEDI!

LeakKernelBob is prety out of date
As I always say at this point in the discussion: it really doesn't matter! You're throwing half the resolution away, and you have an interlaced output. Dumb bob is more than good enough - unless you have test signals, or similar high frequency gratings in your actual content, and you process the 480i output in such a way as to preserve these features - in that case only, you might notice softening, but it's pretty mild.

Cheers,
David.
2Bdecided is offline   Reply With Quote
Old 1st July 2008, 09:59   #16  |  Link
2Bdecided
Registered User
 
Join Date: Dec 2002
Location: UK
Posts: 1,673
Quote:
Originally Posted by florinandrei View Post
It's still a bit blurry. But perhaps this is not objectively true, perhaps I'm unconsciously comparing it with the HD master. Also, the PS3 is doing a lot of processing to convert the 480i to 1080p for the display - I know it's doing a lot of things because the upsampled standard-def (at least the commercial progressive material) looks unnaturally good in most cases.
If the commercial content is 480p30 or 480p24 (typically wrapped in 60i), then it can be upconverted much more easily and crisply than 480i60. If you use 480p30 yourself (and maybe sharpen it a little, accepting the possibility of inter-line twittering on interlaced displays), it'll look just as crisp - but you'll lose the smooth motion of 480i60.

Cheers,
David.
2Bdecided is offline   Reply With Quote
Old 1st July 2008, 18:18   #17  |  Link
henryho_hk
Registered User
 
Join Date: Mar 2004
Posts: 889
Agreed. Life is much more easy if it is an ITVC material. ^_^ florinandrei, perhaps you can host a few seconds of your clip somewhere and so we can try working on it too.

Edit: Just notice the "DirectShowSource()". Have you tried dgavcdecode at http://neuron2.net/dgavcdec/dgavcdec.html?

Last edited by henryho_hk; 2nd July 2008 at 04:07.
henryho_hk is offline   Reply With Quote
Old 1st July 2008, 23:37   #18  |  Link
Blue_MiSfit
Derek Prestegard IRL
 
Blue_MiSfit's Avatar
 
Join Date: Nov 2003
Location: Los Angeles
Posts: 5,986
Quote:
Originally Posted by 2Bdecided View Post
As I always say at this point in the discussion: it really doesn't matter! You're throwing half the resolution away, and you have an interlaced output. Dumb bob is more than good enough - unless you have test signals, or similar high frequency gratings in your actual content, and you process the 480i output in such a way as to preserve these features - in that case only, you might notice softening, but it's pretty mild.

Cheers,
David.

Sure, but NNEDI with TDeint and TMM is pretty damn fast, so why not use it?

Either way - whatever the OP is happy with...
__________________
These are all my personal statements, not those of my employer :)
Blue_MiSfit is offline   Reply With Quote
Old 2nd July 2008, 03:13   #19  |  Link
florinandrei
Registered User
 
Join Date: Jul 2006
Posts: 120
Quote:
Originally Posted by Blue_MiSfit View Post
Either way - whatever the OP is happy with...
I guess it's fair to say the OP has no clue.

Between these two scripts:

Code:
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\LeakKernelDeint.dll")
DirectShowSource("E:\video\birthday\STREAM\00000.MTS")
LeakKernelBob(order=1)
LanczosResize(720,480)
AssumeTFF()
SeparateFields()
SelectEvery(4,0,3)
Weave()
ConvertToYV12()
Code:
Global NewHeight=480
Global NewWidth=720

DirectShowSource("E:\video\birthday\STREAM\00000.MTS")

AssumeTFF()
SeparateFields()

Shift=(Height()/Float(NewHeight/2)-1.0)*0.25

Tf=SelectEven().LanczosResize(NewWidth, NewHeight/2, 0, -Shift, Width(), Height())
Bf=SelectOdd().LanczosResize(NewWidth, NewHeight/2, 0, Shift, Width(), Height())
Interleave(Tf, Bf)
Weave()

ConvertToYV12(Interlaced=True)
The second one is definitely fuzzy. Anybody has a clue why? It was supposed to be the "perfect" resizer for interlaced movies.

The first one looks crisp, but I wonder if the jaggies aren't too much. I don't think there's any way to really tell, other than playing it on an old-school DVD player on a standard-def CRT TV. Anything else would just interfere with its own algorithms.

Quote:
Originally Posted by henryho_hk
Just notice the "DirectShowSource()". Have you tried dgavcdecode?
I was skeptical at first, because they say it's essentially libavcodec in a nice package, and libavcodec has problems reading the AVCHD files produced by the new-gen HD cameras. ffmpeg, ffplay and VLC all have serious issues playing these files.
But anyway, I tried it and it works. Visually, there's no difference from DirectShowSource(). It does get rid of the annoying seconds at the end when AviSynth seems to hang and HCenc is totally frozen - with dgavc the encoder just exits normally.

Quote:
Originally Posted by henryho_hk
perhaps you can host a few seconds of your clip somewhere and so we can try working on it too
Generous offer! Thank you.
I'd rather not make the initial file public (I sent it to a couple people, but putting it on a forum is a different thing), but I made 3 short clips that everyone can poke at:

http://dl.getdropbox.com/u/29966/00000.MTS
http://dl.getdropbox.com/u/29966/00001.MTS
http://dl.getdropbox.com/u/29966/00002.MTS

There's some motion, and there's some horizontal and oblique edges moving vertically.

Quote:
Originally Posted by Blue_MiSfit
there's a difference between "normal" (half rate) deinterlacing, and bob deinterlacing.

Bobbing preserves all temporal information, so 1080i bobbed becomes 1080p60. Then, you can scale these 60fps down to 720x480, separate it into fields, throw away half the info, and re-interlace down to 480i

You can do all this without deinterlacing, but smart bobbing first will give better results - namely less aliasing etc due to spatial alignment I think.
That sounds great, but how do you translate that in actual AVS scripts? Can you relate what you just said to the two scripts I posted above?
florinandrei is offline   Reply With Quote
Old 2nd July 2008, 03:47   #20  |  Link
Guest
Guest
 
Join Date: Jan 2002
Posts: 21,901
Quote:
Originally Posted by florinandrei View Post
That sounds great, but how do you translate that in actual AVS scripts? Can you relate what you just said to the two scripts I posted above?
It's exactly what you did in your first script!

I don't agree that your second is fuzzy. You are imagining it.
Guest 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 07:05.


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