Skip to content

Instantly share code, notes, and snippets.

@stuartloxton
Created February 14, 2012 15:58
Show Gist options
  • Save stuartloxton/1827750 to your computer and use it in GitHub Desktop.
Save stuartloxton/1827750 to your computer and use it in GitHub Desktop.
Quick script to convert videos into mov + ogg for HTML5 videos
#!/usr/bin/env python
import sys
import os.path
import re
import subprocess
if( len(sys.argv) < 2 ):
print("Usage: %s filename" % sys.argv[0])
sys.exit(1)
def slugify(filename, separator='-'):
# Remove Special characters
regex = re.compile( '[^a-z0-9\s\.]' )
filename = regex.sub( '', filename.lower() ).strip()
filename = filename.replace(' ', separator)
return filename
full_path = os.path.realpath( sys.argv[1] )
filename = os.path.basename( sys.argv[1] )
base_path = full_path.replace( filename, '' )
safe_name = slugify( filename.split('.')[0] )
try:
os.mkdir( base_path + safe_name )
except OSError:
print "Directory already exists"
subprocess.call(["ffmpeg", "-i", full_path, "-vframes", "10", "-r", "1", "-s", "640x360", base_path+safe_name+"/poster-%d.jpg"])
subprocess.call(["ffmpeg", "-i", full_path, "-s", "640x360", base_path+safe_name+"/"+safe_name+".ogg"])
subprocess.call(["ffmpeg", "-i", full_path, "-vcodec", "libx264", "-s", "640x360", base_path+safe_name+"/"+safe_name+".mov"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment