Skip to content

Instantly share code, notes, and snippets.

@tin2tin
Created January 15, 2025 09:18
Show Gist options
  • Save tin2tin/f41815cadf76a9fbd1eec74bb6bfa3b7 to your computer and use it in GitHub Desktop.
Save tin2tin/f41815cadf76a9fbd1eec74bb6bfa3b7 to your computer and use it in GitHub Desktop.
Export a Frame for Each Shot
bl_info = {
"name": "Export a Frame for Each Shot",
"author": "tintwotin",
"version": (1, 0),
"blender": (3, 00, 0),
"location": "Strip > Export a Frame for Each Shot",
"description": "",
"warning": "",
"doc_url": "",
"category": "Sequencer",
}
import bpy, os
from bpy.types import Operator
from os import path
import re
def slugify(name):
return re.sub(r'[\W_]+', '-', name)
class OPERATOR_OT_export_a_frame_for_each_shot(Operator):
"""Convert selected strips to IDs"""
bl_idname = "sequencer.vse_export_a_frame_for_each_shot"
bl_label = "Export a Frame for Each Shot"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
filepath = bpy.data.filepath
base_dir = path.dirname(filepath)
scene = bpy.context.scene
strips = bpy.context.selected_editable_sequences
strips = sorted(strips, key=lambda strip: strip.frame_final_start)
original_out = scene.render.filepath
original_format = scene.render.image_settings.file_format
context.window_manager.progress_begin(0, len(strips))
org_path = scene.render.filepath
for i, sq in enumerate(strips):
if sq.type == "IMAGE":
out_path = f'C://tmp/{slugify(scene.name)}/frames/{sq.frame_final_start:06d}_{slugify(sq.name)}.jpg'
scene.render.filepath = out_path
scene.render.image_settings.file_format = 'JPEG'
scene.frame_current = sq.frame_final_start
bpy.ops.render.render(write_still=True, scene=scene.name)
scene.render.filepath = org_path
return {"FINISHED"}
def menu_append(self, context):
layout = self.layout
layout.separator()
layout.operator(OPERATOR_OT_export_a_frame_for_each_shot.bl_idname)
def register():
bpy.utils.register_class(OPERATOR_OT_export_a_frame_for_each_shot)
bpy.types.SEQUENCER_MT_strip.append(menu_append)
def unregister():
bpy.utils.unregister_class(OPERATOR_OT_export_a_frame_for_each_shot)
bpy.types.SEQUENCER_MT_strip.remove(menu_append)
if __name__ == "__main__":
register()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment