Created
April 27, 2021 07:43
-
-
Save artturijalli/44b0e5b2d2372f41223b59d377eea929 to your computer and use it in GitHub Desktop.
Convert video to gif with 3 lines of code. Install Tkinter with brew install python-tk. Install moviepy with pip install moviepy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from moviepy.editor import VideoFileClip | |
from tkinter.filedialog import * | |
import os | |
# Accept only .mov and .mp4 files. Feel free to change. | |
accepted_files = [("Mov files", "*.mov"), ("MP4 files", "*.mp4")] | |
# Select a video which is one of the accepted file types from your machine | |
video_file = askopenfilename(filetypes=accepted_files) | |
# Create a video clip instance | |
clip = VideoFileClip(video_file) | |
# Get the video file name. E.g. 'path/to/video.mov' --> 'video.mov' | |
video_file_name = os.path.basename(video_file) | |
# Split video name to parts. E.g. 'video.mov' --> ('video', 'mov') | |
parts = os.path.splitext(video_file_name) | |
# Get the name of the video from the parts and add a .gif to the end. | |
gif_name = parts[0] + ".gif" | |
# Create a gif with the same name as the original video. | |
clip.write_gif(gif_name, fps=10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment