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 27th November 2011, 22:35   #1  |  Link
vampiredom
Registered User
 
Join Date: Aug 2008
Posts: 233
PARResize() | PAR-aware resizing function

PARResize() is useful for standards conversions and arbitrary anamorphic pixel resizing.

It can automatically detect the "correct" input and output PAR using the assumptions here. Or you can specify SourcePAR or TargetPAR as a decimal or fraction string.

It operates in two modes: Boxing=true (default) will add borders to achieve the target dimensions. When Boxing=false, it will crop the source to match the PAR-compensated target dimensions.

100% AviSynth, no dependent DLLs required.
Download it here

Code:
#####################################################################################################
# PARResize()
# 2011/11/29
#####################################################################################################
#
# Parameters:
#
# TargetWidth, TargetHeight [integer]
#       These determine the output width and height
# SourcePAR, TargetPAR [string or float]
#       These determine the PAR of the input and output, respectively
#       Legal vales are either a floating decimal PAR (ex: SourcePAR=0.909091) or a string
#       The allowed string values are:
#               "" (default)
#                       A blank string will set the corresponding PAR automatically, assuming 4:3 DAR
#               "ws"
#                       A value of "ws" (widescreen) will set the corresponding PAR automatically, assuming 16:9 DAR
#               Fractional String
#                       You can also use fractions as strings (Example: SourcePAR="10/11", TargetPAR="40/33")
# Boxing [boolean]
#       When Boxing=true (default), borders will be added to achieve the TargetWidth or Height as needed
#       When false, PARResize will crop the source as needed to achieve the target DAR
# Color [int]
#       The Color parameter determines the border color when Boxing=true
# CropBias [float]
#       When CropBias=0.5 (default), any cropping of the source will be symmetrical
#       Setting it lower (minimum is 0.0) will show more of the source's left or top, cropping more from the right or bottom
#       Setting it higher (minimum is 1.0) will show more of the source's right or bottom, cropping more from the left or top
#       CropBias has no effect if Boxing=true
#
#####################################################################################################
Examples:
Code:
# Assume 4:3 input and resize to 4:3 NTSC DVD
PARResize(720, 480, SourcePAR="", TargetPAR="")

# Assume widescreen input and output
PARResize(720, 480, SourcePAR="ws", TargetPAR="ws")

# Use arbitrary PARs
PARResize(176, 576, SourcePAR=1.0, TargetPAR="472/81")

# Assume an HD source, convert to widescreen DVD specs
# Here, Boxing=false will crop a few lines from the source before scaling to fill the width
PARResize(720, 576, "ws", "ws", Boxing=false)

# Assume an HD source, convert to 4:3 DVD specs
# Here, Boxing=false will crop the sides to fit the screen
PARResize(720, 576, "ws" , "", false)

#  Set the letterboxing color to white
PARResize(704, 480, color=$FFFFFF)
I have tested it with standard input/output. More testing is needed for odd-sized sources and output and arbitrary PARs. There is some sanity-checking... you can also set debug=true to see what is going on behind the scenes with the numbers.

Last edited by vampiredom; 29th November 2011 at 22:37. Reason: revision 2011/11/29 - fixed a bug
vampiredom is offline   Reply With Quote
Old 29th November 2011, 01:14   #2  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
I haven't looked in detail at the algorithmic part, so can't comment on that, but I spotted a couple of things on a quick look at the code.

In the Assert statement error messages, CHR(13) does not produce a newline, just a square blob. Use CHR(10) instead, or just use a multi-line string literal, eg
"first line
second line" # note no '\' required

Also, Avisynth string comparison is case-insensitive, so there's no need to use LCase when comparing.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 29th November 2011, 02:01   #3  |  Link
vampiredom
Registered User
 
Join Date: Aug 2008
Posts: 233
Quote:
In the Assert statement error messages, CHR(13) does not produce a newline, just a square blob. Use CHR(10) instead, or just use a multi-line string literal, eg
Thanks. That's convenient. However, on my system [Win7/x64 when opening in VirtualDub], the CHR(13) does create a new line on Assert(), strangely enough. I'll look into it and revise using your recommendation.

Quote:
Also, Avisynth string comparison is case-insensitive, so there's no need to use LCase when comparing.
Another handy thing to know! Thanks again.
vampiredom is offline   Reply With Quote
Old 29th November 2011, 05:37   #4  |  Link
vampiredom
Registered User
 
Join Date: Aug 2008
Posts: 233
Updated: Some code cleanup per Gavino's suggestions, more sanity-checking, more flexibility for odd cropping of RGB sources. (download link is in the top post)
vampiredom is offline   Reply With Quote
Old 29th November 2011, 11:51   #5  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by vampiredom View Post
However, on my system [Win7/x64 when opening in VirtualDub], the CHR(13) does create a new line on Assert(), strangely enough.
Hmm, you're right - it seems it's just AvsP that displays it wrongly (haven't tried AvsPmod, but it's probably the same). Curious...
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Reply

Tags
conversion, par, pixel aspect ratio, resizer, scaling

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 11:28.


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