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 14th December 2008, 10:19   #1  |  Link
Avisynth_challenged
Registered User
 
Join Date: Dec 2007
Posts: 117
Vertical upscaling of pure interlaced footage

Hi,

I have a problem that I'm not sure how to solve.

I recorded a program that is 704x480, pure interlaced, NTSC. The video is letterboxed 4:3, and with the letterbox bars removed, a 16:9 image remains.

I'm hoping to be able to somehow crop the letterbox bars, and then resize back to 480, so that I can encode in 16:9 MPEG2. My goal is to put the program onto DVD.

So my workflow would go something like this:

1. Crop: 704x480 -> 704x364
2. Resize: 704x364 -> 704x480
3. Pad: 704x480 -> 720x480

But I'm not sure how to implement Step 2, as the material is pure interlaced.

I did find this thread on downscaling 1080i HD to 480i for DVD, but it talks about how to optimally "throw away" image detail for the HD to SD conversion. My problem is how to interpolate 116 lines of information to go from 4:3 SD to 16:9 SD.

So if anyone has any ideas, comments, or thread links, please pass them along. Thanks everybody
Avisynth_challenged is offline   Reply With Quote
Old 14th December 2008, 11:15   #2  |  Link
*.mp4 guy
Registered User
 
*.mp4 guy's Avatar
 
Join Date: Feb 2004
Posts: 1,348
Quick note on the aspect ratio issue, you can only upsize it to 704*432, the rest has to be filled with black, in order to maintain proper aspect ratio on a dvd.
*.mp4 guy is offline   Reply With Quote
Old 14th December 2008, 14:13   #3  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
@Avisynth_challenged,

A. SmartBob to 60p, then use NNEDI to double the height to 728, then use a normal sharp resizer to scale back 480, finally reinterlace back to 60i.

B. For faster processing but with less quality, separate fields, NNEDI to double the height of the fields to 364, Interlaced resize the fields to 240 (you will need to adjust the correction factor to compensate for the NNEDI), weave.

And are you really sure your source is true 60i and not 3:2 of 24p.

C. If it's 24p then IVTC to recover the 24p, then use NNEDI to double the height to 728, then use a normal sharp resizer to scale back 480. Encode as 24p MPEG2 with soft 3:2 pulldown.


@*.mp4 guy,

432 is 16:9 letterbox of PAL
IanB is offline   Reply With Quote
Old 14th December 2008, 18:32   #4  |  Link
Avisynth_challenged
Registered User
 
Join Date: Dec 2007
Posts: 117
Thanks for the responses IanB and *.mp4 guy.

Quote:
Originally Posted by IanB View Post
@Avisynth_challenged,

A. SmartBob to 60p, then use NNEDI to double the height to 728, then use a normal sharp resizer to scale back 480, finally reinterlace back to 60i.
Highest quality is desired, so I'd like to explore this option. By "SmartBob" were you referring specifically to Donald Graft's SmartBob filter for VirtualDub, or did you mean I should do smart bobbing first? I know there are several quality smart bob filters for Avisynth (i.e. mvbob) so maybe some recommendations for smart bobbing filters can be suggested. Thanks.


Quote:
Originally Posted by IanB View Post
And are you really sure your source is true 60i and not 3:2 of 24p.
Yes, it is definitely true interlaced. The program was a taped concert performance.


Quote:
Originally Posted by IanB View Post
C. If it's 24p then IVTC to recover the 24p, then use NNEDI to double the height to 728, then use a normal sharp resizer to scale back 480. Encode as 24p MPEG2 with soft 3:2 pulldown.
I'm going to try this out on another project which was successfully IVTC'd to 23.976fps. I'm hoping to upscale it from 300 pixels high to 380 pixels high without introducing too much aliasing. Thanks!


Thanks again for your help.
Avisynth_challenged is offline   Reply With Quote
Old 14th December 2008, 21:51   #5  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
Quote:
Originally Posted by Avisynth_challenged
Highest quality is desired, so I'd like to explore this option. By "SmartBob" were you referring specifically to Donald Graft's SmartBob filter for VirtualDub, or did you mean I should do smart bobbing first? I know there are several quality smart bob filters for Avisynth (i.e. mvbob) so maybe some recommendations for smart bobbing filters can be suggested.
You want one of the smart bob filters. Seeing you want to use NNEDI to double the height of the result do NOT use a bobber that uses any of the *edi family. And as you are going to reinterlace again you probably only need one from the very reasonable class, .i.e. yadif, tdeint, kerneldeint, etc

