Skip to content

Instantly share code, notes, and snippets.

View HaydenFaulkner's full-sized avatar

Dr Hayden Faulkner HaydenFaulkner

View GitHub Profile
@HaydenFaulkner
HaydenFaulkner / video_to_frames_decord.py
Created July 15, 2020 01:09
decord version of video_to_frame.py
import cv2 # still used to save images out
import os
import numpy as np
from decord import VideoReader
from decord import cpu, gpu
def extract_frames(video_path, frames_dir, overwrite=False, start=-1, end=-1, every=1):
"""
Extract frames from a video using decord's VideoReader
@HaydenFaulkner
HaydenFaulkner / frames_to_video.py
Last active August 16, 2019 13:20
Function for taking a directory of images and turning it into a video
import cv2
import glob
import os
from tqdm import tqdm
def frames_to_video(frames_dir, video_path, fps=30):
"""
Generates a .mp4 video from a directory of frames
:param frames_dir: the directory containing the frames, note that this and any subdirs be looked through recursively
@HaydenFaulkner
HaydenFaulkner / video_to_frames.py
Last active March 19, 2024 16:37
Fast frame extraction from videos using Python and OpenCV
from concurrent.futures import ProcessPoolExecutor, as_completed
import cv2
import multiprocessing
import os
import sys
def print_progress(iteration, total, prefix='', suffix='', decimals=3, bar_length=100):
"""
Call in a loop to create standard out progress bar
@HaydenFaulkner
HaydenFaulkner / extract_frames.py
Last active December 24, 2021 17:49
Extract frames from a video using Python and OpenCV
import cv2
import os
def extract_frames(video_path, frames_dir, overwrite=False, start=-1, end=-1, every=1):
"""
Extract frames from a video using OpenCVs VideoCapture
:param video_path: path of the video
:param frames_dir: the directory to save the frames
:param overwrite: to overwrite frames that already exist?