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 12th November 2010, 03:56   #1  |  Link
dansrfe
Registered User
 
Join Date: Jan 2009
Posts: 1,210
AutoResize v.1.7 (ideal for use with ffdshow) [Last Updated: 2/4/2011]

This function will resize to any aspect ratio (AR), and add black borders, if needed, to reach any destination resolution, primarily for full-screening video to maximum screen resolution. This function was initially designed to make possible high-quality subtitle rendering at maximum possible resolution with optimal placement area, to be used with ffdshow video decoder. AutoResize can be used with any renderer to deliver automated high-quality spline36 resizing on-the-fly.

Features:

- Compatible with any version of AviSynth 2.5.8+
- Borders appended in a mod2 fashion with right-hand justification for boxed clips (+ 1 pixel) and top justification for letterbox clips with (+ 1 pixel).
- High quality Spline36Resize function used for any resizing
- If necessary, colorimetery conversions are taken care of automatically when changing from SD -> HD or any other upscale/downscale situation.
- OSD displays Resolution changes, Borders information, AR changes, and FPS information in upper left corner.

Prerequisites:

AviSynth 2.5.8+ (Preferably MT version) http://www.mediafire.com/file/kjdzqy...ynthMT_258.exe
ColorMatrix (For SD->HD conversions) http://avisynth.org/warpenterprises/...x_20070828.zip

Syntax:

AutoResize(clip, bool "Info", bool "Borders", float "AR", string "DAR", int "SW", int "SH")

Info: Enables/disables OSD. (default: "false")

Borders: Allows you to resize with or without borders. (default: "true")

AR: Changes AR with respect to "screen" variable values. (default: input AR)

DAR: Sets display aspect ratio of input. Options: PAL/NTSC DVD Only: ["letterbox" for 16/9 (1.777) ,"box" for 4/3 (1.333)]. (default: null)

SW: Screen width in pixels. (default: 1920)

SH: Screen height in pixels. (default: 1080)

Some Important Notes:

AutoResize is meant to be run at all times. It is designed to use it's logic in every possible resizing situation for the best output. AutoResize will not resize unless it is absolutely needed; the same goes for appending black borders. If you pass a video through AutoResize that matches the sw and sh variables or default conditions then it will pass the video through untouched and simply be equivalent to "last" in AviSynth notation. Resizing takes place if needed (see below) then black borders are appended if needed (see below). AR changes are shown in the OSD denoted by "Input AR -> Output AR".

How to know if resizing is taking place:

In order to absolutely know that the input is or is not being passed through the resizer you should check the OSD. If you see "Resolution: Input x Resolution -> Output x Resolution" the input is being passed to the resizer. If you just see "Resolution: "Input x Resolution" then the input is not being passed through a resizer whatsoever.

How to know if borders are being added:

In order to absolutely know that black borders are or are not being appended is by checking the OSD. If you see "Borders: off" then there are no black borders being appended to the output. If you just see "Borders: on, (x,x,x,x)" then black borders are being appended to the output.

Here are some examples:

SW = 1920, SH = 1080; Input = 1280 x 720 [OSD: Resolution: 1280 x 720 -> 1920 x 1080 ; Borders: off]
SW = 1280, SH = 720; Input = 1280 x 720 [OSD: Resolution: 1280 x 720 ; Borders: off]


What works best for me performance wise in using this function and other functions in AviSynth on-the-fly:

This is my script that I have in ffdshow (hats off to Didée for finding the magic performance juice ):

Code:
setmtmode(5)
ffdshow_source()
changefps(last,last,true)
setmtmode(2)
[...other functions if needed...]
AutoResize()
I have 3:2 Pulldown set to "Apply Pulldown" and have unchecked the "Buffer back/ahead:" along with "Add ffdshow video source". The changefps does nothing but cache a few frames but it has a drastic performance boost in the overall script.

Download: AutoResize v1.7.avsi

Changelog:

