Log in

View Full Version : resizing letterboxed AVI to real 16:9


Pages : [1] 2

sander815
19th August 2008, 19:13
if possible, can anyone make or point me to a good avisynth script to resize/crop/filter letterboxed 16:9 to anamorphic 16:9?
Right now i am resizing in avid liquid, but the quality isn't very good.

smok3
19th August 2008, 19:58
Crop(0,72,-0,-72) # 704x432
LanczosResize(704,576) # (mod16)

not good enough?

sander815
20th August 2008, 07:50
i will try, thanx
i don't have much experience yet

ill post the result here

Alex_ander
20th August 2008, 08:15
Are you sure your video is progressive (you'd need a different script for interlaced)?

sander815
20th August 2008, 15:32
no, its interlaced, not progressive
shot with a dv300

Adub
20th August 2008, 16:28
Ah, then best to deinterlace before doing any sort of cropping and/or resizing.

However, do you want it to remain interlaced?

sander815
20th August 2008, 17:09
the mpeg2 that i need is for tv, so i don't think i should deinterlace

Alex_ander
20th August 2008, 18:32
Of course, you don't. A script for interlaced PAL DV source (BFF):LoadPlugin("path/LeakKernelDeint.dll")#take it from here: http://leak.no-ip.org/AviSynth/LeakKernelDeint/
AviSource("path/video.avi")
LeakKernelBob(order=0)
Spline36Resize(720,576,0,72,-0,-72)
DoubleWeave().SelectEvery(4,1)#interlaced TFF

Blue_MiSfit
20th August 2008, 19:03
Yes, you do have to deinterlace - in order to get good quality anyway. Don't worry, deinterlacing doesn't have to be as destructive as you might think. You can keep full temporal resolution, and most spatial resolution.

Use a bob deinterlacer like Alex_ander suggested. I haven't used LeakKernelBob, but there's lots of choices.

You could use a really good interpolator, like NNEDI to double the height vertically before resizing to anamorphic. Anti-aliasing is a free side effect.

Something like this:


AVISource(...)
AssumeTFF() #or AssumeBFF if necessary

#Bob-deinterlace to 50p/60p
Yadif(mode=1)

#Crop as necessary
Crop(0,72,0,-72)

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

#Make it fit
Spline36resize(720,576)

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


Worth a shot :) Try it with and without NNEDI, see if it's worth it to you.

Feel free to post a sample, it might benefit from other magic :D

~MiSfit

Gavino
20th August 2008, 19:39
#Reinterlace
SeparateFields.SelectEvery(4,0,3)

Aren't you missing a Weave() here?

sander815
20th August 2008, 20:49
where do i get Yadif?
found it, but i get yadif.dll is not a avisyth 2.5 plugini am getting this error:
nnedi: field must be set to 0 or 1 when dh=true

and i have to add something like this: ConvertToYV12(), otherwise i get "Video must be YUV"

Blue_MiSfit
20th August 2008, 20:56
Aren't you missing a Weave() here?

ROFL yes I am :)

where do i get Yadif?
found it, but i get yadif.dll is not a avisyth 2.5 plugin

Load it like this:

Load_Stdcall_Plugin("...\yadif.dll")

It's an AviSynth_C plugin, so it needs special treatment!

You can use any bobber you want, but YADIF is a bit better than plain old BOB, and very fast.

-MiSfit

sander815
20th August 2008, 21:10
without NNEDI i get this;
http://www.pichost.nl/uploads/b15a878b85.jpg (http://www.pichost.nl/)

sander815
20th August 2008, 21:31
this is the stuff i have to enlarge in order to get real 16:9
http://www.pichost.nl/uploads/4b986b5676.jpg (http://www.pichost.nl/)
original video cap

Gavino
20th August 2008, 21:58
without NNEDI i get this ...
I think that's because Blue_MiSfit forgot to put Weave() at the end of his script (see above).

Blue_MiSfit
20th August 2008, 22:55
Indeed. I've edited the post :)

sander815
21st August 2008, 08:27
nnedi: field must be set to 0 or 1 when dh=true

i still get this error

this is my script now
LoadPlugin("D:/Program Files/AviSynth 2.5/plugins/nnedi.dll")
LoadCPlugin("D:/Program Files/AviSynth 2.5/plugins/yadif.dll")

AVISource("C:/finalniers.avi")

ConvertToYV12(interlaced=true)

AssumeTFF() #or AssumeBFF if necessary

#Bob-deinterlace to 50p/60p
Yadif(mode=1)

#Crop as necessary
Crop(0,72,0,-72)

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

#Make it fit
Spline36resize(720,576)

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

Alex_ander
21st August 2008, 10:06
To get rid of that warning, use
NNEDI(field=0,dh=true)

Also, most likely your DV source is BFF, then the AssumeTFF before yadif will make it output frames in wrong order, which will invert field order by the end of the script (from the expected TFF).

@Blue_MiSfit
Could you explain, what is gained here by doubling image height with NNEDI?

sander815
21st August 2008, 10:57
this is the result i get with this script:
LoadPlugin("D:/Program Files/AviSynth 2.5/plugins/nnedi.dll")
LoadCPlugin("D:/Program Files/AviSynth 2.5/plugins/yadif.dll")

AVISource("C:/finalniers.avi")

ConvertToYV12(interlaced=true)

AssumeTFF() #or AssumeBFF if necessary

#Bob-deinterlace to 50p/60p
Yadif(mode=1)

#Crop as necessary
Crop(0,72,0,-72)

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

#Make it fit
Spline36resize(720,576)

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

original video, only cropped
http://www.pichost.nl/uploads/8cdc6294ec.jpg (http://www.pichost.nl/)

processed video
http://www.pichost.nl/uploads/da3d36e061.jpg (http://www.pichost.nl/)

sander815
21st August 2008, 10:57
i have no idea if the DV is BFF btw

smok3
21st August 2008, 11:05
sander815, you can check that visualy, with a script like

avisource("film.avi")
# open this and see if the motion is progresing to determine if
# field order is bottom first, or top first
bottom = AssumeBFF().SeparateFields()
top = AssumeTFF().SeparateFields()
bottom = subtitle(bottom, "BFF - bottom field first")
top = subtitle(top, "TFF - top field first")

StackVertical(top, bottom)

another way;
doing a double bob in virtualdub using your cap i got BFF.

Gavino
21st August 2008, 11:56
Also, most likely your DV source is BFF, then the AssumeTFF before yadif will make it output frames in wrong order, which will invert field order by the end of the script (from the expected TFF).
I think the original order will still be restored at the end, even if it's in the wrong order in the middle of the script.

That's as long as yadif preserves the assumed order in its output, which I believe it does.
So, the reinterlacing is done on the same assumptions as the deinterlacing, coming out right.

sander815
21st August 2008, 12:44
ok, i am now converting it in VD, but it takes over 3 hours on a 8 min movie, thats correct?
not the fastest CPU though, AMD XP3000

smok3
21st August 2008, 12:49
Probably NNEDI is to blame.

2Bdecided
21st August 2008, 15:08
I think the original order will still be restored at the end, even if it's in the wrong order in the middle of the script.

That's as long as yadif preserves the assumed order in its output, which I believe it does.
So, the reinterlacing is done on the same assumptions as the deinterlacing, coming out right.If that happens, it's "luck" that Yadif is so simply - better bobbers (mcbob, TGMC) hate the wrong field order because the motion is messed up - stressing the motion compensation like this can make the output visibly poorer, even if you re-order it afterwards.


There was a thread about resizing 4x3 letterbox the other month. As I said there, if it's interlaced, and you haven't got time to use a really good bobber (mcbob, TempGaussMC), I would leave it as it is. You'll only lower the quality.

If you need FHA 16x9 to look "professional" more than you need genuinely good quality, then fair enough. However, 4x3 letterbox is perfect for a 4x3 TV, and will be automatically zoomed by many (most?) 16x9 TVs - much of the time that zooming will look far better than bad deinterlacing followed by resizing.

Cheers,
David.

sander815
21st August 2008, 15:42
i know about the resizing with tv's, but the the way our small tv station puts the tv signal on the cable, they need real 16:9. I tested on several tv's, we get 16:9 with the newer cams, but with the letterbox 16:9 we get black bars on all 4 sides, so its not being sized to real 16:9

sander815
21st August 2008, 15:59
heres a small piece of the original footage for testing
http://www.megaupload.com/?d=EJDN74P0

i generally need a professional look, and i do have time to recompress it

smok3
21st August 2008, 16:38
well, somebody could come up with a nice (and fast!) multipurpose resize function, if avisynth can't do that natively? Usage would be

resize(704,576,interlaced=guess,fieldOrder=guess)

mikeytown2
21st August 2008, 17:40
http://avslib.sourceforge.net/functions/r/resize.html

Alex_ander
21st August 2008, 20:08
I think the original order will still be restored at the end, even if it's in the wrong order in the middle of the script.

That's as long as yadif preserves the assumed order in its output, which I believe it does.
So, the reinterlacing is done on the same assumptions as the deinterlacing, coming out right.

After producing frames from fields original field order doesn't matter since the order in which fields will be separated, can be assumed independently from original order (it's now progressive video). It is important, which field order the bobber uses internally (not the order it translates from input to output as yadif does for some reason; some bob filters do so, some don't). That order defines whether the double-f frames will be outputted in right or wrong (by motion phase) order. In case of mistake with it, the bobber's output still can be used for re-interlacing (fortunately, with this type of script only field order will be inverted) but not for doubling frequency. In case of yadif default field order is taken from last clip (TFF in our example; if set in parameters, it would be used independently from that of the input clip).

Let's look at what can happen:

(B1T1)(B2T2)(B3T3)(B4T4) - BFF video with fields stored in frames
0 1 2 3 4 5 6 7 - its fields numbered in correct order of appearance
1 0 3 2 5 4 7 6 - field sequence used for frame creation at assumed TFF for yadif

AssumeTFF().SeparateFields()
T1 B1 T0 B0 T3 B3 T2 B2 T5 B5 T4 B4 T7 B7 T6 B6
0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3
SelectEvery(4,0,3)
T1 B0 T3 B2 T5 B4 T7 B6
- field order (physically) reversed against assumed for separation, it will be shown in AviSynth as TFF, but actually should be used as BFF
Am I missing something?

Alex_ander
21st August 2008, 20:24
ok, i am now converting it in VD, but it takes over 3 hours on a 8 min movie, thats correct?
not the fastest CPU though, AMD XP3000
Absolutely correct. With my 2400 it recently took me 18 hours for processing with NNEDI a 14 min HD clip. The script somewhere in the beginning of the thread is close to real time. Or simply disable NNEDI :).

Gavino
21st August 2008, 22:45
In case of mistake with it, the bobber's output still can be used for re-interlacing (fortunately, with this type of script only field order will be inverted) but not for doubling frequency
....
Am I missing something?
You are quite correct in what you say. My comment only applied to the original script (which was re-interlacing, not doubling frequency).

sander815
22nd August 2008, 07:40
so, this script is the best result i can get?

LoadPlugin("D:/Program Files/AviSynth 2.5/plugins/nnedi.dll")
LoadCPlugin("D:/Program Files/AviSynth 2.5/plugins/yadif.dll")

AVISource("C:/finalniers.avi")

ConvertToYV12

AssumeBFF() #or AssumeBFF if necessary

#Bob-deinterlace to 50p/60p
Yadif(mode=1)

#Crop as necessary
Crop(0,72,0,-72)

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

#Make it fit
Spline36resize(720,576)

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

mikeytown2
22nd August 2008, 07:45
By best I'm assuming your going after quality since your using NNEDI. You can replace Yadif with a higher quality bobber such as MCBob or TempGaussMC
http://avisynth.org/mediawiki/External_filters#Deinterlacing
Be ready for a super slow script though...

sander815
22nd August 2008, 08:14
thats not a big problem
can you describe how to use both scripts? as they are not dll's?

or how to use them in my script

Alex_ander
22nd August 2008, 08:45
You are quite correct in what you say. My comment only applied to the original script (which was re-interlacing, not doubling frequency).
I just mentioned frequency doubling for illustration, wanted to say that at re-interlacing that script itself doesn't correct field order issues (if wrong order is assumed for yadif):
- it changes field order (against target);
- it shows in info() final field order different from actual

@sander815
In your latest version (with BFF before yadif) you will get BFF in the end (yadif takes input field order and assigns it to its output -> later fields will be separated in different order, etc) and encode as BFF. If you finally want TFF (as expected from original script), you can add AssumeTFF() just before SeparateFields(). Or, if you prefer more compact writing, instead of

AssumeTFF().SeparateFields().SelectEvery(4,0,3).Weave

you can use:

DoubleWeave().SelectEvery(4,1)
#with BFF input this gives TFF output

sander815
22nd August 2008, 09:10
like this?

its getting a bit above my knowledge:o

LoadPlugin("C:/Program Files/AviSynth 2.5/plugins/nnedi.dll")
LoadCPlugin("C:/Program Files/AviSynth 2.5/plugins/yadif.dll")
LoadPlugin("C:/Program Files/AviSynth 2.5/plugins/EEDI2_imp.dll")

Import("C:/Program Files/AviSynth 2.5/plugins/TempGaussMC_beta1.avs")
AVISource("C:/finalniers.avi")

ConvertToYV12

AssumeBFF() #or AssumeBFF if necessary

#Bob-deinterlace to 50p/60p
Yadif(mode=1)

#TempGaussMC_beta1().SelectEvery(2,0)

#Crop as necessary
Crop(0,72,0,-72)

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

#Make it fit
Spline36resize(720,576)

DoubleWeave().SelectEvery(4,1)
#with BFF input this gives TFF output

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

mikeytown2
22nd August 2008, 09:13
LoadPlugin("C:/Program Files/AviSynth 2.5/plugins/nnedi.dll")
LoadCPlugin("C:/Program Files/AviSynth 2.5/plugins/yadif.dll")
LoadPlugin("C:/Program Files/AviSynth 2.5/plugins/EEDI2_imp.dll")
Import("C:/Program Files/AviSynth 2.5/plugins/TempGaussMC_beta1.avs")

AVISource("C:/finalniers.avi")

ConvertToYV12(interlaced=true)

AssumeBFF() #or AssumeBFF if necessary

#Bob-deinterlace to 50p/60p
TempGaussMC_beta1(EdiMode="NNEDI",tr2=3)

#Crop as necessary
Crop(0,72,0,-72)

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

#Make it fit
Spline36resize(720,576)

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

If thats not slow I don't know what is...

sander815
22nd August 2008, 09:27
4 fps on a quadcore with 4gb

2Bdecided
22nd August 2008, 10:01
If thats not slow I don't know what is...TempGaussMC_alpha3() - even slower. ;)

You could throw in a bit of denoising at the end if you wanted it to be even slower, but I don't think it's necessary. Something to stabilise the output of NNEDI could be useful, but might do more harm than good.

You don't need "loadplugin" for normal plugins which are stored in your avisynth/plugins folder. You do need to load C plugins, but that line is redundant since you're no longer using yadif.

Any scripts/functions with the extension .avsi stored in the plugins folder will be autoloaded too - no need to import them.

It is, of course, really good practice to store things elsewhere, and load them only when needed - but the lazy amongst us throw every non-conflicting script/function and plug-in that we use regularly into the plugins folder, and therefore have them all available, without explicit loading or importing, in every script we write.

Cheers,
David.

sander815
22nd August 2008, 16:35
this is my not so good result
http://xs230.xs.to/xs230/08345/vlcsnap-6014526.png.xs.jpg (http://xs.to/xs.php?h=xs230&d=08345&f=vlcsnap-6014526.png)

i assume some setting must be wrong? or is the pixelating because of the resizing

Gavino
22nd August 2008, 17:23
i assume some setting must be wrong? or is the pixelating because of the resizing
The output is still interlaced (as you wanted) so you will see combing in moving areas.

How does it look when you run the video on an interlaced display?

sander815
22nd August 2008, 17:45
but when i compare it with this sample, resized in avid liquid:
http://xs230.xs.to/xs230/08345/vlcsnap-49194392.png.xs.jpg (http://xs.to/xs.php?h=xs230&d=08345&f=vlcsnap-49194392.png)

look at the ground, thats not a moving area

smok3
22nd August 2008, 18:46
guessing: some filter in the chain is either doing bad stuff or you are feeding it with the 'wrong' field order, can you post a few sec original sample?

sander815
24th August 2008, 13:29
heres a small piece of the original footage for testing
http://www.megaupload.com/?d=EJDN74P0


see here

Alex_ander
24th August 2008, 15:10
It is BFF.
Which of the 2 scripts are you using? In the one posted by you there are 2 versions of re-reinterlacing line, so the redundant one could make things go wrong (since it is applied to interlaced), disable it by putting # in the beginning, like this:

#SeparateFields.SelectEvery(4,0,3).Weave

You can also disable NNEDI for testing, this will make script work much faster.

sander815
25th August 2008, 07:45
i used this script:
LoadPlugin("D:/Program Files/AviSynth 2.5/plugins/nnedi.dll")
LoadCPlugin("D:/Program Files/AviSynth 2.5/plugins/yadif.dll")

AVISource("C:/finalniers.avi")

ConvertToYV12

AssumeBFF() #or AssumeBFF if necessary

#Bob-deinterlace to 50p/60p
Yadif(mode=1)

#Crop as necessary
Crop(0,72,0,-72)

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

#Make it fit
Spline36resize(720,576)

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

mikeytown2
25th August 2008, 08:00
ConvertToYV12

should be

ConvertToYV12(interlaced=true)

Blue_MiSfit
25th August 2008, 08:00
Try setting NNEDI to field=1?


mikeytown beat me to a much smarter conclusion! Never convert color spaces in interlaced mode unless you handle it properly..


~MiSfit

mikeytown2
25th August 2008, 08:11
nm, the clip is already YV12, you can get rid of ConvertToYV12 completely.
a better DV codec might help
http://forum.doom9.org/showthread.php?t=94458

My results on frame 74, using the script I posted (http://forum.doom9.org/showthread.php?p=1173534#post1173534)
http://img177.imageshack.us/img177/6425/outvv3.th.jpg (http://img177.imageshack.us/my.php?image=outvv3.jpg)

Frame 148 using Tdeint(1) on the source, for a non interlaced comparison (remove the last line of the script i posted)
http://img378.imageshack.us/img378/3294/out2wf0.th.jpg (http://img378.imageshack.us/my.php?image=out2wf0.jpg)