Log in

View Full Version : Scripted frame multiplication with individual factor per frame?


LigH
6th June 2013, 09:44
Question from the german board (http://forum.gleitz.info/showthread.php?46403-jeden-Frame-unterschiedlich-vervielfachen): Is it possible to have AviSynth read a list of frame numbers and multiplication factors, and loop each frame a different number of times?

The requested loop counts are not regular like in pulldown functions. We already guessed that an internal "conditional function" (like ScriptClip) may not be able, due to the repetitive change of the clip length. And SelectEvery may run into an internal limit of function parameters.

An external "trivial" solution would be the scripted generation of a huge AviSynth script using loops in a descending order (first loop the last frame...). But the disadvantage will be the huge result.

Is there already a plugin which would support this feature? If not, I believe a new plugin may be appreciated which is able to read a list with a syntax like switch-cases:

{frame_number|default}: loop_count

creaothceann
6th June 2013, 11:42
It should be possible to loop frames with this Loop function:
(i = frame index, t = times to loop)

function Loop(clip c, int i, int t) {
c
p1 = (i == 0) ? Trim(0, -1).DeleteFrame(0) : Trim(0, i-1)
p2 = Trim(i, -1).Repeat(t)
p3 = (i == FrameCount-1) ? Trim(0, -1).DeleteFrame(0) : Trim(i+1, 0)
p1 + p2 + p3
(c.HasAudio) ? last.AudioDub(c) : last
}


function Repeat(clip c, int t) {
(t <= 1) ? c : c + Repeat(c, t-1)
}

LigH
6th June 2013, 12:00
The AviSynth kernel already provides a Loop() function. That's not the point of the problem. The question is how to repeat

all frames: 2 times, except
frame 1: 5 times;
frame 3: 4 times;
frame 7: 0 times;
...
for hundreds of different times per frame number. To simplify this issue, I believe there is no audio handling required.

StainlessS
6th June 2013, 12:04
What is the source of the command file, human or machine generated ?

Are the frame numbers always sequential ?

EDIT: If machine generated, then probably easier to modify the script to generate command file for original
FrameSelect plugin.

LigH
6th June 2013, 12:09
The explanation by the thread starter is rather brief; it looks like the file could have been machine generated, and may not have to be related to videos specifically?

StainlessS
6th June 2013, 12:14
See previous edit:

Simply generating a frame number for each and every frame would do it, can you inquire what the generator is,
and if Avisynth script, provide source.
FrameSelect should be able to read about 40,000 commands a second and so file length should not really be a problem.

Maybe its just a case of the guy writing a generator for Conditional Reader and then finding out it dont work,
better to generate for something that does work rather than writing a plugin to fit the wrong output.

LigH
6th June 2013, 12:28
Looks great. Means, the example above could be implemented using a call clip.FrameSelect(cmd="frames.lst") with the file frames.lst containing one frame number per line like (CRLF substituted by semicola):

0;0;1;1;1;1;1;2;2;3;3;3;3;4;4;5;5;6;6;8;8;9;9...

I'll ask how the ist was generated and if it can be generated compatible to FrameSelect.

StainlessS
6th June 2013, 12:36
Looks good to me :)

EDIT: By the way, that is exactly what FrameSelect was written for, frame ranges were an afterthought.

If generator can be modified, then FrameSelect should fly like the wind after initial plugin initialization
(reading file), would be equivalent to about 1 trim() filter and a lot faster than a scripted solution.

StainlessS
7th June 2013, 09:00
LigH,

If mod to FrameSelect format is not easy, I could hack a version to take eg


0 2 # frame 0 x 2
1 5 # frame 1 x 5
2 2
3 4
4 2
5 2
6 2
8 2
9 0 # no frame 9, not necessary, would be skipped anyway if missed from cmd file
10 # same as 10 x 1


Let me know if preferable, maybe I'll call it RepeatFrames() or similar (unless you've got a better name).
I would remove frame ranges from plug, and maybe also remove direct frame number args and command string options,
just leaving command file (would be easiest hack).

LigH
7th June 2013, 09:07
:thanks: in advance!

I will tell you as soon as the user with the problem will reply again; sometimes it takes weeks until people remember having asked... ;)

In the meantime, please consider if this plugin would also make use of a default repetition count for frames not explicitly listed in the file, e.g. as additional parameter with default value 0.

StainlessS
7th June 2013, 09:29
OK.
Originally was intended as frame selection with reduction in output framecount and also output not necessarily sequential with input.
I guess I could change it as suggested but output would have to be sequential with input (but with duplicates).

Anyway let me know when other guy comes back with an answer.

StainlessS
7th June 2013, 13:00
Abracadabra

FrameRepeat() v1.00
EDIT: Link removed, see new thread here:
http://forum.doom9.org/showthread.php?p=1632538#post1632538


FrameRepeat() v1.00, Plugin for Avisynth v2.5 & v2.6 by StainlessS.

FrameRepeat() is a simple plugin to select frames to repeat.

v2.6 plugin only required for Show and Ver arguments to display info on frame in Avisynth v2.6+ colorspaces.

Video:- Planar, YUY2, RGB32, RGB24.

Audio:- Returns NO AUDIO.


FrameRepeat(Clip,int 'default',string 'Cmd', bool 'Show', bool 'Ver')

Compulsory args:

Clip, No Default, source clip.

Optional args:

default, int, default=0. The default repeat count for frames not mentioned in command file.
Default =0, is, frames not mentioned in Cmd command file are excluded (repeated 0 times, ie not output at all).

Cmd, string, Default= "", Not set.
Command file, frame numbers supplied in a file. Use eg "Repeat.txt" for command file in your script directory.

Show bool, Default= false.
true = Show info.

ver bool, Default=false.
true = Show version.


The 'Cmd' Command file allows one command per line and can contain comments eg:

#------------- # below contents of a text file eg "Repeat.txt".
1 1 # This is a comment. Output frame 1 once.
2 # Single frame number without a repeat count, outputs frame only once, equivalent to 2 1.
3,2 # Can also use ',' COMMA rather than SPACE as a number separator. Outputs frame 3 twice.
5,3 # Output frame 5, 3 times.
#-------------

Given a 6 frame clip (frames 0 -> 5)

FrameRepeat(clip,default=0,cmd="Repeat.txt") # would produce this sequence "1,2,3,3,5,5,5".

FrameRepeat(clip,default=1,cmd="Repeat.txt") # would produce this sequence "0,1,2,3,3,4,5,5,5".

FrameRepeat(clip,default=2,cmd="Repeat.txt") # would produce this sequence "0,0,1,2,3,3,4,4,5,5,5".

FrameRepeat(clip,default=3) # would produce this sequence "0,0,0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5".
# Note, above without a command file.

Where a frame number and repeat count is mentioned more than once in file, the last one will override earlier ones..
--------------------------------------
StainlessS.


EDIT: FrameRepeat(clip) will produce a "No frames to output" type error message as 'default' defaults to 0.