An alternative approach that will give slightly less sharp results but will avoid problems with interfield twitter, would be to use a NNEDI based bobber and then used an interlaced resizing related technique to directly produce new fields and finally Weave.

The decision depends a lot on the original source material and your own tastes.
IanB is offline   Reply With Quote
Old 14th December 2008, 21:55   #6  |  Link
Avisynth_challenged
Registered User
 
Join Date: Dec 2007
Posts: 117
Update

Did lots of reading on the forum about resizing interlaced sources, and came upon *this*, which lead me to *this*.

Based on the above, I came up with the following script:


### BEGIN SCRIPT ###
LoadPlugin("C:\program files\avisynth 2.5\plugins\DGDecode.dll")
LoadPlugin("C:\program files\avisynth 2.5\plugins\decomb.dll")
Import("C:\program files\avisynth 2.5\plugins\mcbob_v0.3u.avs")
############


# This line loads the MPEG source
MPEG2Source("Path\source.d2v")
############


# Should already be yv12, but just to make sure...
converttoyv12(interlaced=true).AssumeTFF() #or AssumeBFF if necessary

# crop off borders:
crop(0,58,-0,-58)

#Bob-deinterlace to 50p/60p
mcbob()

#Edge-directed interpolation to double height
NNEDI(field=0, dh=true)

#Make it fit
Spline36resize(704,470).addborders(8,5,8,5)

#Reinterlace
assumetff().SeparateFields().SelectEvery(4,0,3).Weave().converttoyuy2()

### END SCRIPT ###


And here are some before and after screengrabs:


Source:

Output:


Comments, criticism, etc. welcome. Thanks, all
Avisynth_challenged is offline   Reply With Quote
Old 14th December 2008, 22:14   #7  |  Link
Avisynth_challenged
Registered User
 
Join Date: Dec 2007
Posts: 117
Quote:
Originally Posted by IanB View Post
You want one of the smart bob filters. Seeing you want to use NNEDI to double the height of the result do NOT use a bobber that uses any of the *edi family. And as you are going to reinterlace again you probably only need one from the very reasonable class, .i.e. yadif, tdeint, kerneldeint, etc

An alternative approach that will give slightly less sharp results but will avoid problems with interfield twitter, would be to use a NNEDI based bobber and then used an interlaced resizing related technique to directly produce new fields and finally Weave.

The decision depends a lot on the original source material and your own tastes.
I didn't see this before I wrote my previous post. I will look into the other smart bobbers you suggested, yadif, tdeint, kerneldeint. Would you care to comment on my screengrabs showing the source and the result with mcbob? I'm such a novice, as I'm sure you've surmised

I truly appreciate this forum and the assistance that its experienced users offers to us newbies.
Avisynth_challenged is offline   Reply With Quote
Old 14th December 2008, 22:15   #8  |  Link
2Bdecided
Registered User
 
Join Date: Dec 2002
Location: UK
Posts: 1,673
This is a waste of time:
Code:
Spline36resize(704,470).addborders(8,5,8,5)
Just do this:
Code:
Spline36resize(704,480)
That's fine for DVD.

If you're really anal about aspect ratios, you could use crop(0,60,0,-60) in place of your existing crop - but I reckon the aspect ratio is already wrong by that much, and wouldn't worry about it.

Cheers,
David.
2Bdecided is offline   Reply With Quote
Old 14th December 2008, 22:28   #9  |  Link
Avisynth_challenged
Registered User
 
Join Date: Dec 2007
Posts: 117
Quote:
Originally Posted by 2Bdecided View Post
This is a waste of time:
Code:
Spline36resize(704,470).addborders(8,5,8,5)
Just do this:
Code:
Spline36resize(704,480)
That's fine for DVD.

If you're really anal about aspect ratios, you could use crop(0,60,0,-60) in place of your existing crop - but I reckon the aspect ratio is already wrong by that much, and wouldn't worry about it.

Cheers,
David.

Thanks for the tip. But isn't there a side-benefit for padding to 720 pixels wide in that you can expose a few pixels which would otherwise be lost to overscan? I dunno, it doesn't make much difference either way, but if you can have it, why not?
Avisynth_challenged is offline   Reply With Quote
Old 14th December 2008, 22:39   #10  |  Link
thetoof
Sleepy overworked fellow
 
Join Date: Feb 2008
Location: Maple syrup's homeland
Posts: 933
Instead of bobbing and reinterlacing, wouldn't it be simpler to:
-crop the black bars
-separatefields()
-upscale to half vertical resolution
-weave()

Also, when upscaling with nnedi, don't forget to correct the registration error caused by edi upscaling. A bit of info here and at around post #71 + around here.
Code:
dest_x=
dest_y= # half final vertical resolution
nnedi(1,true).spline36resize(dest_x,dest_y,0,-0.5,2*a.width+.001,2*a.height+.001)
__________________
AnimeIVTC() - v2.00
-http://boinc.berkeley.edu/-
Let all geeks use their incredibly powerful comps for the greater good (no, no, it won't slow your filtering/encoding :p)

Last edited by thetoof; 14th December 2008 at 22:56.
thetoof is offline   Reply With Quote
Old 14th December 2008, 22:57   #11  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
Okay Guitar strings they will twitter every time the strings are near horizontal.

Script should go something like this :-
Code:
...
MPEG2Source("Path\source.d2v")

crop(0,58,-0,-58) # crop off borders:

#Bob-deinterlace to 50p/60p
???bob() # pick one

ConvertToYUY2() # Do this while progressive!

AssumeTFF()
Factor=0.5 # Need to derive the correct value for this!
E=SelectEven().Spline36resize(712, 240, 0,  Factor, 0, 0).AddBorders(4,0,4,0)
O=SelectOdd( ).Spline36resize(712, 240, 0, -Factor, 0, 0).AddBorders(4,0,4,0)
Interleave(E, O)
Weave()
I have adjusted your pixel aspect based on 4:3 letterbox of 16:9 material normally having 60 pixel borders and you have 58 pixel borders.

I don't have time to derive Factor, maybe one of the other members can do it. It will be the output uncrop scaled to the input size but with no input crop from my Interlaced Resize code.
IanB is offline   Reply With Quote
Old 15th December 2008, 00:40   #12  |  Link
Avisynth_challenged
Registered User
 
Join Date: Dec 2007
Posts: 117
Quote:
Originally Posted by IanB View Post
Okay Guitar strings they will twitter every time the strings are near horizontal.

Script should go something like this :-
Code:
...
MPEG2Source("Path\source.d2v")

crop(0,58,-0,-58) # crop off borders:

#Bob-deinterlace to 50p/60p
???bob() # pick one

ConvertToYUY2() # Do this while progressive!

AssumeTFF()
Factor=0.5 # Need to derive the correct value for this!
E=SelectEven().Spline36resize(712, 240, 0,  Factor, 0, 0).AddBorders(4,0,4,0)
O=SelectOdd( ).Spline36resize(712, 240, 0, -Factor, 0, 0).AddBorders(4,0,4,0)
Interleave(E, O)
Weave()
I have adjusted your pixel aspect based on 4:3 letterbox of 16:9 material normally having 60 pixel borders and you have 58 pixel borders.

I don't have time to derive Factor, maybe one of the other members can do it. It will be the output uncrop scaled to the input size but with no input crop from my Interlaced Resize code.

Thanks IanB. To calculate "FACTOR", should I use the formula you gave for "SHIFT" in this post? Thanks!

Last edited by Avisynth_challenged; 15th December 2008 at 00:43. Reason: Correcting dumb newbie reasoning :)
Avisynth_challenged is offline   Reply With Quote
Old 15th December 2008, 00:41   #13  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by IanB View Post
I don't have time to derive Factor, maybe one of the other members can do it. It will be the output uncrop scaled to the input size but with no input crop from my Interlaced Resize code.
I reckon it is -0.5*(364.0/480.0).
Sanity check: want negative crop for top field, and it reduces to -0.5 if output size = input size (when it becomes Bob in reverse).

Are you sure the last 0 in the resizes is right? I would expect this to be omitted (ie defaulted to Height()).
Gavino is offline   Reply With Quote
Old 15th December 2008, 02:05   #14  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
I think Gavino has it right, and yes the last 2 zeros in the resize should be gone.

And no, FACTOR and SHIFT, are not the same, here we start with a fully progressive stream so there is no input correction required, there it is a field separated stream so there needs to be an alternating input correction. On output both need the alternating "uncrop". The geometry involved is somewhat tricky.

As I said the decision depends a lot on the original source material and your own tastes. If the guitar is seldom horizontal then twitter may not be an issue and the original A method may be preferred. Experiment some! Remember to view the results an an proper interlaced display device, PC screens are crap for working with interlaced streams.
IanB is offline   Reply With Quote
Old 15th December 2008, 04:33   #15  |  Link
ajp_anton
Registered User
 
ajp_anton's Avatar
 
Join Date: Aug 2006
Location: Stockholm/Helsinki
Posts: 805
Did I miss something? Why not just encode the source as it is (720x480 set to 4:3)?
ajp_anton is offline   Reply With Quote
Old 15th December 2008, 07:00   #16  |  Link
Sagekilla
x264aholic
 
Join Date: Jul 2007
Location: New York
Posts: 1,752
@ajp_anton: The source video isn't supposed to be 4:3. It has a frame size of 704x480, but with 116 pixels of bordering.
__________________
You can't call your encoding speed slow until you start measuring in seconds per frame.
Sagekilla is offline   Reply With Quote
Old 15th December 2008, 07:08   #17  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
@ajp_anton,

Yes, the source is 4:3 hard letterboxed and Avisynth_challenged wants to repair it to be proper 16:9 with the best available vertical rescaling. And I can sympathise with him, typically DVD players into 16:9 televisions play this garbage letterboxed+pillarboxed, my player offers a 1.5x zoom which helps slightly (really want a 1.333x zoom).
IanB is offline   Reply With Quote
Old 15th December 2008, 12:26   #18  |  Link
2Bdecided
Registered User
 
Join Date: Dec 2002
Location: UK
Posts: 1,673
Quote:
Originally Posted by Avisynth_challenged View Post
Thanks for the tip. But isn't there a side-benefit for padding to 720 pixels wide in that you can expose a few pixels which would otherwise be lost to overscan? I dunno, it doesn't make much difference either way, but if you can have it, why not?
In a stand-alone player, it makes precisely no difference - you're just wasting time encoding 8 black pixels either side that will be cropped anyway. Watching on a PC you're adding a black border - equally pointless.


I'm confused why you're now looking at separate field resizing. It would be interesting to see a comparison, but my assumption would be that a good bob (e.g. mcbob, or TempGaussMC_alpha3) would give dramatically better results.

Cheers,
David.

P.S. - the show might be available in HD, which would make a much better source for an anamorphic 16x9 DVD.
2Bdecided is offline   Reply With Quote
Old 15th December 2008, 13:32   #19  |  Link
thetoof
Sleepy overworked fellow
 
Join Date: Feb 2008
Location: Maple syrup's homeland
Posts: 933
Quote:
Originally Posted by 2Bdecided View Post
TempGaussMC_alpha3
beta1 has been available for quite a while now...

You could also use TempGaussMC_beta1mod() with an additionnal parameter:
mt=true #use multithreaded branch by josey_wells (1.9.7.7)
mt=false #use MVTools2 (currently 2.3.0) (default)
chroma correction has been disabled for MVTools2 since it has been corrected in MVTools 1.10.2.1
__________________
AnimeIVTC() - v2.00
-http://boinc.berkeley.edu/-
Let all geeks use their incredibly powerful comps for the greater good (no, no, it won't slow your filtering/encoding :p)
thetoof is offline   Reply With Quote
Old 15th December 2008, 15:12   #20  |  Link
2Bdecided
Registered User
 
Join Date: Dec 2002
Location: UK
Posts: 1,673
Quote:
Originally Posted by thetoof View Post
beta1 has been available for quite a while now...
You say that as if I didn't know

http://forum.doom9.org/showthread.ph...79#post1159579

If I had a CPU capable of MT, I'd look again at beta1 to get "nearly as good" quality in a fraction of the time. TBH I (and, I think, WorBry, with very different content) felt that the default settings for beta1 were so obviously worse than alpha3 that there'd be a beta2 along soon to fix it.

Cheers,
David.

Last edited by 2Bdecided; 15th December 2008 at 15:16.
2Bdecided 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 02:25.


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