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 29th June 2008, 19:44   #1  |  Link
tacman1123
Registered User
 
Join Date: Jun 2007
Location: Washington, DC
Posts: 130
AVSPP: Avisynth Preprocessor, adds PHP scripting to Avisynth Scripts

I'm pleased to announce the alpha release of AVSPP, an Avisynth Preprocessor, available on sourceforge at

https://sourceforge.net/project/show...roup_id=232121

One of the more difficult tasks I've had an an Avisynth newcomer is getting sample scripts to work. Often a sample on the forum is dependent on something being installed, or runs on the author's machine and files but is difficult to replicate.

Another issue is easily processing a batch of files, such as all the jpegs in a directory. Finally, Avisynth control blocks are very cumbersome for the newcomer to use, and difficult to debug.

The Avisynth Preprocessor aims to make some of these issues easier. While it lacks documentation right now, I'll present two simple scripts the introduce some of the benefits of avspp.

Code:
# slideshow1.avp:  very simple display of a directory of jpg's, resizing them to fit
Global W = 720
Global H = 480
Global F = Framerate(AssumeFPS(BlankClip(),"ntsc_video"))
Global R = 48000
dissolve_time = 15
slide_time = 75
video = BlankClip(1, W, H, "RGB32", F, stereo=false).Trim(0, 1).KillAudio().Subtitle("Basic Slideshow")
<? foreach ('c:\photos\*.jpg') as $fn) { ?>
	a = ImageSource("<?=$fn?>").ConvertToRGB32().AssumeFPS(F).Trim(0, slide_time).BilinearResize(W, H)
	video = Dissolve(video, a, dissolve_time)
<? } ?>
return video
The initial setup is probably familiar to most people. The PHP scripting is handled inside of <? ... ?> tags. In this simple example, each jpg in the c:\photos directory is processed. The avisynth script it produces is

Code:
# slideshow1.avp:  goes through a directory of photos
Global W = 720
Global H = 480
Global F = Framerate(AssumeFPS(BlankClip(),"ntsc_video"))
Global R = 48000
dissolve_time = 15
slide_time = 75
video = BlankClip(1, W, H, "RGB32", F, stereo=false).Trim(0, 1).KillAudio().Subtitle("Basic Slideshow")
	a = ImageSource("C:\photos\2179140185_d7fd61f19a_o.jpg").ConvertToRGB32().AssumeFPS(F).Trim(0, slide_time).BilinearResize(W, H)
	video = Dissolve(video, a, dissolve_time)
	a = ImageSource("C:\photos\2179141497_af5c7dc947_o.jpg").ConvertToRGB32().AssumeFPS(F).Trim(0, slide_time).BilinearResize(W, H)
	video = Dissolve(video, a, dissolve_time)
