#!/usr/bin/ruby -w # -*- coding: utf-8 -*- # # Copyright (C) 2007-2009 Thomer M. Gil [http://thomer.com/] # # Thanks to Brian Moore, Justin Payne, Matt Spitz, Martyn Parker, # Jean-Francois Macaud, Thomas Hannigan, Anisse Astier, Juanma Hernández, # Trung Huynh, and Mark Ryan for bugfixes and suggestions. # # Oct. 14, 2008: show percentage progress. add -t and -w flags. # Jan. 11, 2009: switch to bit/s bitrates for newer ffmpeg versions. # add --iphone option. # add -y option to ffmpeg (overwrite). # Jan. 20, 2009: don't exit early when processing multiple files. # Feb. 17, 2009: deal with "Invalid pixel aspect ratio" error. # Apr. 1, 2009: new --outdir parameter. # May 22, 2009: handle filenames with quotes and whitespace. # Oct 6, 2009: fix bug where we forget to read stderr # Nov. 5, 2009: fix -v, -t, and -w command line options # removed bogus 'here' debug statement # # This program is free software. You may distribute it under the terms of # the GNU General Public License as published by the Free Software # Foundation, version 2. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General # Public License for more details. # # This program converts video files to mp4, suitable to be played on an iPod # or an iPhone. It is careful about maintaining the proper aspect ratio. # require 'getoptlong' require 'open3' # will automatically try with -vcoded libxvid, also. # will automatically try with -acodec libfaac, also. DEFAULT_ARGS = "-f mp4 -y -vcodec xvid -maxrate 1000 -qmin 3 -qmax 5 -g 300 -acodec aac" DEFAULT_BUFSIZE = 4096 DEFAULT_AUDIO_BITRATE = 128 # will be automatically multiplied with 1024 for newer ffmpeg versions DEFAULT_VIDEO_BITRATE = 400 # will be automatically multiplied with 1024 for newer ffmpeg versions IPOD_WIDTH = 320.0 IPOD_HEIGHT = 240.0 IPHONE_WIDTH = 480.0 IPHONE_HEIGHT = 320.0 $options = {} opts = GetoptLong.new(*[ [ "--audio", "-a", GetoptLong::REQUIRED_ARGUMENT ], # audio bitrate [ "--help", "-h", GetoptLong::NO_ARGUMENT ], # help [ "--video", "-b", GetoptLong::REQUIRED_ARGUMENT ], # video bitrate [ "--verbose", "-v", GetoptLong::NO_ARGUMENT ], # verbose [ "--width", "-w", GetoptLong::REQUIRED_ARGUMENT ], # override width [ "--height", "-t", GetoptLong::REQUIRED_ARGUMENT ], # override height [ "--iphone", "-i", GetoptLong::NO_ARGUMENT ], # set width/height [ "--outdir", "-o", GetoptLong::REQUIRED_ARGUMENT ], # dir where to write files ]) opts.each { |opt, arg| $options[opt] = arg } if $options['--help'] puts <= duration * 0.99)) end end