|Description||User job to transcode selected recordings to XviD and AAC for use in iPods and other devices with similar codec support.|
iPod export script
Here is a script to export recordings in a format compatible with a video iPod. It can be used on the command line or as a user job script.
Command line usage
If using on the command line, the usage information is as follows:
ipodexport.pl exportdir=/foo/bar starttime=%STARTTIME% chanid=%CHANID% bitrate=x size=320x240 aspect=4:3 debug
%CHANID% = channel ID associated with the recording to export
%STARTTIME% = recording start time in either 'YYYY-MM-DD HH:MM:SS' or 'YYYYMMDDHHMMSS' format
exportdir = dir to export completed MP4 files to (note the user the script runs as must have write permission on that dir
size = frame size of output file. 320x240 is the default value
aspect = aspect ratio of output file. Valid values are 4:3 (default) and 16:9
bitrate = audio bitrate in output file in kbps. Default value is 96
debug = enable debugging information - outputs which commands would be run etc
Use as a User Job
Enter mythtv-setup and select the 'general' menu option. Keep hitting 'next' until the 'Job Queue (Job Commands)' screen appears.
Add a brief description of the script in the 'description' field then enter the path to the script (including any options) to the 'command' field.
In this case, put 'export recordings to iPod' in the description field and
ipodexport.pl exportdir=/foo/bar starttime=%STARTTIME% chanid=%CHANID% bitrate=128 size=320x240 aspect=4:3in the 'command' field. You may want to change some of the parameters to suit your own needs.
Click all the way to 'finish' and if user jobs are permitted to run, the script will now be available to use.
Note on change in ffmpeg parameter
With a recent version of ffmpeg (SVN-r25059), the above script gives this error:
encoder 'aac' is experimental and might produce bad results. Add '-strict experimental' if you want to use it. Or use the non experimental encoder 'libfaac'.
-acodec aac to
-acodec libfaac in the
$command line in the script to solve the issue.
Note On Conversion Of DVB Recording
If you live in the UK and you are using MythTV with Freeview, then you are probably pulling your hair out for 2 reasons:
- It is impossible to get the audio and video in sync whatever you do.
- Somehow ffmpeg always seems to pick the audio description soundtrack for the partially sighted rather than the normal one.
I have used the following script for some time, and it solves both the above problems by using ffprobe to determine which soundtrack to pick and then projectX to correct the lip-sync problems.
You can find details of how to install projectX here: Installing_MythArchive_Dependencies#ProjectX.
#!/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 | sed -e 's/]//g' | sed -e 's/(//g'` AUDIO_PID=`ffprobe "$1" 2>&1 | grep "2 channels" | cut -c17-22 | sed -e 's/]//g' | sed -e 's/(//g'` # 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.