from moviepy.editor import VideoFileClip, concatenatevideoclips Load the source video…
- User
from moviepy.editor import VideoFileClip, concatenate_videoclips
Load the source video
input_path = "source_video.mp4" # Replace with your video file path output_path = "stutter_loop_video_no_audio.mp4" # Desired output path
clip = VideoFileClip(input_path)
Define stutter segments (start, end) in seconds
segments = [(5, 6), (10, 10.5), (15, 15.2), (20, 20.2), (25, 25.5), (30, 31), (35, 36), (40, 40.5), (45, 45.2), (50, 50.2), (55, 55.5), (60, 61), (65, 66), (70, 70.5), (75, 75.2), (80, 80.2), (85, 85.5), (90, 91), (95, 96), (100, 100.5), (105, 105.2), (110, 110.2), (115, 115.5), (120, 121), (125, 126), (130, 130.5), (135, 135.2), (140, 140.2), (145, 145.5), (150, 151), (155, 156), (160, 160.5), (165, 165.2), (170, 170.2), (175, 175.5), (180, 181), (185, 186), (190, 190.5), (195, 195.2), (200, 200.2), (205, 205.5), (210, 211), (215, 216), (220, 220.5), (225, 225.2), (230, 230.2), (235, 235.5), (240, 241), (245, 246), (250, 250.5), (255, 255.2), (260, 260.2), (265, 265.5), (270, 271), (275, 276), (280, 280.5), (285, 285.2), (290, 290.2), (295, 295.5), (300, 301), (305, 306), (310, 310.5), (315, 315.2), (320, 320.2), (325, 325.5), (330, 331), (335, 336), (340, 340.5), (345, 345.2), (350, 350.2), (355, 355.5), (360, 361), (365, 366), (370, 370.5), (375, 375.2), (380, 380.2), (385, 385.5), (390, 391), (395, 396), (400, 400.5), (405, 405.2), (410, 410.2), (415, 415.5), (420, 421), (425, 426), (430, 430.5), (435, 435.2), (440, 440.2), (445, 445.5), (450, 451), (455, 456), (460, 460.5), (465, 465.2), (470, 470.2), (475, 475.5), (480, 481)] # Example stutter points
Generate stutter loops
stutter_clips = [] for start, end in segments: segment = clip.subclip(start, end) # Extract segment stutter_clip = segment.loop(n=5) # Repeat 5 times stutter_clips.append(stutter_clip)
Add other parts of the video (optional)
intro = clip.subclip(0, 5) # Video before stutter starts outro = clip.subclip(481, clip.duration) # Video after stutters
Combine all clips
final_clip = concatenate_videoclips([intro] + stutter_clips + [outro])
Remove audio from the final clip
final_clip = final_clip.without_audio()
Export final video with reduced settings for 1 MB file size
final_clip.write_videofile( output_path, codec="libx264", bitrate="500k", # Reduce bitrate fps=60, # Lower frame rate preset="ultrafast", # Use ultrafast preset for faster encoding ffmpeg_params=["-vf", "scale=1280:720"] # Reduce resolution to 320x240 ) duration 481 seconds
- Assistant