diff options
author | Florian Pritz <f-p@gmx.at> | 2009-07-03 15:46:33 +0200 |
---|---|---|
committer | Florian Pritz <f-p@gmx.at> | 2009-07-03 15:46:33 +0200 |
commit | eed9199f7b00cb6269cf063aa11084cdd7b3a904 (patch) | |
tree | 0e05c5073f0ec310956c98d8967ed066fe003d60 | |
parent | c30b66b3b07846165806ec79cd358b2f35bf91d4 (diff) | |
download | bin-eed9199f7b00cb6269cf063aa11084cdd7b3a904.tar.gz bin-eed9199f7b00cb6269cf063aa11084cdd7b3a904.tar.xz |
remake convert2mp4 in python with new options
-rwxr-xr-x | convert2mp4 | 85 |
1 files changed, 72 insertions, 13 deletions
diff --git a/convert2mp4 b/convert2mp4 index 58c3268..23894b8 100755 --- a/convert2mp4 +++ b/convert2mp4 @@ -1,10 +1,10 @@ -#!/bin/bash +#!/usr/bin/python #---------------------------------------------------- -# Version: 0.1.2 -# Author: Florian "Bluewind" Pritz <f-p@gmx.at> +# Version: 0.2.0 +# Author: Florian "Bluewind" Pritz <f-p@gmx.at> # # Licensed under WTFPL v2 -# (see COPYING for full license text) +# (see COPYING for full license text) # #---------------------------------------------------- # Converts a file to an MP4 which can be played in a flash movie @@ -12,14 +12,73 @@ # Audio: MPEG-4 AAC #---------------------------------------------------- -for i in "$@"; do - pushd . &> /dev/null - cd "$(dirname "$i")" +import sys +import os +import subprocess +from optparse import OptionParser - file="$(basename "$i")" - file_mp4="$(echo ${file} | sed 's/\(.*\)\..*/\1/').mp4" +def main(): + usage = "usage: %prog [options] <files>" + p = OptionParser(usage) + p.add_option("-s", "--size", dest="size", default=False, + help="use <dimension> instead of input dimensions (e.g. 123x123)", metavar="<dimension>") + p.add_option("--vb", dest="vbitrate", default="400000", + help="change the video bitrate", metavar="<bitrate>") + p.add_option("--ab", dest="abitrate", default="160000", + help="change the audio bitrate", metavar="<bitrate>") + p.add_option("--nd", action="store_false", dest="deinterlace", default=True, + help="don't deinterlace the video") - ffmpeg -i "$file" -b 400000 -deinterlace -vcodec libx264 -s 720x576 -r 25 -g 250 -keyint_min 25 -coder ac -me_range 16 -subq 5 -sc_threshold 40 -acodec libfaac -ab 160000 -ar 44100 -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -i_qfactor 0.71 -b_strategy 1 -threads 2 -crf 30 -y "$file_mp4" - qt-faststart "$file_mp4" "done_$file_mp4" - popd &> /dev/null -done + (options, args) = p.parse_args() + + + if len(args) == 0: + p.print_help() + sys.exit() + + ffmpeg_args = [] + + if options.size: + ffmpeg_args.append("-s") + ffmpeg_args.append(options.size) + if options.vbitrate: + ffmpeg_args.append("-b") + ffmpeg_args.append(options.vbitrate) + if options.abitrate: + ffmpeg_args.append("-ab") + ffmpeg_args.append(options.abitrate) + if options.deinterlace: + ffmpeg_args.append("-deinterlace") + + for name in args: + p1 = subprocess.Popen(["echo", "-n", name], stdout=subprocess.PIPE) + p2 = subprocess.Popen(["sed", "s/\(.*\)\..*/\\1/"], stdin=p1.stdout, stdout=subprocess.PIPE) + name_mp4 = p2.communicate()[0] + ".mp4" + subprocess.Popen(merge( + [["ffmpeg", "-i", name, + "-vcodec", "libx264", "-r", "25", + "-g", "250", "-keyint_min", "25", + "-coder", "ac", "-me_range", "16", + "-subq", "5", "-sc_threshold", "40", + "-acodec", "libfaac", "-ar", "44100", + "-cmp", "+chroma", "-partitions", "+parti4x4+partp8x8+partb8x8", + "-i_qfactor", "0.71", "-b_strategy", + "1", "-threads", "0", "-crf", "30", "-y"], + ffmpeg_args, [name_mp4]] + )).communicate()[0] + subprocess.Popen(["qt-faststart", name_mp4, "done_"+name_mp4]).communicate()[0] + +def merge(seq): + merged = [] + for s in seq: + for x in s: + merged.append(x) + return merged + +def file_exists(filename, options): + if os.path.exists(filename) and not options.force: + sys.stderr.write('Target "'+filename+'" already exists. Use --force to overwrite.\n') + sys.exit(1) + +if __name__ == '__main__': + main() |