Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Blender Markers to Subtitle Script
# Marker Subtitle Script For Blender
#
# Exports Blender Timecodes to a
# .txt or .srt file.
# 2015 Nathan Craddock
# Type the location here that you would like to save the file
# on windows devices make sure to double backslash \\ so python
# reads it as a \
# Example: "C:\\Users\\ExampleUser\\Desktop\\Folder\\name.srt"
export_location = "C:\\Users\\nzcra_000\\Desktop\\output.srt"
import bpy
def get_time_code(frame, fps):
return '{0:02d}:{1:02d}:{2:02d},{3:03d}'.format(int(frame / (3600*fps)), int(frame / (60*fps) % 60), int(frame / fps % 60), int(frame % fps))
fps = bpy.context.scene.render.fps
last_frame = bpy.context.scene.frame_end
markers = bpy.context.scene.timeline_markers
frames = {}
if markers:
for m in markers:
frames[m.name] = m.frame
s_titles = []
s_frame = []
for m in sorted(frames, key=frames.get):
s_titles.append(m)
s_frame.append(frames[m])
with open(export_location, 'w') as outfile:
for x in range(0, len(s_frame)):
tc = get_time_code(s_frame[x], fps)
if x is not len(s_frame) - 1:
tc_next = get_time_code(s_frame[x + 1], fps)
else:
tc_next = get_time_code(last_frame, fps)
subtitle = str(x + 1)
times = tc + " --> " + tc_next
title = s_titles[x]
# Write to subtitle file
outfile.write(subtitle + "\n")
outfile.write(times + "\n")
outfile.write(title + "\n")
outfile.write("\n")
print(x + 1)
print(tc, "-->", tc_next)
print(s_titles[x])
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.