return video
(Note: for simplcity, I've shortened the result to just 2 slides, obviously the power comes in not having to type in all the names of a much longer list of files.)

Of course, the problem with this simple script is that portrait files are stretched and look ugly. As part of Mike's KBE routines is a function called ZoomBox. The normal procedure to incorporate this would be to find the thread, cut out the code into your script or an avsi file, and make your code work. AVSPP automates this by extracting code from doom9 threads into a temporary file.

Here's a second example, with ZoomBox.

Code:
# slideshow2.avp:  goes through a directory of photos

Global W = 720
Global H = 480
Global F = Framerate(AssumeFPS(BlankClip(),"ntsc_video"))
Global R = 48000
video = BlankClip(1, W, H, "RGB32", F, stereo=false).Trim(0, 1).KillAudio().Subtitle("Slideshow with no resizing")

# the zoombox function requires Avisynth 2.58, which has max() as a native function.  
# define it here for 2.57 users
function max(x,y) { return x > y ? x : y }

<?
/*
import_code() is a function that goes to the zoom9 forums and grabs the first  block,
and puts that block of code into the avspp download directory (default is a directory named 'downloads'
in the directory where avspp.exe.  The second parameter is the local name of the file.

Once the code has been downloaded to a local file, it can be called by Avisynth with import.

In this case, we want the code for the ZoomBox routine, which will preserve the aspect ratio 
when resizing the photo, so that the pictures are not distorted.

*/		
import_code('http://forum.doom9.org/showthread.php?p=1111789#post1111789', "zoom.avsi");

# this 
foreach (glob(dirname(__FILE__) . '\loc_photos\*.jpg') as $fn) 
{ 
?>
	a = ImageSource("<?=$fn?>").ConvertToRGB32().AssumeFPS(F).Trim(0, 90).ZoomBox(W, H)
	video = Dissolve(video, a, 20)
<?
}
?>
video
The relevant line here is import_code, which automatically extracts the code, creates the .avsi file, and includes it, so running

avspp examples\slideshow2.avp

will create examples\slideshow2.avs, which looks like

Code:
# slideshow2.avp:  goes through a directory of photos

Global W = 720
Global H = 480
Global F = Framerate(AssumeFPS(BlankClip(),"ntsc_video"))
Global R = 48000
video = BlankClip(1, W, H, "RGB32", F, stereo=false).Trim(0, 1).KillAudio().Subtitle("Slideshow with no resizing")

# the zoombox function requires Avisynth 2.58, which has max() as a native function.  
# define it here for 2.57 users
function max(x,y) { return x > y ? x : y }

#Getting http://forum.doom9.org/showthread.php?p=1111789#post1111789
#   from S:\vt\avspp\downloads\zoom.avsi
import("S:\vt\avspp\downloads/zoom.avsi")

	a = ImageSource("S:\vt\avspp\examples\loc_photos\2179140185_d7fd61f19a_o.jpg").ConvertToRGB32().AssumeFPS(F).Trim(0, 90).ZoomBox(W, H)
	video = Dissolve(video, a, 20)
video
I have some other examples I'm working on, including an easy way to use the KenBurnsEffect that Mike's been working on. I'd also like to use the Avisynth Library, which looks really cool but lacks examples.

Avspp can also download images from the internet, which will make presenting examples much, much easier (I'll post that example shortly), and in the future will be able to get dll's.

Anyway, I'm quite jazzed about this script, I want to thank the doom9 community for all their support, and hope that this tool will grow into something useful for Avisynth fans.

I look forward to comments and feedback!

Tac
tacman1123 is offline   Reply With Quote
Old 2nd July 2008, 21:25   #2  |  Link
Comatose
Registered User
 
Join Date: Dec 2007
Posts: 639
Didn't work for me =/
I used the slideshow2.avp sample, only changing \loc_photos\ to \pics\ (didn't touch the quotes or anything)...

It didn't process any of the PHP. The AVS is created was exactly the same as the AVP.
Comatose is offline   Reply With Quote
Old 3rd July 2008, 03:36   #3  |  Link
tacman1123
Registered User
 
Join Date: Jun 2007
Location: Washington, DC
Posts: 130
Thanks for the feedback. When you ran

avspp examples\slideshow2.avp

It didn't create a file examples\slideshow2.avs?

What did it create? Can you send me the log of what it produced? (Post it here, or send to tac at smokescreen dot org)

Thanks, and thanks for giving it a try! (My first sourceforge project, my first official contribution to Open Source, hoping it turns out to be worthwhile!)

Tac
tacman1123 is offline   Reply With Quote
Old 3rd July 2008, 09:22   #4  |  Link
Comatose
Registered User
 
Join Date: Dec 2007
Posts: 639
It created slideshow2.avs, but it didn't process the PHP code in the AVP, so what was in the created slideshow2.avs was identical to the AVP contents ><
Also, what showed in stdout was the same as what was outputted to the AVS, if that helps.
Comatose is offline   Reply With Quote
Old 6th July 2008, 06:53   #5  |  Link
matrix
Registered User
 
Join Date: Jan 2002
Location: ..north of Great Lakes
Posts: 263
Well, your examples work fine, but how do I make it look in another directory than "loc_photos"?
I tried changing that to different folders, but it didn't seem to work. I got the same results as Comatose.
So again, what do I have to change to point it to a different directory?
__________________
Welcome....to the real world.
matrix is offline   Reply With Quote
Old 6th July 2008, 15:52   #6  |  Link
tacman1123
Registered User
 
Join Date: Jun 2007
Location: Washington, DC
Posts: 130
The code glob(dirname(__FILE__) . '\loc_photos\*.jpg') was written so that it would work regardless of where the user installed the program. But I see that it's confusing. Try changing it to

Code:
<? foreach ('c:\My Photos\loc_photos\*.jpg') as $fn) { ?>
or whatever the name of the directory is.

I'll add some more options next alpha release, with more debugging.

Tac
tacman1123 is offline   Reply With Quote
Old 6th July 2008, 17:10   #7  |  Link
matrix
Registered User
 
Join Date: Jan 2002
Location: ..north of Great Lakes
Posts: 263
It doesn't work like that.
Only if I copy the slideshow2.avp to the directory where the folder with photos is.
for example I changed the line to this:
foreach (glob(dirname(__FILE__) . '\dvd covers\*.jpg') as $fn)
and put the slideshow2.avp on C:\ (that is where the dvd covers folder is) it works like this.
But if I change the path in the .avp file like this:
foreach (glob(dirname(__FILE__) . 'c:\dvd covers\*.jpg') as $fn)
and run it from where I have it now (c:\unzipped\avspp-a2), it won't work.
__________________
Welcome....to the real world.
matrix is offline   Reply With Quote
Old 6th July 2008, 18:39   #8  |  Link
tacman1123
Registered User
 
Join Date: Jun 2007
Location: Washington, DC
Posts: 130
Does
Code:
foreach ('c:\unzipped\dvd covers\*.jpg') as $fn)
work correctly? (Assuming I understood where the jpg's are located). Also, glob() is case sensitive, so if the photos are .JPG, you need to capitialize it.

I'm assuming the problem now is that no files in the loop, right?
tacman1123 is offline   Reply With Quote
Old 6th July 2008, 20:11   #9  |  Link
matrix
Registered User
 
Join Date: Jan 2002
Location: ..north of Great Lakes
Posts: 263
No, maby I didn't express myself correctly.

Your program is in "c:\unzipped\avspp-a2", where I unzipped it.
Now I type in the cmd prompt: "avspp examples\slideshow2.avp" and it works correctly. That line in the slideshow2.avp file is: foreach (glob(dirname(__FILE__) . '\loc_photos\*.jpg') as $fn) . If I edit that line to: foreach (glob(dirname(__FILE__) . 'C:\dvd covers\*.jpg') as $fn) and type the same thing in the cmd prompt, it doesn't work.

But if I move the slideshow2.avp in "c:\" and change the line to this: foreach (glob(dirname(__FILE__) . '\dvd covers\*.jpg') as $fn), and then type in the cmd prompt : "avspp c:\slideshow2.avp", it works.

So I have to have the slideshow2.avp file in the parent directory of the picture folder. in my case "C:\" . If the avp file is not there, it won't work.

Mabe that's the way it's supposed to be?.
__________________
Welcome....to the real world.
matrix is offline   Reply With Quote
Old 6th July 2008, 22:01   #10  |  Link
Leak
ffdshow/AviSynth wrangler
 
Leak's Avatar
 
Join Date: Feb 2003
Location: Austria
Posts: 2,441
Quote:
Originally Posted by matrix View Post
Mabe that's the way it's supposed to be?.
Well, let's look at that code in depth:

dirname(__FILE__) ... evaluates to the directory where the file itself is located, i.e. 'c:\unzipped\avspp-a2'
. ... joins the two strings to the left and right of it
'c:\dvd covers\*.jpg' ... is just that

So if you run the above it will look for the files in 'c:\unzipped\avspp-a2c:\dvd covers\*.jpg', which of course is doomed to fail.

If you want to use your own path, totally drop the 'dirname(__FILE__) .' bit and just put your own path, quoted with single quotes, into that call to glob()...

np: Richard Devine - Patelle (Lipswitch)
__________________
now playing: [artist] - [track] ([album])
Leak is offline   Reply With Quote
Old 7th July 2008, 01:47   #11  |  Link
matrix
Registered User
 
Join Date: Jan 2002
Location: ..north of Great Lakes
Posts: 263
Oh yeah. Thanks Leak.
It works now.
I can just have a slideshow.avp file, and access any photo folder by changing the path in it.
I like that.
__________________
Welcome....to the real world.
matrix 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 14:57.


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