summaryrefslogtreecommitdiffstats
path: root/abs/core/LinHES-system/myth2mp3
diff options
context:
space:
mode:
authorBritney Fransen <brfransen@gmail.com>2013-09-16 22:08:01 (GMT)
committerBritney Fransen <brfransen@gmail.com>2013-09-16 22:08:01 (GMT)
commit2c5a67ec9f7176f022449415a48f48d89cf0afad (patch)
tree5df6f12de751b985abc7e8a0661fa7821dbe3696 /abs/core/LinHES-system/myth2mp3
parent13db4e5f492412b8127322169ffc8e75c3ea4ef4 (diff)
downloadlinhes_pkgbuild-2c5a67ec9f7176f022449415a48f48d89cf0afad.zip
linhes_pkgbuild-2c5a67ec9f7176f022449415a48f48d89cf0afad.tar.gz
linhes_pkgbuild-2c5a67ec9f7176f022449415a48f48d89cf0afad.tar.bz2
LinHES-system: move get_airplay_key, importfile.sh, myth2mkv, myth2mp3, and ripD_eject.sh from linhes-scripts
Diffstat (limited to 'abs/core/LinHES-system/myth2mp3')
-rwxr-xr-xabs/core/LinHES-system/myth2mp396
1 files changed, 96 insertions, 0 deletions
diff --git a/abs/core/LinHES-system/myth2mp3 b/abs/core/LinHES-system/myth2mp3
new file mode 100755
index 0000000..69d5d3f
--- /dev/null
+++ b/abs/core/LinHES-system/myth2mp3
@@ -0,0 +1,96 @@
+#!/bin/sh
+# convert recordings to as mp3 audio only
+# version 1.1.3
+
+# usage:
+# first parameter must be %DIR%/%FILE% of the recording
+# second parameter must be the desired base name of the output
+# third parameter must be %CHANID% if you set USECUTLIST=Y
+# fourth parameter must be %STARTTIME% if you set USECUTLIST=Y
+# In the mythtv setup screen invoke this script like this:
+# MYTHTV User Job Command:
+# /usr/LH/bin/myth2mp3 "%DIR%/%FILE%" "%TITLE% - %SUBTITLE%" "%CHANID%" "%STARTTIME%"
+
+# options:
+BITRATE=256k #ie. 128k, 160k, 192k, 224k, 256k
+USECUTLIST=Y #Y or N
+
+# where the converted audio is stored
+OUT_DIR=/myth/music
+
+# create temp filename so multiple instances won't conflict
+TMPNAME=toMP3-$$
+TMPFILE=/myth/tmp/$TMPNAME
+TMPCUTFILE=/myth/tmp/$TMPNAME.mpg
+FFINPUTFILE=$1
+TITLE=`echo $2 | sed 's/\//_/g'`
+
+# log file location
+LOGFILE=/var/log/mythtv/myth2mp3.log
+CDate="`date`"
+echo "" >> $LOGFILE
+echo $CDate >> $LOGFILE
+echo "File to encode: $1 Name: $TITLE" >> $LOGFILE
+
+# start timer
+beforetime="$(date +%s)"
+
+# check if using cutlist
+if [ $USECUTLIST = Y ];then
+ MYTHCOMMFRAMES=`mythutil --getcutlist --chanid "$3" --starttime "$4" | grep 'Cutlist:' | cut -d \ -f 2`
+ if [ -n "$MYTHCOMMFRAMES" ]; then
+ echo "Extracting Cutlist..." >> $LOGFILE
+ /usr/bin/nice -n19 /usr/bin/mythtranscode --chanid "$3" --starttime "$4" --outfile "$TMPCUTFILE" --mpeg2 --honorcutlist
+ FFINPUTFILE=$TMPCUTFILE
+ fi
+fi
+
+# run ffmpeg to do conversion to wav
+echo "Encoding to intermediate wav..." >> $LOGFILE
+/usr/bin/nice -n19 /usr/bin/ffmpeg -i "$FFINPUTFILE" -vn -acodec pcm_s16le -ar 44100 -ac 2 "$TMPFILE.wav"
+ERROR=$?
+
+# Normalize the intermediate wav
+echo "Normalizing intermediate wav..." >> $LOGFILE
+/usr/bin/nice -n19 /usr/bin/normalize -q "$TMPFILE.wav"
+ERROR=$?
+
+FFINPUTFILE=$TMPFILE.wav
+
+# Final encode of normalized wav to mp3
+echo "Encoding normalized wav to mp3..." >> $LOGFILE
+/usr/bin/nice -n19 /usr/bin/ffmpeg -i "$FFINPUTFILE" -vn -acodec libmp3lame -ab $BITRATE -ar 44100 -ac 2 "$TMPFILE.mp3"
+ERROR=$?
+
+# make output filename unique
+OUTPUTFILE=$OUT_DIR/$TITLE.mp3
+i=1
+while [ -e "$OUTPUTFILE" ]
+do
+ OUTPUTFILE=$OUT_DIR/$TITLE-$i.mp3
+ i=`expr $i + 1`
+done
+
+# move temp file to output location
+chown mythtv "$TMPFILE.mp3" && mv "$TMPFILE.mp3" "$OUTPUTFILE"
+
+# stop timer
+aftertime="$(date +%s)"
+seconds="$(expr $aftertime - $beforetime)"
+
+if [ $ERROR -eq 0 ]; then
+ echo "File Encoded Sucessfully: $OUTPUTFILE" >> $LOGFILE
+ hours=$((seconds / 3600))
+ seconds=$((seconds % 3600))
+ minutes=$((seconds / 60))
+ seconds=$((seconds % 60))
+ echo "Encoding Time: $hours hour(s) $minutes minute(s) $seconds second(s)" >> $LOGFILE
+else
+ echo "ERROR: $ERROR" >> $LOGFILE
+fi
+
+# clean up left over files
+unlink $TMPFILE.mp3 2> /dev/null
+unlink $TMPFILE.wav 2> /dev/null
+unlink $TMPCUTFILE 2> /dev/null
+unlink $TMPCUTFILE.map 2> /dev/null