1
$\begingroup$

I want to import multiple movie files via script and add an offset to each file. What I came up with so far returns an error:

"Python script fail, look in the console for now" but there is nothing in the console.

import os, bpy, sys    
from bpy import context
scene = context.scene

path = "/Volumes/Temp/Grau_Benjamin/VIDEO/STab_Kippe_Einzelbilder"

files = os.listdir(path)
files.sort()

file_start_increase = 12
end = 5
i = 0 # count variable


# create the sequencer data

scene.sequence_editor_create()

while i <= end :

    starta = i * 48 + i * file_start_increase

    print (frame_range_back_start)

    bpy.ops.sequencer.movie_strip_add(
                filepath=os.path.join(path, files[i]),
                channel=i + 1, frame_start=starta)

    i += 1

Thank you!

$\endgroup$
  • $\begingroup$ Related IMO it's far easier to add strips using API methods. $\endgroup$ – batFINGER Jun 24 '18 at 16:45
  • $\begingroup$ You mean strips as in image strips? I have a folder of 72 datamoshed avi files. I thought to import them directly would be a huge timesaver. $\endgroup$ – Benni Jun 24 '18 at 16:48
  • $\begingroup$ I mean strips as in sequencer strips, click the manual link above. This one new_movie(...) looks promising. Replace the operator in your code with it. If error persists edit error into your question. (copy text from system console) $\endgroup$ – batFINGER Jun 24 '18 at 16:58
  • $\begingroup$ looks really good, but how do I implement it? Sorry I'm really bad at this, I just try to find and copy code. py.types.sequences.new_movie("test", filepath=os.path.join(path, files[i]), channel=i + 1, frame_start=starta) If I do it like this I get still an error message. $\endgroup$ – Benni Jun 24 '18 at 17:02
  • $\begingroup$ Related $\endgroup$ – batFINGER Jun 24 '18 at 17:06
1
$\begingroup$

Glob all movie files in a folder

Below is a script to glob all movie files in a given folder, and add them to the VSE as movie strips using Sequencer.new_movie an offset of 12 is added to start frame of each. Edit to suit.

Note the use of bpy.path.extensions_movie Blender's list of movie types it can open. For my blender

>>> bpy.path.extensions_movie
frozenset({'.mpg2', '.mov', '.avi', '.vob', '.flc', '.mpeg', '.movie',
 '.avs', '.xvid', '.webm', '.mv', '.ogg', '.r3d', '.dv', '.mp4',
 '.flv', '.m2ts', '.mts', '.wmv', '.mpg', '.divx', '.ogv', '.mxf',
 '.mkv', '.m2t', '.m4v', '.ts', '.m2v'})

The script.

import bpy
import os, glob

# glob all movie files from
vid_dir = "/home/batfinger/Videos"
exts = bpy.path.extensions_movie
files = [f for ext in exts for f in glob.glob(os.path.join(vid_dir, "*%s" % ext))]
files.sort()

# get sequence editor
scene = bpy.context.scene
scene.sequence_editor_create()
seq = scene.sequence_editor.sequences

# add movie strips
for i, fp in enumerate(files):
    frame_start = i * 12 # some offset 
    name = os.path.basename(fp)
    ms = seq.new_movie(
            name=name,
            filepath=fp,
            channel=i,
            frame_start=frame_start
            )
    # print some details
    print("%s ch: %d fs: %3.1f len: %d" %
            (name, i, frame_start, ms.frame_final_duration)
            )

StackOverflow

Script in question had simple python errors, in that you were trying to print an undefined variable. How to view python error messages?

For python questions like finding all files in a folder, or sorting lists strongly recommend searching on StackOverflow via google. Eg this search

site:stackoverflow.com python list all files in folder
$\endgroup$
  • $\begingroup$ Thank you! Now the import is working. The files are out of order though. How do I fix that? $\endgroup$ – Benni Jun 25 '18 at 7:40

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.