#!/bin/bash # # Developer: Alper KANAT # Contributor: Ricky Cintron # # Script name: ipodenc # Purpose: Used to transcode existing video files # into ipod-friendly .mp4 files. # Resulting format of the video (Available Options: mov, mp4) FORMAT="mp4" # Video Size (Available Options: 320:240, 640:480) SIZE="320:240" # Aspect Ratio (Available Options: 4/3, 16/9) ASPECT_RATIO="4/3" # Audio Bitrate (Available Recommended Options: 96, 128, 320) A_BITRATE=320 # Subtitle Codepage SUB_CP="iso8859-9" # Subtitle Size SUB_SIZE=4 # Log File. It will be saved in the same directory. (Available Options: 0, 1) LOG=0 if [ $LOG -ge 0 -a $LOG -le 1 ]; then if [ $LOG -eq 0 ]; then log2here="/dev/null" else log2here="`basename $0`-log.txt" fi else echo echo "LOG Switch can only be 1 or 0." echo exit 0 fi help_usage () { echo echo "Usage: `basename $0` -a \"Artist\" -n \"Name\" -s /path/to/subtitle.ext /path/to/sourcefile.ext" echo echo "Options:" echo " -a Artist name for destination file" echo " -n Track name for destination file" echo " -s Subtitle file to be used" echo echo "Note: The source file is required." echo exit 1 } if [ $# -lt 1 ]; then help_usage elif [ $# -gt 7 ]; then echo "" echo "Incorrect number of parameters." help_usage fi while getopts a:n:s: opt do case "$opt" in a) if [ ! -f "$OPTARG" ]; then artist="$OPTARG" else help_usage fi;; n) if [ ! -f "$OPTARG" ]; then name="$OPTARG" else help_usage fi;; s) if [ -f "$OPTARG" ]; then sub="$OPTARG" echo echo "Subtitle detected." else echo echo "Missing or wrong subtitle." help_usage fi;; *) help_usage;; esac done # Set the index to the filename shift $(($OPTIND - 1)) if [ -f "$1" ]; then source_filename="$1" else echo echo "Missing or wrong filename." help_usage fi if [ -z "${artist}" ]; then artist="Unknown Artist" fi if [ -z "${name}" ]; then name="Unknown Name" fi echo echo "Process starting..." echo if [ -z "${sub}" ]; then mencoder -quiet -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=2500:vqmin=2:vqmax=10:acodec=aac:vglobal=1:aglobal=1:abitrate=$A_BITRATE:aspect=$ASPECT_RATIO -oac lavc -lavfopts format=$FORMAT:i_certify_that_my_video_stream_does_not_use_b_frames -vf scale=$SIZE,harddup -of lavf -info artist="${artist}":name="${name}" -o "${artist} - ${name}.$FORMAT" "${source_filename}" &> "$log2here" else mencoder -quiet -sub "${sub}" -subcp $SUB_CP -subfont-encoding unicode -subfont-text-scale $SUB_SIZE -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=2500:vqmin=2:vqmax=10:acodec=aac:vglobal=1:aglobal=1:abitrate=$A_BITRATE:aspect=$ASPECT_RATIO -oac lavc -lavfopts format=$FORMAT:i_certify_that_my_video\_stream_does_not_use_b_frames -vf scale=$SIZE,harddup -of lavf -info artist="${artist}":name="${name}" -o "${artist} - ${name}.$FORMAT" "${source_filename}" &> "$log2here" fi echo echo "Operation completed successfully!" echo "$source_filename has been transcoded to `pwd`/${artist} - ${name}.$FORMAT" echo