#!/bin/bash # # recode and burn subtitles for iphone/ipod-touch # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # any later version. # # 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. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # # (C) 2008 Jose L. Hidalgo ValiƱo (pplux@pplux.com) # OUTPUT="${1%%${1##*.}.}_ipod.mp4" LANG="en" # Optional language to search subtitles as in VLC ############################################################################## [ -f "$1" ] || { echo "File $1, not found"; exit 1; } SUBS_ALT="${1%%${1##*.}}$LANG.srt" if [ -f "$SUBS_ALT" ]; then SUBS_FILE=$SUBS_ALT; else SUBS_FILE="${1%%${1##*.}}srt"; fi if [ -f "$SUBS_FILE" ]; then SUBS_OPTS="-subfont-autoscale 1 -sub"; echo "Subtitles found... $SUBS_FILE" [ -f ~/.mplayer/subfont.ttf ] || cat; << EOF **************** WARNING ****************** * You're trying to use subtitles, but * * mplayer doesn't have a subtitles font. * * It is possible that mplayer requires * * one, in that case you should place it * * here: * * ~/.mplayer/subfont.ttf * ******************************************* EOF else SUBS_FILE=""; SUBS_OPTS=""; fi # Create a temp file TEMP=$(mktemp -t ipodvideo) # first pass, rescale and include subtitles mencoder -vf scale=480:-3 -ovc lavc -oac copy $SUBS_OPTS "$SUBS_FILE" -o $TEMP "$1" # encode using mpeg4 FFMPEG_VIDEO_OPTS="-vcodec libx264 -b 128k -level 30 -mbd 2 -cmp 2 -subcmp 2 -g 300 -qmin 20 -qmax 31 -flags +loop -chroma 1 -partitions partp8x8+partb8x8 -flags2 +mixed_refs -me_method 8 -subq 7 -trellis 2 -refs 1 -coder 0 -me_range 16 -bf 0 -sc_threshold 40 -keyint_min 25 -maxrate 3584k -bufsize 8192k" FFMPEG_AUDIO_OPTS="-acodec libfaac -ac 2 -ar 44100 -ab 0 -aq 120 -alang ENG -async 1 " ffmpeg -i $TEMP -y $FFMPEG_VIDEO_OPTS $FFMPEG_AUDIO_OPTS "${OUTPUT}" # remove temp file rm $TEMP echo "->$OUTPUT<- done!" which growlnotify >/dev/null && growlnotify -t "ipod video" -m "Finished ${OUTPUT}"