name=unnamed
author=Justin Hornsby
webpage=none
short=export recordings to iPod
long=User job to transcode selected recordings to XviD and AAC for use in iPods and other devices with similar codec support.
file=none
category=User Job Scripts
supports=S21:unset,S22:unset,S23:unset,S231:unset,S24:unset,S241:unset,S25:unset,S251:unset,S252:unset,S26:unset,S27:unset,S28:unset,S29:unset

Author

Justin Hornsby

Description

User job to transcode selected recordings to XviD and AAC for use in iPods and other devices with similar codec support.

#!/bin/bash
# Run this script with 2 arguments:
#
# iphone.sh <src_file> <dest_file>
#
# We make a temporary directory to work in.
# NOTE: If you have problems with file access it is probably
# because you tested this script as one user and the mythtv is
# running as another. Try chmoding this directory to 777.
mkdir /tmp/projectX
# Generate the filenames for the commands
TMP_FILE=`basename "$1" .mpg`
TMP2_FILE=/tmp/`basename "$1" .mpg`.mov
# First up, we find the correct audio and video streams
# to transcode, if we didn't do this then 9 times out of 10
# you will end up with a video that has the audio descriptive
# track and not the real audio!
VIDEO_PID=`ffprobe "$1" 2>&1 | grep -i "video" | cut -c17-22`
AUDIO_PID=`ffprobe "$1" 2>&1 | grep "2 channels" | cut -c17-22`
VIDEO_PID=${VIDEO_PID/\]/}
AUDIO_PID=${AUDIO_PID/\]/}
# Now use projectX to split the audio and video in to separate files. We
# do this to fix lip-sync problems when transcoding DVB-T transmission.
# Note that the important thing here is that projectX fixes up the problems
# not the separation in to separate files.
# If you don't do this then the audio and video will be out of sync by many
# seconds by then end of the programme.
# This is where we use the PIDs from the previous commands.
java -Djava.awt.headless=true -jar /usr/share/projectx/ProjectX.jar -demux "$1" -id $AUDIO_PID,$VIDEO_PID -out /tmp/projectX/
#
# Now we can actually transcode the video! Insert your favourite ffmpeg
# command below. Don't like it or it is too slow, well try changing the
# output size to 320x180 to speed up the transcode.
ffmpeg -i "/tmp/projectX/$TMP_FILE.m2v" -i "/tmp/projectX/$TMP_FILE.mp2" -async 1000 -dts_delta_threshold 100 -vcodec libx264 -b 768k -vpre medium -s 720x576 -acodec libfaac -ac 2 -ar 48k -ab 128k "$TMP2_FILE"
# We can now delete the intermediate files
rm /tmp/projectX/$TMP_FILE*
# ... and move the result in to the output directory
mv $TMP2_FILE $2

Multi Channel Audio

When a recording is in 5.1 surround sound, or any multi channel audio for that matter, I had to use the following option for ffmpeg to convert to 2 channel stereo. Otherwise the ipod would not output any audio.