Skip to content

Instantly share code, notes, and snippets.

@danielnorberg
Created February 10, 2011 15:00
Show Gist options
  • Save danielnorberg/820653 to your computer and use it in GitHub Desktop.
Save danielnorberg/820653 to your computer and use it in GitHub Desktop.
dvd_transcode takes a list of video files and transcodes them into DVD compliant MPEG-2 (NTSC).
#! /usr/bin/env python
import argparse
import os
import subprocess
def main():
parser = argparse.ArgumentParser(description='Transcodes videos to DVD compatible MPEG-2 using mencoder')
parser.add_argument('file', help='Input file', nargs='+')
args = parser.parse_args()
command_format = "mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd:tsaf"\
" -vf scale=720:480,harddup -srate 48000 -af lavcresample=48000"\
" -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:keyint=18:vstrict=0:acodec=ac3:abitrate=192:aspect=16/9"\
" -ofps 30000/1001 -o \"%s\" \"%s\""
commands = []
logfilepaths = []
for filepath in args.file:
root, ext = os.path.splitext(filepath)
logfilepath = '%s.transcoding.log' % root
logfilepaths.append(logfilepath)
output_filepath = '%s.mpg' % root
command = command_format % (output_filepath, filepath)
commands.append(command)
logfiles = []
processes = []
for command, logfilepath in zip(commands, logfilepaths):
logfile = open(logfilepath, 'w')
logfiles.append(logfile)
p = subprocess.Popen(command, shell=True, stdout=logfile, stderr=logfile)
processes.append(p)
for p in processes:
p.wait()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment