Difference between revisions of "Transcoding for the PDA"

From MythTV Official Wiki
Jump to: navigation, search
 
Line 35: Line 35:
 
Below is Jeff's pdatranscode script:
 
Below is Jeff's pdatranscode script:
  
#!/bin/sh
+
  #!/bin/sh
# pdatranscode
+
  # pdatranscode
#
+
  #
# created by Jeff Volckaert (inspired by Zach White)
+
  # created by Jeff Volckaert (inspired by Zach White)  
# modified 11/10/06
+
  # modified 11/10/06
VIDEODIR=$1
+
  VIDEODIR=$1
FILENAME=$2
+
  FILENAME=$2
TITLE=$3
+
  TITLE=$3
# Remove non-alpha characters from TITLE
+
  # Remove non-alpha characters from TITLE
TITLE=${TITLE//[^a-zA-Z0-9]/}
+
  TITLE=${TITLE//[^a-zA-Z0-9]/}
STARTTIME=$4
+
  STARTTIME=$4
SUBTITLE=$5
+
  SUBTITLE=$5
# Remove non-alpha characters from SUBTITLE
+
  # Remove non-alpha characters from SUBTITLE
SUBTITLE=${SUBTITLE//[^a-zA-Z0-9]/}
+
  SUBTITLE=${SUBTITLE//[^a-zA-Z0-9]/}
 
+
 
# Sanity checking, to make sure everything is in order.
+
  # Sanity checking, to make sure everything is in order.
if [ -z "$VIDEODIR" -o -z "$FILENAME" ]; then
+
  if [ -z "$VIDEODIR" -o -z "$FILENAME" ]; then
        echo "Usage: $0 <VideoDirectory> <FileName> "<Title>" <Starttime>"
+
          echo "Usage: $0 <VideoDirectory> <FileName> "<Title>" <Starttime>"
        exit 5
+
          exit 5
fi
+
  fi
if [ ! -f $VIDEODIR/$FILENAME ]; then
+
  if [ ! -f $VIDEODIR/$FILENAME ]; then
        echo "File does not exist: $VIDEODIR/$FILENAME"
+
          echo "File does not exist: $VIDEODIR/$FILENAME"
        exit 6
+
          exit 6
fi
+
  fi
 
+
 
# Transcode the file (Uncomment the method you want to use)
+
  # Transcode the file (Uncomment the method you want to use)
 
+
   
# Transcode using Myth's Transocde for Low Quality
+
  # Transcode using Myth's Transocde for Low Quality
# mythtranscode -i  $VIDEODIR/$FILENAME -o  $VIDEODIR/pda/$TITLE-$STARTTIME.avi -l -p 29
+
  # mythtranscode -i  $VIDEODIR/$FILENAME -o  $VIDEODIR/pda/$TITLE-$STARTTIME.avi -l -p 29
 
+
 
# Transcode using mencoder Xvid
+
  # Transcode using mencoder Xvid
# mencoder -vf scale=320:240 -oac mp3lame -lameopts mode=0:cbr:br=96 -af volnorm -srate 32000 -ovc xvid -xvidencopts bitrate=300 -o $VIDEODIR/pda/$TITLE-$STARTTIME-$SUBTITLE.avi $VIDEODIR/$FILENAME -quiet
+
  # mencoder -vf scale=320:240 -oac mp3lame -lameopts mode=0:cbr:br=96 -af volnorm -srate 32000 -ovc   xvid -xvidencopts bitrate=300 -o $VIDEODIR/pda/$TITLE-$STARTTIME-$SUBTITLE.avi $VIDEODIR/$FILENAME -quiet
 
+
 
# Transcode Using lavc's mpeg4 (this is what I use)
+
  # Transcode Using lavc's mpeg4 (this is what I use)
# mencoder -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=300:vhq:vpass=1 -vf scale=320:240 -oac lavc -lavcopts acodec=ac3:abitrate=128 -ffourcc DX50 -o $VIDEODIR/pda/$TITLE-$STARTTIME-$SUBTITLE.avi $VIDEODIR/$FILENAME -quiet
+
  # mencoder -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=300:vhq:vpass=1 -vf scale=320:240 -oac lavc   -lavcopts acodec=ac3:abitrate=128 -ffourcc DX50 -o $VIDEODIR/pda/$TITLE-$STARTTIME-$SUBTITLE.avi $VIDEODIR/$FILENAME -quiet
 
+
   
 
+
 
# Transcode using FFmpeg for Ipod Touch
+
  # Transcode using FFmpeg for Ipod Touch
#nice -+19 ffmpeg -i  $VIDEODIR/$FILENAME -f mp4 -r 30 -vcodec mpeg4 -b 384 -qmin 3 -qmax 5 -g 300 -acodec aac -ar 44100 -ab 192 -s 320x240 -aspect 16:9 -title $TITLE $VIDEODIR/pda/$TITLE-$STARTTIME.mp4 -v -1
+
  #nice -+19 ffmpeg -i  $VIDEODIR/$FILENAME -f mp4 -r 30 -vcodec mpeg4 -b 384 -qmin 3 -qmax 5 -g 300   -acodec aac -ar 44100 -ab 192 -s 320x240 -aspect 16:9 -title $TITLE $VIDEODIR/pda/$TITLE-$STARTTIME.mp4 -v -1
 
+
 
 
+
 
# Transcode using Mencoder for Ipod Touch
+
  # Transcode using Mencoder for Ipod Touch
nice -+19 mencoder -ofps 25 -of lavf -lavfopts format=mp4 -af lavcresample=44100 -vf-add harddup -vf-add scale=320:240 -oac lavc -ovc lavc -lavcopts aglobal=1:vglobal=1:acodec=libfaac:abitrate=128:vcodec=mpeg4:vbitrate=384:keyint=25 -o $VIDEODIR/pda/$TITLE-$STARTTIME-$SUBTITLE.mp4 $VIDEODIR/$FILENAME -quiet
+
  nice -+19 mencoder -ofps 25 -of lavf -lavfopts format=mp4 -af lavcresample=44100 -vf-add harddup -vf-add scale=320:240 -oac lavc -ovc lavc -lavcopts aglobal=1:vglobal=1:acodec=libfaac:abitrate=128:vcodec=mpeg4:vbitrate=384:keyint=25 -o $VIDEODIR/pda/$TITLE-$STARTTIME-$SUBTITLE.mp4 $VIDEODIR/$FILENAME -quiet
 
+
 
 
+
 
# Transcode for Dell PDA
+
  # Transcode for Dell PDA
# nice -+19 mencoder -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=256:vhq -vf scale=320:240 -oac lavc -lavcopts acodec=mp3:abitrate=128 -ffourcc DX50 -o $VIDEODIR/pda/$TITLE-$STARTTIME-$SUBTITLE.avi $VIDEODIR/$FILENAME -quiet
+
  # nice -+19 mencoder -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=256:vhq -vf scale=320:240 -oac lavc -lavcopts acodec=mp3:abitrate=128 -ffourcc DX50 -o $VIDEODIR/pda/$TITLE-$STARTTIME-$SUBTITLE.avi $VIDEODIR/$FILENAME -quiet
 
+
 
 
+
 
chmod 664 $VIDEODIR/pda/$TITLE-$STARTTIME-$SUBTITLE.avi
+
  chmod 664 $VIDEODIR/pda/$TITLE-$STARTTIME-$SUBTITLE.avi
 
+
 
ERROR=$?
+
  ERROR=$?
if [ $ERROR -ne 0 ]; then
+
  if [ $ERROR -ne 0 ]; then
        echo "Transcoding failed for ${FILENAME} with error $ERROR"
+
          echo "Transcoding failed for ${FILENAME} with error $ERROR"
        exit 3
+
          exit 3
fi
+
  fi
  
  
 
[[Category:HOWTO]]
 
[[Category:HOWTO]]

Latest revision as of 14:15, 21 November 2007

I created a simple script to transcode recordings for a PDA (Dell Axim X51V in my case). The files get stored in the directory "pda" under my video directory. I just copy the files I want onto a memory card and watch them using TCPMP. An hour long show comes out to 145M or so (that's alot of shows on a $40 2G card). They play wonderfully on the PDA.

I created a second user job to run after Zach's removecommercial script from the Wiki. I check only those shows I want a copy of for the PDA.

Here's the commands I used to create the user job:

mysql> use mythconverg;
mysql> UPDATE settings SET data='/usr/local/bin/pdatranscode %DIR%
%FILE% "%TITLE%" %STARTTIME%' WHERE value='UserJob2';
UPDATE settings SET data='PDA Transcode' WHERE value='UserJobDesc2';
mysql> UPDATE settings SET data='1' WHERE value='JobAllowUserJob2';

Then I create a script call "pdatranscode" and put it in "/usr/local/bin". I have two methods to transcode here. The first one uses mythtranscode's low quality transcoder (number 29 on my system). I have low quality set to 320x240 with a 300k bitrate. An hour long show came out to 136M. The second method uses mencoder. Mencoder produced a show 145M in size. Uncomment whichever you prefer to use.

Another script called pdatranscode.pl with more features (rich syntax for formatting output file names, subdirectories in the output directory, maximum number of videos per directory, and maximum filespace used by all transcoded files in/under PDA output directory) is available at http://www.tux.org/~peterw/linux/pdatranscode.pl.txt Installing pdatranscode.pl is as simple as copying it to your backend server, making the script executable, running a command like

 pdatranscode.pl --install-job-number 1

to update the MySQL database, and restarting mythbackend. It can take the same arguments as Jeff's shell script, but also has its own more flexible command-line usage. Since all options can be overriden on the command line, the same script can be used for different behavior in different User Jobs. For instance, the following commands would set up MythTV for two different jobs with the same script

 pdatranscode.pl --install-job-number 1 --install-job-name "PDA Transcode (TV)" --scale 320:240
 pdatranscode.pl --install-job-number 2 --install-job-name "PDA Transcode (movie)" --filename-format "{title}.avi" --scale 480:360

Run the script with no arguments to get usage and filename format string information. -Peter

Below is Jeff's pdatranscode script:

 #!/bin/sh
 # pdatranscode
 #
 # created by Jeff Volckaert (inspired by Zach White) 
 # modified 11/10/06
 VIDEODIR=$1
 FILENAME=$2
 TITLE=$3
 # Remove non-alpha characters from TITLE
 TITLE=${TITLE//[^a-zA-Z0-9]/}
 STARTTIME=$4
 SUBTITLE=$5
 # Remove non-alpha characters from SUBTITLE
 SUBTITLE=${SUBTITLE//[^a-zA-Z0-9]/}
 
 # Sanity checking, to make sure everything is in order.
 if [ -z "$VIDEODIR" -o -z "$FILENAME" ]; then
         echo "Usage: $0 <VideoDirectory> <FileName> "<Title>" <Starttime>"
         exit 5
 fi
 if [ ! -f $VIDEODIR/$FILENAME ]; then
         echo "File does not exist: $VIDEODIR/$FILENAME"
         exit 6
 fi
 
 # Transcode the file (Uncomment the method you want to use)
   
 # Transcode using Myth's Transocde for Low Quality
 # mythtranscode -i  $VIDEODIR/$FILENAME -o  $VIDEODIR/pda/$TITLE-$STARTTIME.avi -l -p 29
 
 # Transcode using mencoder Xvid
 # mencoder -vf scale=320:240 -oac mp3lame -lameopts mode=0:cbr:br=96 -af volnorm -srate 32000 -ovc    xvid -xvidencopts bitrate=300 -o $VIDEODIR/pda/$TITLE-$STARTTIME-$SUBTITLE.avi $VIDEODIR/$FILENAME -quiet
 
 # Transcode Using lavc's mpeg4 (this is what I use)
 # mencoder -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=300:vhq:vpass=1 -vf scale=320:240 -oac lavc   -lavcopts acodec=ac3:abitrate=128 -ffourcc DX50 -o $VIDEODIR/pda/$TITLE-$STARTTIME-$SUBTITLE.avi $VIDEODIR/$FILENAME -quiet
   
 
 # Transcode using FFmpeg for Ipod Touch
 #nice -+19 ffmpeg -i  $VIDEODIR/$FILENAME -f mp4 -r 30 -vcodec mpeg4 -b 384 -qmin 3 -qmax 5 -g 300   -acodec aac -ar 44100 -ab 192 -s 320x240 -aspect 16:9 -title $TITLE $VIDEODIR/pda/$TITLE-$STARTTIME.mp4 -v -1
 
 
 # Transcode using Mencoder for Ipod Touch
 nice -+19 mencoder -ofps 25 -of lavf -lavfopts format=mp4 -af lavcresample=44100 -vf-add harddup -vf-add scale=320:240 -oac lavc -ovc lavc -lavcopts aglobal=1:vglobal=1:acodec=libfaac:abitrate=128:vcodec=mpeg4:vbitrate=384:keyint=25 -o $VIDEODIR/pda/$TITLE-$STARTTIME-$SUBTITLE.mp4 $VIDEODIR/$FILENAME -quiet
 
 
 # Transcode for Dell PDA
 # nice -+19 mencoder -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=256:vhq -vf scale=320:240 -oac lavc -lavcopts acodec=mp3:abitrate=128 -ffourcc DX50 -o $VIDEODIR/pda/$TITLE-$STARTTIME-$SUBTITLE.avi $VIDEODIR/$FILENAME -quiet
 
 
 chmod 664 $VIDEODIR/pda/$TITLE-$STARTTIME-$SUBTITLE.avi
 
 ERROR=$?
 if [ $ERROR -ne 0 ]; then
         echo "Transcoding failed for ${FILENAME} with error $ERROR"
         exit 3
 fi