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 1st May 2020, 15:20   #1  |  Link
Georgiana
Registered User
 
Join Date: Apr 2020
Posts: 4
Using for loop with imagewriter

Is there any chance to use a for loop and inside this loop to have executed a series of imagewriters? One at each step of the loop, in order to write some frames of a clip? I have already tried:

for (i=0,3,1)
{
imagewriter (clip,"path",start=i,end=i,type="jpg")
}

But it seems that ONLY for the last value of i, the imagewriter is executed. How could I tell the imagewriter to be executed for my specific number of steps, not only for the last one? Thank you for any advice!
Georgiana is offline   Reply With Quote
Old 1st May 2020, 20:26   #2  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,412
The reason this doesn't work is that ImageWriter() only produces output when frames are requested from the filter, and for this to happen the filter must be in the filter graph contributing to the final result of the script.
In your script, only the last loop iteration is used in the result of the script so it's the only one that actually does any writing.

But if I understand what you are trying to do, you don't need a loop here.
Just:
Code:
ImageWriter(clip,"path",start=0,end=3,type="jpg")
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 1st May 2020, 21:02   #3  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 9,132
Damn that Gavino, stays aways for years at a time and then jumps in to spoil my fun.

Anyway, pretending that above did not happen.

script 1 [EDIT: play file at least past last write frame]
Code:
/*

ImageWriter(clip, string "file", int "start", int "end", string "type", bool "info")

*/

Colorbars().Trim(0,-200)        # 200 frames
ShowFrameNumber

FILE="D:\IMWR\MyFile_"
START=100
END=103
TYPE = "jpeg"
INFO=False
ImageWriter(File=FILE,Start=START,end=END,type=TYPE,info=INFO)      # Output MyFile_000100.jpeg -> MyFile_000103.jpeg
Return last
script 2 [EDIT: play complete 4 frame clip]
Code:
Colorbars().Trim(0,-200)        # 200 frames
ShowFrameNumber

Trim(100,-4)                    # 4 frames, 100 -> 103

FILE="D:\IMWR\MyFile_"

START=0                         # All frames (ie 0 -> 3)
END=0
TYPE = "jpeg"
INFO=False

ImageWriter(File=FILE,Start=START,end=END,type=TYPE,info=INFO)      # Output MyFile_000000.jpeg -> MyFile_000003.jpeg
Return last
script 3 [EDIT: play at least 1 frame]
Code:
Colorbars().Trim(0,-200)        # 200 frames
ShowFrameNumber

FILE="D:\IMWR\MyFile_"
TYPE = "jpeg"
INFO=False

Trim(100,-4)                    # 100 -> 103

For(i=0,3) {
    current_frame=i                                                 # kludge to make Imagewriter work (pretend in runtime environment)
    k=ImageWriter(File=FILE,Start=i,end=i,type=TYPE,info=INFO)      # Output MyFile_000000.jpeg -> MyFile_000003.jpeg
    k.ConvertToY8.Averageluma                                       # Kludge to force write files (ImageWriter only writes frame when frame is requested from the ImageWriter result clip)
}

Return MessageClip("All Done")
ImageWriter is not the easiest filter to abuse. [scripts 2 and 3 to write frame filenames relative to 0 rather than 100]
EDIT: Output filenames are 'Tied' to the frame numbers being output [thats why we had to use Trim for filenames relative 0].
__________________
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; 1st May 2020 at 21:25.
StainlessS is offline   Reply With Quote
Old 1st May 2020, 21:23   #4  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,412
Quote:
Originally Posted by StainlessS View Post
Damn that Gavino, stays aways for years at a time and then jumps in to spoil my fun.

What took you so long? LOL

Good to see you've found another use for my 'current_frame' trick too.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 1st May 2020, 21:28   #5  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 9,132
Quote:
What took you so long
Well, I thought I had plenty of time, did not anticipate the interloper.

Quote:
Good to see...
I like to keep that quiet.

Dont be so much a stranger Big G, nice to see you

EDIT: Maybe a bit more flexible [writing filenames relative 0].
Code:
Colorbars().Trim(0,-200)        # 200 frames
ShowFrameNumber
##############
FILE="D:\IMWR\MyFile_"
TYPE = "jpeg"
START=100
END=103                        # EDIT: Cannot use 0 here to mean last frame, must use actual end frame number
INFO=False
##############
COUNT=(END-START+1)

Trim(START,-COUNT)             # COUNT frames 0->3, , original numbers 100 -> 103

For(i=0,COUNT-1) {
    current_frame=i                                                 # kludge to make Imagewriter work (pretend in runtime environment)
    k=ImageWriter(File=FILE,Start=i,end=i,type=TYPE,info=INFO)      # Output MyFile_000000.jpeg -> MyFile_000003.jpeg
    k.ConvertToY8.Averageluma                                       # Kludge to force write files (ImageWriter only writes frame when frame is requested from the ImageWriter result clip)
    # OR MAYBE a bit quicker
    # k.crop(0,0,4,4).ConvertToY8.Averageluma
}

Return MessageClip("All Done, "+String(COUNT)+" Frames Written")
Oops, fixed filename comment.
EDIT: The AverageLuma forces a frame fetch of the result current_frame frame of ImageWriter, AverageLuma requires Luma so convertToY8 just to allow Averageluma to work for eg RGB.
__________________
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; 1st May 2020 at 22:49.
StainlessS is offline   Reply With Quote
Old 6th May 2020, 20:12   #6  |  Link
Georgiana
Registered User
 
Join Date: Apr 2020
Posts: 4
Dear Gavino and StainlessS, thank you very much for all your time and help! Your answers helped me a lot to better understand how to work with ImageWriter from AviSynth! So thank you again!
Georgiana is offline   Reply With Quote
Reply

Tags
clip, for-loop, image, imagewriter, jpg image decoding

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 23:20.


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