Last active
December 14, 2017 19:03
-
-
Save duhaime/3cfb33bdadefc22fcba0de874f8e448a to your computer and use it in GitHub Desktop.
Convert an mp4 to a series of jpg files, one per frame
This file contains 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, sys, glob, os, multiprocessing | |
def get_images(mp4_path): | |
name = '.'.join( os.path.basename(mp4_path).split('.')[:-1] ) | |
out_dir = os.path.join('kpop', 'images', name) | |
if not os.path.exists(out_dir): | |
os.makedirs(out_dir) | |
# 10 fps, 200px width | |
cmd = 'ffmpeg -i ' + mp4_path + ' ' | |
cmd += '-r 10 ' | |
cmd += '-vf scale=200:-1 ' | |
cmd += out_dir + '/' + name + '-%04d.jpg' | |
os.system(cmd) | |
videos = glob.glob(sys.argv[1]) | |
pool = multiprocessing.Pool(6) | |
for i in pool.imap(get_images, videos): | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment