Log in

View Full Version : newbie python questions


poisondeathray
6th February 2020, 00:44
1) If I have multiple clips, can I apply a command to them all at once ? eg. If I have clip with alpha [0] , and [1] for the alpha, and I want to trim the clip (including the alpha clip) - normally I can do something like this .

clip[0] = core.std.Trim(clip[0], first=10)
clip[1] = core.std.Trim(clip[1], first=10)

Is there a way to reference both clips[0 and 1] or something like that to combine them into 1 command or line?



2) Is there a simple python way to repeat multiple commands "n" times ?

eg. How would I simplify this applying StackHorizontal multiple times ?

s1 = core.std.StackHorizontal([a,b])
s1 = core.std.StackHorizontal([s1,s1])
s1 = core.std.StackHorizontal([s1,s1])
s1 = core.std.StackHorizontal([s1,s1])
s1 = core.std.StackHorizontal([s1,s1])


Thanks

WolframRhodium
6th February 2020, 02:34
1)

clips = [clip_1, clip_2] # store clips into a list

for i in range(len(clips)):
clips[i] = core.std.Trim(clips[i], first=10)

clip_1, clip_2 = clips # obtain the results


Or

clip_1, clip_2 = map(lambda clip: core.std.Trim(clip, first=10), [clip_1, clip_2])


2)
Any of the following with n = 4


s1 = core.std.StackHorizontal([a, b])

for _ in range(n):
s1 = core.std.StackHorizontal([s1, s1])



import vsutil # https://github.com/Irrational-Encoding-Wizardry/vsutil
s1 = core.std.StackHorizontal([a, b])

s1 = vsutil.iterate(s1, lambda clip: core.std.StackHorizontal([clip, clip]), n)



# case-specific implementation
s1 = core.std.StackHorizontal([a, b] * (2 ** n))

poisondeathray
6th February 2020, 03:17
Thanks WR;

That last one especially "feels" "pythony" . Very cool