Skip to content

Instantly share code, notes, and snippets.

@tin2tin
Last active August 17, 2019 12:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tin2tin/1eabb233bce24e78d2edf35cb5a435c8 to your computer and use it in GitHub Desktop.
Save tin2tin/1eabb233bce24e78d2edf35cb5a435c8 to your computer and use it in GitHub Desktop.
Add frame count numbers as subtitles to the sequencer within the preview range - in Blender.
# Run script to add frame count numbers as subtitles to the sequencer within the preview range
import bpy
def find_empty_channel():
"""
Finds the first empty channel above all others in the VSE
and returns it
"""
sequences = bpy.context.sequences
if not sequences:
return 1
channels = [s.channel for s in sequences]
channels = sorted(list(set(channels)))
return channels[-1] + 1
def subtitles_to_sequencer(context):
"""Add frame number subtitles to the video sequencer"""
scene = context.scene
fps = scene.render.fps / scene.render.fps_base
open_channel = find_empty_channel()
if not scene.sequence_editor:
scene.sequence_editor_create()
wm = context.window_manager
wm.progress_begin(0, 100.0)
added_strips = []
fr_start=bpy.context.scene.frame_start
fr_end=bpy.context.scene.frame_end
bpy.ops.sequencer.select_all(action='DESELECT') # only have the new strips selected
for i in range(fr_start,fr_end+1):
start_time = i
strip_start = i
end_time = i+1
strip_end = i+1
sub_name = str(i)
text_strip = scene.sequence_editor.sequences.new_effect(
name=sub_name,
type='TEXT',
channel=open_channel,
frame_start=strip_start,
frame_end=strip_end
)
print(str(open_channel)+":"+str(strip_start))
text_strip.font_size = int(bpy.context.scene.render.resolution_y/13) # Change the subtitle size here
text_strip.text = str(bpy.utils.smpte_from_frame(i))
text_strip.use_shadow = True
text_strip.select = True
text_strip.location[1] = 0.85
text_strip.blend_type = 'ALPHA_OVER'
added_strips.append(text_strip)
bpy.ops.sequencer.meta_make() # make meta strip
bpy.context.scene.sequence_editor.active_strip.name = "Frame Numbers"
my_meta=bpy.context.scene.sequence_editor.active_strip.name
for scene in bpy.data.scenes:
scene.sequence_editor.sequences_all[my_meta].blend_type = "ALPHA_OVER"
return added_strips
subtitles_to_sequencer(bpy.context)
@tin2tin
Copy link
Author

tin2tin commented Aug 16, 2019

Changed to SMPTE and moved it to the top.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment