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)

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

# create the sequencer data


while i <= end :

    starta = i * 48 + i * file_start_increase

    print (frame_range_back_start)

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

    i += 1

Thank you!

  • $\begingroup$ Related IMO it's far easier to add strips using API methods. $\endgroup$
    – batFINGER
    Commented Jun 24, 2018 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
    Commented Jun 24, 2018 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
    Commented Jun 24, 2018 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
    Commented Jun 24, 2018 at 17:02
  • $\begingroup$ Related $\endgroup$
    – batFINGER
    Commented Jun 24, 2018 at 17:06

1 Answer 1


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))]

# get sequence editor
scene = bpy.context.scene
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(
    # print some details
    print("%s ch: %d fs: %3.1f len: %d" %
            (name, i, frame_start, ms.frame_final_duration)


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
  • $\begingroup$ Thank you! Now the import is working. The files are out of order though. How do I fix that? $\endgroup$
    – Benni
    Commented Jun 25, 2018 at 7:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .