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 26th January 2011, 20:46   #1  |  Link
fenomeno83
Registered User
 
Join Date: Aug 2006
Posts: 336
for cycle

Hello. I need to write in a script a code like this

//I want load, process and save 1.jpg, 2.jpg, 3.jpg



for (i = 1; i <= 3; i++)

{

string1 = String(i)
string2 = string1 + ".jpg"
ImageSource(string2)
.....
.....
ImageWriter (string2,0,0,"jpg")
i = i + 1;
}


How can I implement loop in avisynth?
thanks
fenomeno83 is offline   Reply With Quote
Old 26th January 2011, 23:44   #2  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,418
The Avisynth language does not have a loop construct, but looping can be achieved using a recursive function.

Alternatively, GScript is a set of language extensions that includes a for-loop construct.

There are a couple of things to sort out in your script, though.
First, I'm sure you didn't mean to have both i++ and i=i+1 in the code.
Less obviously, you need to be aware that ImageWriter will only write to the file for frames that form part of the script's final output. So you need to join the individual ImageWriter results together.
Code:
GScript("""
  for (i = 1, 3) {
    string1 = String(i)
    string2 = string1 + ".jpg"
    ImageSource(string2)
    .....
    ImageWriter (string2,0,0,"jpg")
    result = (i == 1 ? last : result + last)
  }
  return result
""")
Note that this assumes the images all have the same resolution; otherwise the splice will fail unless you convert them to the same size.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 27th January 2011, 01:54   #3  |  Link
ajp_anton
Registered User
 
ajp_anton's Avatar
 
Join Date: Aug 2006
Location: Stockholm/Helsinki
Posts: 792
Quote:
Originally Posted by Gavino View Post
Note that this assumes the images all have the same resolution; otherwise the splice will fail unless you convert them to the same size.
You could just do

result = (i == 1 ? pointresize(16,16) : result + pointresize(16,16))

or a better resizer/bigger size if you actually want to preview the images.
ajp_anton is offline   Reply With Quote
Old 27th January 2011, 11:39   #4  |  Link
fenomeno83
Registered User
 
Join Date: Aug 2006
Posts: 336
i don't understand how write several output images with imagewriter (write only the first)

how create in alternative a recursive function?
fenomeno83 is offline   Reply With Quote
Old 27th January 2011, 12:03   #5  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,418
Quote:
Originally Posted by fenomeno83 View Post
i don't understand how write several output images with imagewriter (write only the first)
Are you saying the script above does not work?
Note that you must 'play' the entire video for ImageWriter to write everything out.
Quote:
how create in alternative a recursive function?
Code:
function f(int i, int limit) {
  string1 = String(i)
  string2 = string1 + ".jpg"
  ImageSource(string2)
  .....
  ImageWriter (string2,0,0,"jpg")
  PointResize(16, 16) # see ajp_anton's post
  return (i < limit ? last+f(i+1, limit) : last)
}

f(1, 3)
__________________
GScript and GRunT - complex Avisynth scripting made easier

Last edited by Gavino; 27th January 2011 at 12:09. Reason: must play entire video
Gavino is offline   Reply With Quote
Old 27th January 2011, 14:26   #6  |  Link
fenomeno83
Registered User
 
Join Date: Aug 2006
Posts: 336
thanks!!
fenomeno83 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 11:11.


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