-2
$\begingroup$

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!")
$\endgroup$
6
  • 3
    $\begingroup$ Hello and welcome to ChatGPT... I mean BSE :) "I write this code" > I asked ChatGPT and it said that it was most likely GPT generated. It seems you want us to fix what it generated? $\endgroup$
    – Harry McKenzie
    Commented Apr 14 at 10:19
  • $\begingroup$ Yes you got it right as I do not know python. I just want to get this code fixed. $\endgroup$
    – Jatin
    Commented Apr 14 at 10:23
  • $\begingroup$ What are the "alternate frames"? From the code it is the even frames. Do you want to edit bpy.types.ImageSequence.elements? $\endgroup$
    – unwave
    Commented Apr 14 at 11:52
  • 1
    $\begingroup$ @unwave he cant answer that due to having no python experience. just fix the code thats what he wants. $\endgroup$
    – Harry McKenzie
    Commented Apr 14 at 15:36
  • $\begingroup$ AFAIK There is no such thing as "remove frames from a strip" in Blender. You could cut the strip at each frame and remove odd ones. Which has the advantage of working with the audio strip, but I reckon to be wasteful and tedious ressource-wise. A simpler way would be to use ffmpeg to export your video as an image sequence and delete odd ones using python. But that's off topic here. $\endgroup$
    – Lauloque
    Commented Apr 14 at 16:03

1 Answer 1

0
$\begingroup$
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)
        

Note: you should be honest - not only here, that makes things easier. And i am pretty sure that's why nobody answered you - and that's why you did get 3 downvotes (until now). Nevertheless - i believe people can learn from mistakes - that's why i do answer.

result demo:

https://github.com/luckychris/blender_gifs/blob/main/delete%20partial%20strips%20demo.gif

enter image description here

Note2: once there was a great feature in SE: gif upload. This enriched this community a lot because you could show e.g. working examples or results. Unfortunately SE "killed" that by their latest "upgrade" which i think is more a downgrade. But that's just my personal opinion.

$\endgroup$
11
  • $\begingroup$ @Leander: i have no idea why you think you have to undelete my deleted post!? $\endgroup$
    – Chris
    Commented Apr 15 at 5:38
  • 1
    $\begingroup$ I think the "downgrade" was done for good reason snipboard.io/bAdi2h.jpg You can still upload up to 2mb gif files. $\endgroup$
    – Harry McKenzie
    Commented Apr 15 at 6:36
  • 1
    $\begingroup$ @Chris Huh, I didn't undelete your post? I only rolled back the edit that obfuscated the actual post. By all means leave your post deleted. $\endgroup$
    – Leander
    Commented Apr 15 at 6:44
  • 2
    $\begingroup$ sorry, i didn't make myself clear. You cannot undelete it - that's right. By why did you roll it back? i had reasons why i did make "points" there, or how you call it "obfuscate". It was deleted anyway, so just a few people could see it. So i don't get it... i would prefer if you don't change my deleted answers. thx for your understanding. $\endgroup$
    – Chris
    Commented Apr 15 at 8:09
  • 1
    $\begingroup$ Thanks you Chris. I was expecting the same output. Thanks Again $\endgroup$
    – Jatin
    Commented Apr 15 at 8:49

You must log in to answer this question.

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