script for VSE to remove all gaps between strips?

Is there a script for VSE to automatically remove all gaps between selected strips?

For instance say you have a big movie strip and you cut out all the bits you dont want…
Youre left with <strip> <empty gap> <strip> <empty gap> …

It would be good to have a script which will remove all gaps and align the strips back to back.

Thanks.

I once made this nice small script, which also crossfades them. I didn’t convert it to a plugin yet, but it works quite nice.


import bpy
import itertools


def crossfade_movie_parts(movie_parts, overlap = 30):
    sequences = bpy.context.scene.sequence_editor.sequences
    crossfade_channel = movie_parts[0].channel + 2 #one for the even movies, one for the effects
    movie_parts = list(movie_parts)
    movie_parts.sort(key=lambda s: s.frame_final_start)
    for num, first_part, second_part in zip(itertools.count(), movie_parts, movie_parts[1:]):
        print('fading {} and {}'.format(first_part.name, second_part.name))
        channel_change = 1 if num % 2 == 0 else -1
        second_part.channel = first_part.channel + channel_change
        starting_frame = first_part.frame_final_end - overlap
        second_part.frame_start = starting_frame - second_part.frame_offset_start
        cross_fade = sequences.new_effect(
            name = 'cross_fade[{}]'.format(num),            
            type = 'GAMMA_CROSS',
            channel = crossfade_channel,
            seq1 = first_part,
            seq2 = second_part)
        cross_fade.update()
        
        
if __name__ == '__main__':
    crossfade_movie_parts(bpy.context.selected_sequences)

Due to a glitch in blender however, sometimes the duration of a crossfade does not show correctly, so you need to move one of the movie parts to update the crossfade.