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. |
|
|
Thread Tools | Search this Thread | Display Modes |
29th June 2008, 18:44 | #1 | Link |
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 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 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 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 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 |
3rd July 2008, 02:36 | #3 | Link |
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 |
3rd July 2008, 08:22 | #4 | Link |
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. |
6th July 2008, 05:53 | #5 | Link |
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. |
6th July 2008, 14:52 | #6 | Link |
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) { ?> I'll add some more options next alpha release, with more debugging. Tac |
6th July 2008, 16:10 | #7 | Link |
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. |
6th July 2008, 17:39 | #8 | Link |
Registered User
Join Date: Jun 2007
Location: Washington, DC
Posts: 130
|
Does
Code:
foreach ('c:\unzipped\dvd covers\*.jpg') as $fn) I'm assuming the problem now is that no files in the loop, right? |
6th July 2008, 19:11 | #9 | Link |
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. |
6th July 2008, 21:01 | #10 | Link |
ffdshow/AviSynth wrangler
Join Date: Feb 2003
Location: Austria
Posts: 2,441
|
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]) |
7th July 2008, 00:47 | #11 | Link |
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. |
Thread Tools | Search this Thread |
Display Modes | |
|
|