from moviepy.editor import VideoFileClip
def speed_up_video(input_video_path, output_video_path, speed_factor=2):
# Load the video file
= VideoFileClip(input_video_path)
video_clip
# Speed up the video
= video_clip.speedx(factor=speed_factor)
new_clip
# Write the resulting video to the output file
='libx264', audio_codec='aac')
new_clip.write_videofile(output_video_path, codec
= 'demo.mov'
input_video_path = 'demo_2x.mov'
output_video_path 2) speed_up_video(input_video_path, output_video_path,
Video capture and processing
To grab a video on MacOS use Command + Shift + 5
.
To refer to the video in markdown like README.md use this (btw GitHub automatically embeds video):
![description](demo.mov)
pip install moviepy
Speed up video
Convert to gif
from moviepy.editor import VideoFileClip
def convert_mov_to_gif(source_file, target_file, frame_subsampling=1, start_time=None, end_time=None, resize=None):
# Load the source video file
= VideoFileClip(source_file) # .subclip(start_time, end_time)
clip
# Optionally resize the clip if resize dimensions are provided
if resize:
= clip.resize(resize)
clip
if frame_subsampling > 1:
= clip.set_fps(clip.fps / frame_subsampling)
clip
# Write the result to a gif file
clip.write_gif(target_file)
# Usage
'/Users/nenadbozinovic/Desktop/demo_extracted_data.mov', '/Users/nenadbozinovic/Desktop/demo_extracted_data_2.gif', frame_subsampling=20) # , resize=(320, 240)) convert_mov_to_gif(
MoviePy - Building file /Users/nenadbozinovic/Desktop/demo_extracted_data_2.gif with imageio.