Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Trying to finish a PhD

Hayden Faulkner HaydenFaulkner

💭
Trying to finish a PhD
  • The Australian Institute for Machine Learning, The University of Adelaide
  • Adelaide, South Australia
View GitHub Profile
@HaydenFaulkner
HaydenFaulkner / video_to_frames_decord.py
Created Jul 15, 2020
decord version of video_to_frame.py
View video_to_frames_decord.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 Aug 16, 2019
Function for taking a directory of images and turning it into a video
View frames_to_video.py
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 Jun 10, 2021
Fast frame extraction from videos using Python and OpenCV
View video_to_frames.py
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 Nov 19, 2020
Extract frames from a video using Python and OpenCV
View extract_frames.py
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?