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

from moviepy.editor import VideoFileClip

def speed_up_video(input_video_path, output_video_path, speed_factor=2):
    # Load the video file
    video_clip = VideoFileClip(input_video_path)
    
    # Speed up the video
    new_clip = video_clip.speedx(factor=speed_factor)
    
    # Write the resulting video to the output file
    new_clip.write_videofile(output_video_path, codec='libx264', audio_codec='aac')

input_video_path = 'demo.mov'
output_video_path = 'demo_2x.mov'
speed_up_video(input_video_path, output_video_path, 2)

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
    clip = VideoFileClip(source_file)  # .subclip(start_time, end_time)
    
    # Optionally resize the clip if resize dimensions are provided
    if resize:
        clip = clip.resize(resize)
    
    if frame_subsampling > 1:
        clip = clip.set_fps(clip.fps / frame_subsampling)
        
    # Write the result to a gif file
    clip.write_gif(target_file)

# Usage
convert_mov_to_gif('/Users/nenadbozinovic/Desktop/demo_extracted_data.mov', '/Users/nenadbozinovic/Desktop/demo_extracted_data_2.gif', frame_subsampling=20)  # , resize=(320, 240))
MoviePy - Building file /Users/nenadbozinovic/Desktop/demo_extracted_data_2.gif with imageio.