Sign In

Panorama() - an AviSynth function for converting 4:3 into 16:9

Author
Time
This started out as a bit of fun, just a daft idea I had. However, the script function that resulted may be of use so I'm posting it here.

Let's say you have some deleted scenes you want to edit back into the main movie. The problem is, the deleted scenes are in 4:3, but your main feature is in 16:9 widescreen.

http://img.photobucket.com/albums/v670/Moth3r/pano/4-3.png
Geometry of 4:3 source

The standard options for dealing with this problem are:
a) Pillarbox the 4:3 frame into a 16:9 frame. You end up with black bars either side of the 4:3 frame.

http://img.photobucket.com/albums/v670/Moth3r/pano/pillarbox.png
4:3 image pillarboxed into 16:9 frame

b) Zoom in on a 16:9 frame within the 4:3 frame. You end up cropping the top and bottom of the image.

http://img.photobucket.com/albums/v670/Moth3r/pano/cropped.png
4:3 image cropped and zoomed to make it 16:9

c) Stretch the 4:3 frame out horizontally to make it 16:9. You end up with a distorted aspect ratio.

http://img.photobucket.com/albums/v670/Moth3r/pano/stretched.png
4:3 image stretched to make it 16:9

This AviSynth function gives you a 4th option. The idea came from the manufacturers of widescreen TVs. Many sets give you the option to display 4:3 material in a mode that stretches the image differentially; the central area where the most important action occurs is not stretched as much as the image towards the edges of the screen (which is normally just background).

http://img.photobucket.com/albums/v670/Moth3r/pano/pana4.png
Panoramically stretched 4:3 image. No cropping, no black bars,
and central portion of image is not too stretched


When using the Panorama() function you have a choice of 4 strength settings:
1. A weak effect - not much different to a uniform horizontal stretch.
2. Medium - still stretched, although a little more natural looking at the centre, minor bit of distortion towards the edges.
3. Strong - not much of a stretch at the centre, noticeable distortion at the image edges.
4. Very strong - aspect ratio of central portion is almost correct, but there are large distortions at the edges.

Please remember that I am not an AviSynth guru; there are probably neater/better ways to do this. I would welcome any suggestions for improvement.

Here is the function:

function Panorama(clip clp, int "strength")
{

# function for converting 4:3 full frame clips to simulated 16:9
# source vid should be 720x480 or 720x576 and have display AR of 4:3
# script by Moth3r - originaltrilogy.com

ht=clp.height

a=(strength==1)?clp.lanczos4resize(256,ht,0,0,-660,0): \
(strength==2)?clp.lanczos4resize(284,ht,0,0,-660,0): \
(strength==3)?clp.lanczos4resize(308,ht,0,0,-660,0): \
clp.lanczos4resize(332,ht,0,0,-660,0)
b=(strength==1)?clp.lanczos4resize(248,ht,60,0,-600,0): \
(strength==2)?clp.lanczos4resize(260,ht,60,0,-600,0): \
(strength==3)?clp.lanczos4resize(272,ht,60,0,-600,0): \
clp.lanczos4resize(284,ht,60,0,-600,0)
c=clp.lanczos4resize(240,ht,120,0,-540,0)
d=(strength==1)?clp.lanczos4resize(236,ht,180,0,-480,0): \
(strength==2)?clp.lanczos4resize(228,ht,180,0,-480,0): \
(strength==3)?clp.lanczos4resize(220,ht,180,0,-480,0): \
clp.lanczos4resize(212,ht,180,0,-480,0)
e=(strength==1)?clp.lanczos4resize(232,ht,240,0,-420,0): \
(strength==2)?clp.lanczos4resize(216,ht,240,0,-420,0): \
(strength==3)?clp.lanczos4resize(204,ht,240,0,-420,0): \
clp.lanczos4resize(192,ht,240,0,-420,0)
f=(strength==1)?clp.lanczos4resize(456,ht,300,0,-300,0): \
(strength==2)?clp.lanczos4resize(424,ht,300,0,-300,0): \
(strength==3)?clp.lanczos4resize(392,ht,300,0,-300,0): \
clp.lanczos4resize(360,ht,300,0,-300,0)
g=(strength==1)?clp.lanczos4resize(232,ht,420,0,-240,0): \
(strength==2)?clp.lanczos4resize(216,ht,420,0,-240,0): \
(strength==3)?clp.lanczos4resize(204,ht,420,0,-240,0): \
clp.lanczos4resize(192,ht,420,0,-240,0)
h=(strength==1)?clp.lanczos4resize(236,ht,480,0,-180,0): \
(strength==2)?clp.lanczos4resize(228,ht,480,0,-180,0): \
(strength==3)?clp.lanczos4resize(220,ht,480,0,-180,0): \
clp.lanczos4resize(212,ht,480,0,-180,0)
i=clp.lanczos4resize(240,ht,540,0,-120,0)
j=(strength==1)?clp.lanczos4resize(248,ht,600,0,-60,0): \
(strength==2)?clp.lanczos4resize(260,ht,600,0,-60,0): \
(strength==3)?clp.lanczos4resize(272,ht,600,0,-60,0): \
clp.lanczos4resize(284,ht,600,0,-60,0)
k=(strength==1)?clp.lanczos4resize(256,ht,660,0,0,0): \
(strength==2)?clp.lanczos4resize(284,ht,660,0,0,0): \
(strength==3)?clp.lanczos4resize(308,ht,660,0,0,0): \
clp.lanczos4resize(332,ht,660,0,0,0)

clp=StackHorizontal(a, b, c, d, e, f, g, h, i, j, k)

return clp.lanczos4resize(720,ht)
}
(Now, who's going to be first to put the cut scenes back into dark_jedi's Howard the Duck release?)

Guidelines for post content and general behaviour: read announcement here

Max. allowable image sizes in signatures: reminder here

Author
Time
This awsome, Moth3r! Thanks for supplying us with it.


Author
Time
Thanks Moth3r
I'm going to try this out on a project that I am working on.
Author
Time
I asked about doing this on videohelp.com months ago.
Thanks for the script.Will have to do some trials with some video clips just to see how well it works.
Author
Time
How do I get this to work in virtualdub?
I'm used to using virtualdub but have never used any type of scripts with it.

Tell me if this is right
Example of test I am doing

AVISource("C:\fallofachampion_led.avi")

function Panorama(clip clp, int "medium")

and I left the rest of the script the same

I then open up virtualdub, and goto File, Open video file. I select the .avs script and it loads up the video just fine. What do I do from there?

If this helps i am using sample 4:3 avi from this page http://www.100fps.com/
near the bottom

http://www.100fps.com/fallofachampion_led.avi


*edit*
I think I found what is wrong
The source has to be 720x480
I'll try to find a video sample of that size and try again.


Author
Time
You can resize the video in AviSynth using
Lanczos4Resize(720, 480)
Author
Time
AVISource("C:\fallofachampion_led.avi")
Lanczos4resize(720,480)
Panorama(strength=2)
... should do it.

To check the AR, right-click on the VirtualDub preview window and select "16:9".

Guidelines for post content and general behaviour: read announcement here

Max. allowable image sizes in signatures: reminder here

Author
Time
Nice job, Moth3r.
MeBeJedi: Sadly, I believe the prequels are beyond repair.
JediRandy: They're certainly beyond any repair you're capable of making.


MeBeJedi: You aren't one of us.
Go-Mer-Tonic: I can't say I find that very disappointing.


JediRandy: I won't suck as much as a fan edit.
Author
Time
Originally posted by: Moth3r
AVISource("C:\fallofachampion_led.avi")
Lanczos4resize(720,480)
Panorama(strength=2)
... should do it.

To check the AR, right-click on the VirtualDub preview window and select "16:9".


I did it this way
AVISource("C:\fallofachampion_led.avi")
Lanczos4resize(720,480)
function Panorama(clip clp, int "medium")

using Panorama(strength=2)
said it had an error in line3

Looks like it is working


Author
Time
Works fine for me.

http://img.photobucket.com/albums/v670/Moth3r/pano/zidane0.jpg
4:3 Source

Results (obviously resized for display):

http://img.photobucket.com/albums/v670/Moth3r/pano/zidane1.jpg
Panorama(strength=1)

http://img.photobucket.com/albums/v670/Moth3r/pano/zidane2.jpg
Panorama(strength=2)

http://img.photobucket.com/albums/v670/Moth3r/pano/zidane3.jpg
Panorama(strength=3)

http://img.photobucket.com/albums/v670/Moth3r/pano/zidane4.jpg
Panorama(strength=4)

Guidelines for post content and general behaviour: read announcement here

Max. allowable image sizes in signatures: reminder here

Author
Time
Yeah, whip out that damn fullscreen-release...

By the way, nice job Moth3r... a question though, when using "only" 8 strips, isn't there a risk of having slight "sharp bends" in very steep diagonals?
Author
Time
The image is actually divided into 12 (the two central strips are treated together), but yes, that is a risk in theory.

Guidelines for post content and general behaviour: read announcement here

Max. allowable image sizes in signatures: reminder here

Author
Time
Originally posted by: Laserman
Nice work!
How about a SW scene? Sure...

http://img.photobucket.com/albums/v670/Moth3r/cindel0.jpg



Actually, I just wanted to show that using Panorama in combination with a little cropping and a little "pillarboxing", you can reduce the edge distortions somewhat.

For example (PAL 4:3 source):
lanczos4resize(688,604)
crop(0,14,0,-14)
addborders(16,0,16,0)
panorama(3)

http://img.photobucket.com/albums/v670/Moth3r/cindel1.jpg
or:lanczos4resize(672,632)
crop(0,28,0,-28)
addborders(24,0,24,0)
panorama(2)

http://img.photobucket.com/albums/v670/Moth3r/cindel2.jpg

Guidelines for post content and general behaviour: read announcement here

Max. allowable image sizes in signatures: reminder here

Author
Time
Hmmm, well now I feel like a bit of a fool.

Someone already wrote a filter that does the same thing - about 4 years ago. Check out WarpedResize at this page.

Guidelines for post content and general behaviour: read announcement here

Max. allowable image sizes in signatures: reminder here

Author
Time
So you write AviSynth filters and still think of yourself as a fool? Hardly.

What's the difference between yours and that other one?
Author
Time
Originally posted by: Moth3r
Hmmm, well now I feel like a bit of a fool.

Someone already wrote a filter that does the same thing - about 4 years ago. Check out WarpedResize at this page.

What is the differences in yours vs his?
Or they exactly alike?
Author
Time
Originally posted by: Moth3r
Hmmm, well now I feel like a bit of a fool.

Someone already wrote a filter that does the same thing - about 4 years ago. Check out WarpedResize at this page.


But we get to see how yours works and can tweak it, I never would have known the other one existed if you hadn't posted yours.
Author
Time
Originally posted by: Moth3r
Hmmm, well now I feel like a bit of a fool.

Someone already wrote a filter that does the same thing - about 4 years ago. Check out WarpedResize at this page.


Nice job, Moth3r! I saw this treatment on a widescreen TV at Chili's Restaurant and always wanted to know a way to achieve the same. Thanks for bringing the knowledge to the forum.
Author
Time
Originally posted by: Zeromancer
What is the differences in yours vs his?
Or they exactly alike?
The main difference is that I just used a bit of maths together with AviSynth's bulit-in resize filters to kludge together a custom function; trbarry is actually clever enough to code his own filters.

I was going to try his filter out last night but didn't get round to it; it looks like it can do exactly the same thing, but on a mathematical curve rather than a linear approximation. It also seems much more tweakable than mine, it will do different resolutions and warp vertically, too.

However, at least my function works in YV12 colorspace!

I would love to be able to program for myself (and take on Laserman's colour grading idea). In the past I've learned BASIC and FORTRAN 77, so it probably wouldn't be too hard for me to learn C++ or whatever people use these days. It's just finding the time to do so.

Guidelines for post content and general behaviour: read announcement here

Max. allowable image sizes in signatures: reminder here