1
$\begingroup$

After removing the audio part of a video strip, is there a way to bring it back (other than Ctrl+Z or manually re-importing and re-cutting the video)?

For example, in Kdenlive, you can right-click on a strip and click on "Restore audio".

$\endgroup$
1
  • $\begingroup$ Kdenlive might be an example where this is possible, but there is lot of NLE software where it is not. In Blender it is not possible. And after all it is foremost a 3D modeling software. Many dedicated video and audio editing softwares have some kind of media pool where you can append media files which in many editors is the only way to get the audio back by dragging it back in, Blender does not have such thing as a media pool and therefore you have to add the whole thing again. It is always best practice to simply not delete the audio (in Blender and other software) but instead mute it. $\endgroup$ Commented Aug 12 at 10:58

1 Answer 1

1
$\begingroup$

It is possible to do using Python.

As a standalone script to run from the text editor or used in the Toolshelf addon (success and error messages will be posted in Blender's console):

import bpy

if (video_strip := bpy.context.scene.sequence_editor.active_strip):
    # Check if the strip is a video strip
    if video_strip.type == 'MOVIE':
        movie_file = video_strip.filepath
        movie_name = video_strip.name
        start_frame = video_strip.frame_start
        final_duration = video_strip.frame_final_duration
        start_offset = video_strip.frame_offset_start
        end_offset = video_strip.frame_offset_end

        # Create a new sound strip using the same data block
        sound_strip = bpy.context.scene.sequence_editor.sequences.new_sound(
            name=f"{movie_name} Audio",
            filepath=movie_file,
            channel=video_strip.channel + 1,
            frame_start=int(start_frame)
        )
        sound_strip.frame_final_duration = final_duration
        sound_strip.frame_offset_start = start_offset
        sound_strip.frame_offset_end = end_offset

        print("Audio strip successfully recovered.")

    else:
        print("Selected strip is not a video strip.")
else:
    print("Please select a video strip.")

Or as an operator under the sequencer's strip menu:

import bpy

class sequencer_OT_audio_from_video(bpy.types.Operator):
    """Recreates audio strip from selected video strip"""
    bl_idname = "sequencer.simple_operator"
    bl_label = "Audio from Video strip"

    @classmethod
    def poll(cls, context):
        if context.scene.sequence_editor.active_strip == None:
            cls.poll_message_set("Please select a video strip.")
        return context.scene.sequence_editor.active_strip

    def execute(self, context):
        video_strip = bpy.context.scene.sequence_editor.active_strip
        # Check if the strip is a video strip
        if video_strip.type == 'MOVIE':
            movie_file = video_strip.filepath
            movie_name = video_strip.name
            start_frame = video_strip.frame_start
            final_duration = video_strip.frame_final_duration
            start_offset = video_strip.frame_offset_start
            end_offset = video_strip.frame_offset_end

            # Create a new sound strip using the same data block
            sound_strip = bpy.context.scene.sequence_editor.sequences.new_sound(
                name=f"{movie_name} Audio",
                filepath=movie_file,
                channel=video_strip.channel + 1,
                frame_start=int(start_frame)
            )
            sound_strip.frame_final_duration = final_duration
            sound_strip.frame_offset_start = start_offset
            sound_strip.frame_offset_end = end_offset

            self.report({"INFO"}, "Audio strip successfully recovered.")

        else:
            self.report({"WARNING"}, "Selected strip is not a video strip.")
        return {'FINISHED'}


def menu_func(self, context):
    self.layout.operator(sequencer_OT_audio_from_video.bl_idname, text=sequencer_OT_audio_from_video.bl_label)

def register():
    bpy.utils.register_class(sequencer_OT_audio_from_video)
    bpy.types.SEQUENCER_MT_strip.append(menu_func)


def unregister():
    bpy.utils.unregister_class(sequencer_OT_audio_from_video)
    bpy.types.SEQUENCER_MT_strip.remove(menu_func)


if __name__ == "__main__":
    register()

It will have a proper GUI. And you can save it in your Blender user directory/script/startup to always have it registered when Blender starts. But it will ask permission to be executed.

$\endgroup$
1
  • 1
    $\begingroup$ Thanks! I was hoping there was a native feature but that does the trick. There was just a little quirk in the code where the imported audio wouldn't be cut on the left side, so I fixed it. $\endgroup$ Commented Aug 12 at 21:38

You must log in to answer this question.

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