Created
March 1, 2013 20:36
-
-
Save smajda/5067584 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
""" | |
Converts source video files in `sources` to mp4, ogv, and webm 640x360. | |
Edit `sources` (list of filenames) and adjust `source_dir`, `output_dir`, | |
and `new_path` as needed. | |
Reference: http://paulrouget.com/e/converttohtml5video/ | |
""" | |
import os | |
import subprocess | |
sources = ( | |
'video_one.mov', | |
'video_two.mov', | |
) | |
source_dir = os.path.dirname(os.path.abspath(__file__)) # Assume same dir as this file | |
output_dir = os.path.join(source_dir, 'output') # Assume this dir + 'output/' | |
def new_path(src, ext): | |
return os.path.join( | |
output_dir, | |
os.path.basename(src).replace('HD.mov', u"640.{0}".format(ext)), | |
) | |
def make_mp4(src): | |
new = new_path(src, 'mp4') | |
cmd = """ffmpeg -i "{0}" \ | |
-acodec libfaac -ab 96k \ | |
-vcodec libx264 -vpre slower -vpre main \ | |
-level 21 -refs 2 -b 345k -bt 345k \ | |
-threads 0 -s 640x360 "{1}" | |
""".format(src, new) | |
subprocess.call(cmd, shell=True) | |
def make_ogg(src): | |
new = new_path(src, 'ogv') | |
cmd = """ffmpeg -i "{0}" \ | |
-acodec libvorbis -ac 2 -ab 96k -ar 44100 \ | |
-b 345k -s 640x360 "{1}" | |
""".format(src, new) | |
subprocess.call(cmd, shell=True) | |
def make_webm(src): | |
new = new_path(src, 'webm') | |
cmd = """ffmpeg -i "{0}" \ | |
-acodec libvorbis -ac 2 -ab 96k -ar 44100 \ | |
-b 345k -s 640x360 "{1}" | |
""".format(src, new) | |
subprocess.call(cmd, shell=True) | |
for src in sources: | |
src = os.path.join(source_dir, src) | |
make_mp4(src) | |
make_ogg(src) | |
make_webm(src) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment