Skip to content

Instantly share code, notes, and snippets.

@sizhky
Created July 24, 2020 05:05
Show Gist options
  • Save sizhky/a4f1e9a13f83a332ab862260c5c0281c to your computer and use it in GitHub Desktop.
Save sizhky/a4f1e9a13f83a332ab862260c5c0281c to your computer and use it in GitHub Desktop.
import cv2, os
def stem(fpath): return '.'.join(fname(fpath).split('.')[:-1])
def convert_mp4_to_frames(filename):
vidcap = cv2.VideoCapture(filename)
success,image = vidcap.read()
count = 0
while success:
os.makedirs(stem(filename), exist_ok=True)
cv2.imwrite(f"{stem(filename)}/{count}.jpg", image) # save frame as JPEG file
success,image = vidcap.read()
print(count, end='\r')
count += 1
filename = 'sample-mp4-file.mp4'
convert_mp4_to_frames(filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment