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. |
![]() |
#1 | Link |
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! |
![]() |
![]() |
![]() |
#2 | Link |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,437
|
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") |
![]() |
![]() |
![]() |
#3 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,078
|
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 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 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") 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. |
![]() |
![]() |
![]() |
#5 | Link | ||
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,078
|
Quote:
Quote:
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") 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. |
||
![]() |
![]() |
![]() |
Tags |
clip, for-loop, image, imagewriter, jpg image decoding |
Thread Tools | Search this Thread |
Display Modes | |
|
|