Created
July 24, 2020 05:05
-
-
Save sizhky/a4f1e9a13f83a332ab862260c5c0281c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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