0
$\begingroup$

My goal is to edit a video automatically, so that there are small parts reapeating in forward and backward motion with variable part lengths. The sequence of frames for part length 1 would be: 1 2 3 2 3 4 3 4 5 Part length 2: 1 2 3 2 1 2 3 4 3 2 3 4 5 A friend provided me with an array, which can generate this and other sequences.

#!/usr/bin/python
# coding: utf8
amplitude = 5 #Min 1  
end = 30 
drunkenArr = []
i = 0
while i <= end - amplitude + 1:
    for j in range(amplitude):
        drunkenArr.append(i + j)
    for j in range(amplitude)[::-1][1:-2]:
        drunkenArr.append(i + j)
    i = i + 1
print drunkenArr

There could be multiple ways: - Opening a video file on consecutive frames and setting frame start to this sequence. This one will be very slow I think. - Opening one video file and cut and copy the frames after a pattern - converting the video file to single images and putting them into a folder ( could be done by hand, but with a script it would be much more convenient) and importing them in the sequence of an array.

$\endgroup$
  • 1
    $\begingroup$ Mention to your friend blender uses python 3.6 $\endgroup$ – batFINGER May 20 '18 at 11:48
  • $\begingroup$ Also the VSE can perform a speed effect that will read frames forwards and backwards but not out of order. It will perform frame skipping if in excess of 100% speed $\endgroup$ – 3pointedit Jul 21 '18 at 3:30
1
$\begingroup$

Perhaps try this:

import os

from bpy import context
scene = context.scene

path = "C:/Users/Admin/Documents/Projects/VIDEO/atabilized/timelapse"
files = os.listdir(path)
files.sort()

# create the sequencer data
scene.sequence_editor_create()

seq = scene.sequence_editor.sequences.new_image(
    name="MyStrip",
    filepath=os.path.join(path, files[0]),
    channel=1, frame_start=1)

# add the images. forward and backwards
amplitude = 25
i=0
while i <= files.len() - amplitude:
    for f in files[i : i + amplitude]: #forward
        seq.elements.append(f)
    for f in files[i + 2 : i + amplitude - 1 ][::-1] #backwards
        seq.elements.append(f)
    i += 1
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.