Skip to content

Instantly share code, notes, and snippets.

@Abhayparashar31
Created December 16, 2024 04:56
Show Gist options
  • Save Abhayparashar31/70bb4c515d8642ab2281188eb1694ac1 to your computer and use it in GitHub Desktop.
Save Abhayparashar31/70bb4c515d8642ab2281188eb1694ac1 to your computer and use it in GitHub Desktop.
from moviepy.editor import VideoFileClip
def convert_video_to_gif(video_path, gif_path, start_time=0, duration=None):
# Load video clip
clip = VideoFileClip(video_path)
# Duration for GIF, if not specified use whole video
if duration:
clip = clip.subclip(start_time, start_time + duration)
else:
clip = clip.subclip(start_time, clip.duration)
# Write the clipped video as GIF
clip.write_gif(gif_path)
print(f"GIF saved to {gif_path}")
video_path = "Sample_Video.mp4" # Path to your video file
gif_path = "output.gif" # Path where the gif will be saved
convert_video_to_gif(video_path, gif_path, start_time=0, duration=15)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment