0
$\begingroup$

Is it possible to show the Filename of the current frame of a Image-Strip in the VSE as overlay text?

$\endgroup$

1 Answer 1

1
$\begingroup$

concept based on How can I make dynamic text in an animation? i came along with this script:

# based on https://blender.stackexchange.com/a/8087/16634

import bpy

#debug helper
print("all vse strips:", end="\n  ")
print(*bpy.context.scene.sequence_editor.sequences, sep="\n  ")

# output VSE Text strip:
text_overlay = bpy.context.scene.sequence_editor.sequences["Text"]

def get_combined_speed_factor(strip):
    # this does not handle all possible configuration options!
    # only 
    # - Stretch to input strip length
    # - Speed factor 
    # - Multiply Speed
    # are handled.
    combined_speed_factor = 1.0
    if strip.use_default_fade:
        # update / overwrite not used speed_factor value.
        orig = strip.input_1
        strip.speed_factor = orig.frame_duration / orig.frame_final_duration 
    # calculate
    combined_speed_factor = strip.speed_factor
    combined_speed_factor *= strip.multiply_speed
    return combined_speed_factor


def get_speed_factor_for_strip(scene, strip):
    strips_all = scene.sequence_editor.sequences
    strips_speed = (i for i in strips_all if i.type == 'SPEED')
    effects_for_strip = (i for i in strips_speed if i.input_1 == strip)
    combined_speed_factor = 1.0
    # this should calculate the overall speed for this input strip
    for effect_strip in effects_for_strip:
        combined_speed_factor *= get_combined_speed_factor(effect_strip)
    return combined_speed_factor


def find_current_img_filename(scene):
    frame_current = scene.frame_current
    file_name = None
    strips_all_sorted = list(sorted(scene.sequence_editor.sequences, 
        key=lambda x: x.frame_final_start))
    strips_image = (i for i in strips_all_sorted if i.type == 'IMAGE')
    strips_speed = (i for i in strips_all_sorted if i.type == 'SPEED')
    for strip in strips_image:
        strip_speed_factor = get_speed_factor_for_strip(scene, strip)
        if strip.frame_final_start <= frame_current < strip.frame_final_end:
            strip_frame = (
                (frame_current - strip.frame_final_start) 
                * strip_speed_factor
            ) + strip.frame_final_start
            file_name = strip.strip_elem_from_frame(strip_frame).filename
    return file_name


def recalculate_text(scene):
    filename = find_current_img_filename(scene)
    #print("filename", filename)
    text_new = "-"
    if (filename):
        text_new = filename.replace(".png", "")
    text_overlay.text = text_new


bpy.app.handlers.frame_change_pre.clear()
bpy.app.handlers.frame_change_pre.append(recalculate_text)
bpy.app.handlers.render_pre.clear()
bpy.app.handlers.render_pre.append(recalculate_text)

now this also works with Speed-Control Effects applied: blender example screenshot

if you experiment with the script use bpy.app.handlers.***.clear() to remove the old handler functions. (be careful - if you have other scripts or addons that use this callback they also get removed..)

$\endgroup$
2
  • $\begingroup$ if you answer your own question please mark the question as answered so that it show that it has already been answered. $\endgroup$
    – Syler
    May 15, 2019 at 6:29
  • $\begingroup$ done. (it was not allowed to do this for the first ~n days...) $\endgroup$ May 19, 2019 at 6:43

You must log in to answer this question.

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