I want to remove alternate frames from video strip in blender in python

I write this code in blender to update the video strip so as to delete alternate frames from it and leave rest of the frames in video sequence editor but it removes first half of the strip instead of alternate frames. Please let me know where I am doing it wrong.

import bpy

# Set the name of your video strip
video_strip_name = "YourStripName"

# Get the video sequence editor
vse = bpy.context.scene.sequence_editor

# Find the video strip by name
strip = vse.sequences.get(video_strip_name)

if strip:
    # Create a new list to store the frames to be removed
    frames_to_remove = []

    # Iterate through the frames and identify alternate ones
    for frame in range(strip.frame_final_start, strip.frame_final_end + 1):
    if frame % 2 == 0:
        # Add the frame index to the list
        frames_to_remove.append(frame)

# Remove the identified frames from the beginning
for frame_index in frames_to_remove:
    strip.frame_final_start += 1
else:
    print(f"Video strip '{video_strip_name}' not found.")

    print("Alternate frames removed successfully from the beginning!")

Where exactly in your code do you expect the frames to be deleted? Using frame_final_start has nothing to do with deleting if I am not mistaken.

https://docs.blender.org/api/current/bpy.types.Sequence.html#bpy.types.Sequence.frame_final_start

Not sure if deleting individual frames is supported in a trivial way in the VSE. The only way I see right now would be cutting the video into many pieces (in your case every frame!) and removing the parts you want to get rid. But as you are looking for every second frame that will be a nightmare. For sure you could use Python for that (although I never tried).

BUT:
Did you ever think about using something like ffmpeg? There these things can be managed much easier. And then you just reimport the image sequence into the VSE. Quick Google gave me this:

import bpy

# Set the name of your video strip
video_strip_name = "maserati red fron dof high.001"

# Get the video sequence editor
vse = bpy.context.scene.sequence_editor

# Find the video strip by name
strip = vse.sequences.get(video_strip_name)


start = int(strip.frame_start)
duration = int(strip.frame_duration)
end = int(start + duration)

print("start", start)
print("end", end)
print("duration", duration)

counter = 0

for (cut) in range(start, end):
    
    if cut % 5 == 0:
        
        counter += 1
    
        print('cut', end-cut)
        
        new_strip = strip.split(frame=end-cut, split_method='HARD')
        
        if counter % 2 == 1 and new_strip != None:
            bpy.context.scene.sequence_editor.sequences.remove(new_strip)
            
        if counter % 2 == 1 and new_strip == None:
            bpy.context.scene.sequence_editor.sequences.remove(strip)
        
1 Like