2/4/11 - Major code rewrites. PAR changed to DAR (only "letterbox" and "box" modes exist now). Added "Borders" variable. OSD massively improved and cleaned up. Variable names shortened to abbreviations. Housekeeping and labeling of different parts of code.
1/2/11 - Added new PAR parameters and error message on invalid par parameter input or when par is fed a non-square pixel NTSC or PAL source.
12/21/10 - Fixed some bugs. Could result in faster speeds for some.
11/25/10 - Removed ThreadRequest.
11/16/10 - Removed mode setting & changed function name to "AutoResize".
11/16/10 - Major changes. Added input PAR setting for flagged content. Optimized code.
11/15/10 - Minor bugfixes, one variable input changed and added documentation in script.
11/12/10 - Code updated from creaothceann's adjustments. Thanks!

Last edited by dansrfe; 10th February 2012 at 22:32. Reason: Updated
dansrfe is offline   Reply With Quote
Old 12th November 2010, 08:55   #2  |  Link
creaothceann
Registered User
 
Join Date: Jul 2010
Location: Germany
Posts: 357
DVDs can also have a width of 704.

Code:
function Resize(clip c, int "Mode", bool "Info", float "AR", int "ScreenWidth", int "ScreenHeight")  {
        Info         = Default(Info        , False)
        Mode         = Default(Mode        ,     0)
        ScreenWidth  = Default(ScreenWidth ,  1920)
        ScreenHeight = Default(ScreenHeight,  1080)

        SetMTMode(2)
        last = c

        AR_Screen = Float  (ScreenWidth) / ScreenHeight
        AR_norm   = Float  (      Width) /       Height
        AR        = Default(AR, AR_norm)

        Resize_BoxWidth        = Round(Float(ScreenHeight) * AR)
        Resize_LetterboxHeight = Round(Float(ScreenWidth ) / AR)

        Mod2Box       = Resize_BoxWidth        + (Resize_BoxWidth        % 2)
        Mod2Letterbox = Resize_LetterboxHeight - (Resize_LetterboxHeight % 2)

        Border_Letterbox = (ScreenHeight - Mod2Letterbox) / 2
        Border_Box       = (ScreenWidth  - Mod2Box      ) / 2

        Resize_Letter = Spline64Resize(ScreenWidth, Mod2Letterbox).ThreadRequest
        Resize_Box    = Spline64Resize(Mod2Box    , ScreenHeight ).ThreadRequest

        Upscale_Letterbox = (Border_Letterbox == 0)  ?  Resize_Letter.ThreadRequest  :  Resize_Letter.ThreadRequest.AddBorders(         0, Border_Letterbox,          0, Border_Letterbox).ThreadRequest 
              Upscale_Box = (Border_Box       == 0)  ?  Resize_Box                   :  Resize_Box   .ThreadRequest.AddBorders(Border_Box,                0, Border_Box,                0).ThreadRequest

        Letterbox_or_Box = (AR >= AR_Screen)  ?  Upscale_Letterbox  :  Upscale_Box
        DVD_or_SD        = ((Width == 720 || Width == 704) && (Height == 480 || Height == 576))  ?  Spline64Resize(1920, 1080).ThreadRequest  :  (Width > 1280)  ?  Letterbox_or_Box  :  Letterbox_or_Box.ColorMatrix("Rec.601->Rec.709").ThreadRequest

        HD_BorderWidth  = (ScreenWidth  - Width ) / 2
        HD_BorderHeight = (ScreenHeight - Height) / 2

        ResizeHeight = (Height == ScreenHeight) && (AR_norm == AR)  ?  AddBorders(0, HD_BorderWidth , 0, HD_BorderWidth ).ThreadRequest  :  DVD_or_SD
        ResizeWidth  = (Width  == ScreenWidth ) && (AR_norm == AR)  ?  AddBorders(0, HD_BorderHeight, 0, HD_BorderHeight).ThreadRequest  :  ResizeHeight

        HD        = ((Width == ScreenWidth) && (Height == ScreenHeight)) && (AR_norm == AR)  ?  last  :  ResizeWidth
        SelectRes = (AR >= AR_Screen)  ?  Resize_Letter  :  ((Width == 720 && (Height == 480 || Height == 576))  ?  Spline64Resize(1920, 1080)  :  Resize_Box)
        ChangeAR  = (AR_norm == AR)  ?  String(AR_norm)  :  (String(AR_norm) + " -> " + String(AR))
        ChangeRes = (SelectRes.Width != Width) || (SelectRes.Height != Height)  ?  String(Width) + " x " + String(Height) + " -> " + String(SelectRes.Width) + " x " + String(SelectRes.Height)  :  String(Width) + " x " + String(Height)

        SourceInfo = HD.Subtitle("Source res: "      , x= 19, y=25, Size=22, Font="Arial", Text_Color=$DC143C)
        \.              Subtitle(String(ChangeRes)   , x=140, y=25, Size=22, Font="Arial"                    )
        \.              Subtitle("A/R: "             , x= 92, y=49, Size=22, Font="Arial", Text_Color=$DC143C)
        \.              Subtitle(String(ChangeAR)    , x=141, y=49, Size=22, Font="Arial"                    )
        \.              Subtitle("FPS: "             , x= 88, y=72, Size=22, Font="Arial", Text_Color=$DC143C)
        \.              Subtitle(String(framerate(c)), x=141, y=72, Size=22, Font="Arial"                    )

        (Mode == 1)  ?  (Info  ?  SourceInfo.ThreadRequest  :  HD)  :  last
}

