Skip to content

Instantly share code, notes, and snippets.

@607011
Created January 28, 2016 13:13
Show Gist options
  • Save 607011/c64a55998a51cc451e01 to your computer and use it in GitHub Desktop.
Save 607011/c64a55998a51cc451e01 to your computer and use it in GitHub Desktop.
Convert screencast from Microsoft Expression Encoder to mp4 and webm, extract a thumbnail at 75% of playtime
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import sys, subprocess
from os import chdir
from glob import glob
FFMPEG = 'D:\\Developer\\ffmpeg.exe'
FFPROBE = 'D:\\Developer\\ffprobe.exe'
def main():
folder = sys.argv[1]
chdir(folder)
f = glob('*.wmv')[0]
subprocess.call([FFMPEG, '-y', '-i', f, '-an', '-preset', 'veryslow', '-qp', '0', '-movflags', '+faststart', '-vcodec', 'libx264', '-vf', 'fps=10', 'output.mp4'])
subprocess.call([FFMPEG, '-y', '-i', f, '-an', '-q:v', '0', '-preset', 'veryslow', '-vcodec', 'libvpx', '-vf', 'fps=10', 'output.webm'])
p = subprocess.Popen([FFPROBE, '-of', 'flat=s=_', '-v', 'error', '-show_entries', 'format=duration', 'output.mp4'], stdout=subprocess.PIPE)
p.wait()
duration = str(0.75 * float(p.communicate()[0].split('=')[1].rstrip()[1:-1]))
subprocess.call([FFMPEG, '-y', '-i', 'output.mp4', '-vframes', '1', '-ss', duration, 'thumbnail.png'])
chdir('..')
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment