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 17th December 2018, 20:32   #1  |  Link
Qaenos
Registered User
 
Join Date: Oct 2018
Posts: 35
Looking for a 64-bit Non-Linear Resizer

I'm upgrading to AVS+ 64-bit and I have a few scripts that need to undo some videos that took the original 4:3 image and non-linearly stretched it to 16:9. Basically the center pixels were almost unchanged, but the stretching got exponentially worse towards the edge of the images.

I've been using WarpedResize from SimpleResize.dll and it works well in 32-bit. Problem is there's inline assembly in the source code that's preventing me from compiling a 64-bit version myself.
Qaenos is offline   Reply With Quote
Old 18th December 2018, 00:02   #2  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,492
Can you give this a try?

http://horman.net/avisynth/download/widen.zip

It takes four parameters:

Code:
width   : the new width of the video
scale   : stretch the center by this amount (to compensate for distortion at the edges). Defaults to 1 (maintains the original aspect ratio of the center)
quality : 0 = nearest neighbour, 1 = bilinear, 2 = bicubic ( can also use WIDEN_DRAFT, WIDEN_BILINEAR, or WIDEN_BICUBIC . defaults to WIDEN_BICUBIC )
threads : number of threads to use. Defaults to number of logical processors

Example:

colorbars(pixel_type="yv12")
widen(960,1.25)
It's very thrown together so it may well crash. I've tried to reject invalid values for the parameters but I'm not certain what's good and bad. It can only handle Y8, YV12, YV24 and 8-bit planar RGB (Avisynth+) video.

8-bit planar RGB gives the best results because it is (approximately) gamma-aware.
__________________
My AviSynth filters / I'm the Doctor

Last edited by wonkey_monkey; 18th December 2018 at 01:33.
wonkey_monkey is offline   Reply With Quote
Old 18th December 2018, 16:17   #3  |  Link
Qaenos
Registered User
 
Join Date: Oct 2018
Posts: 35
Quote:
Originally Posted by davidhorman View Post
I did, thank you!

Unfortunately, when I went to run it, I got a error message from AVISynth+ stating that there was no function named "Widen". I double checked that I had placed widen.dll in my 64-bit plugin folder (where I have MaskTools2.dll, etc.,) and it's there. I'm not sure what the problem is.
Qaenos is offline   Reply With Quote
Old 18th December 2018, 16:58   #4  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Works here, (tested in 64 bit, plugins, plugins+ and avs LoadPlugin).
Req CPP runtimes from VS 2013.
Code:
#LoadPlugin(".\Widen.dll") # if not in plugins dir
Colorbars(Pixel_Type="YV24")
widen(960,1.25)
Return Last


try Groucho2004 AvsMeter avsinfo
(me guesses that you is usin' 32 bit avs+, you got both installed ?, try load into Vdub2 64 bit.).
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 18th December 2018 at 17:05.
StainlessS is offline   Reply With Quote
Old 18th December 2018, 17:33   #5  |  Link
Qaenos
Registered User
 
Join Date: Oct 2018
Posts: 35
I was missing VC 2013 CPP runtime. Now it runs, thanks!

Now my problem is using this. I can stretch an image, just like the colorbars example

Colorbars(Pixel_Type="YV24")
widen(960,1.25)

but I need to go the other way. I need to shrink a 16:9 image that has been non-linearly stretched from it's original 4:3. I want to go back to the 4:3 by non-linearly shrinking the image with the shrinkage being highest at the edges and very little at the center.

I tried using a width that is less than the original, as well as a fraction for scale (e.g. 0.75) and a negative for the scale (e.g. -1.25) but all I get is error messages such as "Stretch must bust be less than 1.7777" etc.
Qaenos is offline   Reply With Quote
Old 18th December 2018, 21:14   #6  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,492
Okay, how about this?

http://horman.net/avisynth/download/unwiden.zip

The filter name is, rather unimaginatively, unwiden. I'm not sure what it'll do if you give it a bigger width then the input image, so don't do that. Try stretch<=1 - it should throw an error if you give it an out of range value.

Edit: I have no idea how the original resizer used worked, so I don't know how good the result will be with unwiden.
__________________
My AviSynth filters / I'm the Doctor

Last edited by wonkey_monkey; 18th December 2018 at 21:29.
wonkey_monkey is offline   Reply With Quote
Old 18th December 2018, 22:49   #7  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
According to my free WordWeb popup dictionary (very old from maybe Win98/2000 or thereabouts, apparently last updated Oct 2017),
Widen, Antonym = Narrow.
Perhaps you would like to rename Widen to UnNarrow.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 19th December 2018, 00:01   #8  |  Link
Qaenos
Registered User
 
Join Date: Oct 2018
Posts: 35
Quote:
Originally Posted by davidhorman View Post
Okay, how about this?

http://horman.net/avisynth/download/unwiden.zip

The filter name is, rather unimaginatively, unwiden. I'm not sure what it'll do if you give it a bigger width then the input image, so don't do that. Try stretch<=1 - it should throw an error if you give it an out of range value.

Edit: I have no idea how the original resizer used worked, so I don't know how good the result will be with unwiden.
It worked with planar RGB, thanks! I'll play with it for a bit and see what scale value works best but ~0.6 is not bad for the videos I am trying to fix.

FYI, it did not work with YV12, though. There was color in the center of the image, but it was messed up. The sides of the image had no color (monochrome).

Last edited by Qaenos; 19th December 2018 at 00:42.
Qaenos is offline   Reply With Quote
Old 19th December 2018, 00:49   #9  |  Link
Qaenos
Registered User
 
Join Date: Oct 2018
Posts: 35
By the way, do you happen to have a 32-bit dll compiled for widen/unwiden.dll? Once in a while, I still need to run a 32-bit version of AVISynth and I like to keep the same filters, if possible. If not, I'll just keep using WarpedResize from SimpleResize.dll when I have to run a 32-bit version of AVISynth, but your filter seems to work pretty good.
Qaenos is offline   Reply With Quote
Old 19th December 2018, 00:56   #10  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,492
Obviously a scaling problem with subsampled chroma. It probably works fine with YV24, but Planar RGB gives the technically best result (if not distinguishable with normal footage).

I can compile 32-bit versions at some point, but my project's a bit all over the place at the moment.
__________________
My AviSynth filters / I'm the Doctor
wonkey_monkey is offline   Reply With Quote
Old 19th December 2018, 01:05   #11  |  Link
Qaenos
Registered User
 
Join Date: Oct 2018
Posts: 35
Quote:
Originally Posted by davidhorman View Post
Obviously a scaling problem with subsampled chroma. It probably works fine with YV24, but Planar RGB gives the technically best result (if not distinguishable with normal footage).

I can compile 32-bit versions at some point, but my project's a bit all over the place at the moment.
No rush! The 64-bit was what I really needed, thanks! If you ever do get around to making a 32-bit dll I'd love to get a copy, but please don't go out of your way.
Qaenos is offline   Reply With Quote
Old 19th December 2018, 04:37   #12  |  Link
Qaenos
Registered User
 
Join Date: Oct 2018
Posts: 35
Quote:
Originally Posted by davidhorman View Post
Obviously a scaling problem with subsampled chroma. It probably works fine with YV24, but Planar RGB gives the technically best result (if not distinguishable with normal footage).

I can compile 32-bit versions at some point, but my project's a bit all over the place at the moment.
Yep, tested it with YV24 and it works fine.
Qaenos is offline   Reply With Quote
Old 19th December 2018, 05:56   #13  |  Link
Qaenos
Registered User
 
Join Date: Oct 2018
Posts: 35
Hmmm...tried a few more videos and I keep getting a "bad stretch parameter?" error when I try to Unwiden.

The error seems to be related to the ratio between the input width and the output width. For example, I have a 1920x1080 video I want to unwiden to 640x480.


Unwiden(640, 0.6)
BiCubicResize(640,480)

will give "bad stretch parameter?" error

If I go

BiCubicResize(640,480)
Unwiden(640, 0.6)

I also get the "bad stretch parameter?" error.

But if I go

BiCubicResize(640 * 2,480)
Unwiden(640, 0.6)

It works!

Yet if I go,

BiCubicResize(640 * 3,480)
Unwiden(640, 0.6)

I once again get the "bad stretch parameter?" error.
Qaenos is offline   Reply With Quote
Old 19th December 2018, 06:00   #14  |  Link
Qaenos
Registered User
 
Join Date: Oct 2018
Posts: 35
Actually, forgive me if it's obvious (I'm still sort of new to AVISynth) but why do you recommend PlanarRGB instead of YV24? What do you mean by it gives the technically best result? Sometimes I work with RGB footage, but more often than not I'm dealing with YV12. I was under the impression that a YV12 to YV24 conversion would be better than a YV12 to PlanarRGB conversion.
Qaenos is offline   Reply With Quote
Old 19th December 2018, 10:06   #15  |  Link
jpsdr
Registered User
 
Join Date: Oct 2002
Location: France
Posts: 2,297
Is there by any chance, out of curiosity, the source code of theses widen/unwiden somewhere ?
__________________
My github.
jpsdr is offline   Reply With Quote
Old 19th December 2018, 11:22   #16  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,492
I used some pretty dodgy maths to work out the remapping and some even dodgier assumptions to try and avoid getting stuck in an infinite loop. I'm not sure why some parameter combinations don't work.

RGB is best because it can take gamma into account. You'd get this with YUV:


but with RGB and taking gamma into account, you get this:


widen/unwiden does slightly better than the first image with YUV because it still takes gamma into account with the Y channel, but not the UV channels, so colours can still be slightly messed up. With natural footage you probably won't notice the problem.
__________________
My AviSynth filters / I'm the Doctor

Last edited by wonkey_monkey; 19th December 2018 at 13:06.
wonkey_monkey 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 15:04.


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