PS: You shouldn't assign anything to "last", it's a predefined variable that contains the result of the last operation that wasn't assigned to another variable:

Code:
AVISource(...)
AudioDub(last, WAVSource(...))
tmp = AddBorders(1, 0, 1, 0, $123456)
StackHorizontal(last, tmp)

Last edited by creaothceann; 12th November 2010 at 09:00.
creaothceann is offline   Reply With Quote
Old 12th November 2010, 10:50   #3  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by creaothceann View Post
PS: You shouldn't assign anything to "last", it's a predefined variable that contains the result of the last operation that wasn't assigned to another variable
Agreed that you shouldn't use a variable called 'last' for some unrelated purpose, but I don't see anything wrong with writing
last = c
where the purpose is to set the 'real' last, needed in the later use of 'width' (ie last.width()) and 'height'.
You could just write
c
on its own to get the same result, but that looks a bit odd.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 12th November 2010, 12:34   #4  |  Link
creaothceann
Registered User
 
Join Date: Jul 2010
Location: Germany
Posts: 357
Quote:
Originally Posted by Gavino View Post
You could just write
c
on its own to get the same result
Yeah, I do that in my functions.
creaothceann is offline   Reply With Quote
Old 12th November 2010, 13:05   #5  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
It's debatable which is 'better', 'c' on its own or 'last=c' - I do it either way, more or less at random.

Another possibility is
/* last = */ c
which shows the intent without explicitly assigning to 'last'.
It's really a matter of taste, and I wouldn't lose sleep over the issue.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 12th November 2010, 13:50   #6  |  Link
noee
Registered User
 
