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
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$