Skip to content

Instantly share code, notes, and snippets.

@duhaime
Last active December 14, 2017 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duhaime/3cfb33bdadefc22fcba0de874f8e448a to your computer and use it in GitHub Desktop.
Save duhaime/3cfb33bdadefc22fcba0de874f8e448a to your computer and use it in GitHub Desktop.
Convert an mp4 to a series of jpg files, one per frame
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