Join Date: Jan 2007
Posts: 530
What benefit to pic quality does madVR bring to the table in this case (besides 3DLut)? Why not use EVR or EVR-CP as the renderer and output RGB from ffdShow (and use it's HQRGB and dithering)?
noee is offline   Reply With Quote
Old 12th November 2010, 14:56   #7  |  Link
dansrfe
Registered User
 
Join Date: Jan 2009
Posts: 1,210
madVR is basically the smoothest renderer for me and *does* actually look better in terms of gradient reproduction and minimal banding. But you can do that with gradfun in ffdshow as well. It boils down to personal preference I guess if you don't use the 3DLUT.

Also, any other changes I could make to it? I wish there was some way I could combine some if statements to get it to run a bit faster and just want to point out that this script will not work with AviSynth unless the AddBordersMod function is applied to is from the Development section. I don't use 2.6 at this time therefore I didn't use AddBodersMod.

Last edited by dansrfe; 15th November 2010 at 02:07.
dansrfe is offline   Reply With Quote
Old 14th November 2010, 17:03   #8  |  Link
henryho_hk
Registered User
 
Join Date: Mar 2004
Posts: 889
I have written a similar function and it accepts both source and destination pixel aspect ratio:

Code:
function parresize(clip c, int dst_w, int dst_h, string "dst_par", string "src_par", bool "ss")
{
    unit_w  = c.isRGB() ? 1 : 2
    unit_h  = c.isRGB() || c.isYUY2() ? 1 : 2

    assert(dst_w % unit_w == 0, "Destination width must be divisible by "  + string(unit_w))
    assert(dst_h % unit_h == 0, "Destination height must be divisible by " + string(unit_h))

    ss = default(ss, false)

    src_par = default(src_par, "vga11")
    dst_par = default(dst_par, "vga11")
    cvt_par = \
        ( \
        dst_par == "pal43"    ? 12.0/11.0 : \
        dst_par == "ntsc43"   ? 10.0/11.0 : \
        dst_par == "pal169"   ? 16.0/11.0 : \
        dst_par == "ntsc169"  ? 40.0/33.0 : \
                                1.0 \
        ) / \
        ( \
        src_par == "pal43"    ? 12.0/11.0 : \
        src_par == "ntsc43"   ? 10.0/11.0 : \
        src_par == "pal169"   ? 16.0/11.0 : \
        src_par == "ntsc169"  ? 40.0/33.0 : \
                                1.0 \
        )

    src_dar = float(c.width) / cvt_par / c.height
    dst_dar = float(dst_w) / dst_h

    temp_w = floor((src_dar >= dst_dar ? dst_w : round(1.0 * dst_h * src_dar))/unit_w)*unit_w
    temp_h = floor((src_dar >= dst_dar ? round(1.0 * dst_w / src_dar) : dst_h)/unit_h)*unit_h

    r_factor = ss ? int(pow(2,ceil(log(max(float(temp_w)/c.width,float(temp_h)/c.height))/log(2.0)))) : 1

    s1 = r_factor == 1 \
         ? c.blackmanresize(temp_w,temp_h) \
         : c.nnedi3_rpow2(rfactor=r_factor,cshift="spline64resize",fwidth=temp_w,fheight=temp_h)

    pad_l = floor(0.5*(dst_w-temp_w)/unit_w)*unit_w
    pad_r = dst_w - pad_l - temp_w
    pad_t = floor(0.5*(dst_h-temp_h)/unit_h)*unit_h
    pad_b = dst_h - pad_t - temp_h

    return s1.addborders(pad_l, pad_t, pad_r, pad_b)
}
Thanks Gavino for the suggestion.

Last edited by henryho_hk; 15th November 2010 at 01:37. Reason: Modified as advised by Gavino
henryho_hk is offline   Reply With Quote
Old 14th November 2010, 17:39   #9  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by henryho_hk View Post
Code:
    assert(dst_w == floor(dst_w/unit_w)*unit_w, ...)
    assert(dst_h == floor(dst_h/unit_h)*unit_h, ...)
'floor' is redundant here - since dst_w and unit_w are both integers, so is dst_w/unit_w.

So you could simplify it to
Code:
    assert(dst_w == (dst_w/unit_w)*unit_w, ...)
or even more simply
Code:
    assert(dst_w % unit_w == 0, ...)
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 25th November 2010, 00:24   #10  |  Link
BatKnight
Registered User
 
BatKnight's Avatar
 
Join Date: Oct 2008
Location: Portugal
Posts: 161
Can you explain me how to use this script in ffdshow? Because I've loaded the script to ffdshow, in the Avisynth window, enabled it, but it' doesn't resize the video.

Bat
__________________
Win 11 x64, Geforce RTX 4060 Ti 16GB, TV Sony KD-55X8509C HDMI, Denon AVR-X2700H, Core i7-9700K, 32GB DDR4, Creative Labs Gigaworks S750 7.1 speakers
MPC Home-Cinema
madVR
LAV Filters
BatKnight is offline   Reply With Quote
Old 25th November 2010, 08:46   #11  |  Link
dansrfe
Registered User
 
Join Date: Jan 2009
Posts: 1,210
load the script in ffdshow, write "AutoResize()" without quotes and you're good to go. if you are trying to play a 16:9 dvd then just enter par="wide" or if you're trying to view a 4:3 dvd then add par="[any string]" where basically you can add any string to signal 4:3 flagged content. If par is left blank then it won't override the AR setting. Also read the what the parameters mean inside of the script.

Note: If you're resolution is NOT 1920 x 1080 then you will need to specify the ScreenWidth & ScreenHeight parameters.

Last edited by dansrfe; 26th November 2010 at 04:40.
dansrfe is offline   Reply With Quote
Old 26th November 2010, 04:32   #12  |  Link
dansrfe
Registered User
 
Join Date: Jan 2009
Posts: 1,210
If someone could download and optimize the script via changing calling methods or whatever you feel will have it running as fast as possible then please do so. Unfortunately, I'm inexperienced in the optimization area and still learning different techniques.
dansrfe is offline   Reply With Quote
Old 26th November 2010, 09:17   #13  |  Link
gnol009
Registered User
 
Join Date: Feb 2010
Posts: 11
This is my scrip error. how can i fix it?

gnol009 is offline   Reply With Quote
Old 26th November 2010, 18:26   #14  |  Link
dansrfe
Registered User
 
Join Date: Jan 2009
Posts: 1,210
^ install this: http://www.mediafire.com/file/kjdzqy...ynthMT_258.exe. You must have an MT version of AviSynth 2.5.8 or higher in order for this to work

Last edited by dansrfe; 26th November 2010 at 19:35.
dansrfe is offline   Reply With Quote
Old 6th December 2010, 21:30   #15  |  Link
Frank K Abbott
Registered User
 
Join Date: Mar 2010
Posts: 69
This functions works well for me thanks!
Frank K Abbott is offline   Reply With Quote
Old 22nd December 2010, 07:35   #16  |  Link
Mark Regalo
Registered User
 
Join Date: Oct 2010
Posts: 24
THis is a good function. I use with madvr. Will there be any more features coming out??
Mark Regalo is offline   Reply With Quote
Old 22nd December 2010, 19:09   #17  |  Link
dansrfe
Registered User
 
Join Date: Jan 2009
Posts: 1,210
For right now I'm fairly sure I have perfected the functions that currently exist. As for more functions, I'll add them if it is something that would help others as well. Suggestions are welcome. Please test it and see if it works for you.

PS: All colorimetery conversions etc. are ALL taken care of internally in the script. You will always get the right output from madVR with respect to what is coming out of the function.

Last edited by dansrfe; 22nd December 2010 at 19:12.
dansrfe is offline   Reply With Quote
Old 22nd December 2010, 22:11   #18  |  Link
Usedocne
lurkster
 
Join Date: Jul 2009
Location: D9|D10
Posts: 123
Nice function dansrfe, thanks for sharing it.
Usedocne is offline   Reply With Quote
Old 31st December 2010, 11:32   #19  |  Link
Sharc
Registered User
 
Join Date: May 2006
Posts: 3,997
Nice function, dansfre. Thanks for sharing it.

I assume the script does not automatically de-interlace interlaced video before resizing. Means interlaced video should be de-interlaced before applying this script, correct?

Last edited by Sharc; 31st December 2010 at 12:18.
Sharc is offline   Reply With Quote
Old 31st December 2010, 12:37   #20  |  Link
THX-UltraII
Registered User
 
Join Date: Aug 2008
Location: the Netherlands
Posts: 851
I think I m missing (because my English is not good) but what is the exact pupose of this tool? Why would someone want to change the aspect ration of a movie if you get a incorrect result ('long heads') of the picture?
THX-UltraII 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 09:30.


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