File indexing completed on 2024-07-21 03:28:56

0001 #!/bin/sh
0002 
0003 # First create a new directory (aac ac3 mp3)
0004 # Example for aac:
0005 # rsync -a --exclude .git backgroundMusic *.sh $aac
0006 # cd aac
0007 # ./encodeTo.sh
0008 
0009 if [ $# -ne 1 ]
0010 then
0011   echo "Usage $(basename $0) aac|ac3|mp3"
0012   exit 1
0013 fi
0014 
0015 format=$1
0016 
0017 encoder="avconv"
0018 if command -v avconv >/dev/null 2>&1;
0019 then
0020     echo "avconv found"
0021     if [ $format = "aac" ]
0022     then
0023         codec="libvo_aacenc"
0024     elif [ $format = "ac3" ]
0025     then
0026         codec="ac3"
0027     elif [ $format = "mp3" ]
0028     then
0029         codec="libmp3lame"
0030     else
0031         echo "Error, unsupported format $1"
0032         exit 1
0033     fi
0034 elif command -v ffmpeg >/dev/null 2>&1;
0035 then
0036     echo "ffmpeg found"
0037     encoder="ffmpeg"
0038     if [ $format = "aac" ]
0039     then
0040         codec="aac"
0041     elif [ $format = "ac3" ]
0042     then
0043         codec="ac3"
0044     elif [ $format = "mp3" ]
0045     then
0046         codec="mp3"
0047     else
0048         echo "Error, unsupported format $1"
0049         exit 1
0050     fi
0051 else
0052     echo "neither avconv nor ffmpeg found"
0053     exit 1
0054 fi
0055 
0056 echo "Transcode ogg files to $format"
0057 for f in $(find . -type f -name \*.ogg)
0058 do
0059     #echo "Processing $f"
0060     $encoder -v warning -i $f -acodec $codec ${f%.*}.${format}
0061     if [ $? -ne 0 ]
0062     then
0063        echo "ERROR: Failed to convert $f"
0064     fi
0065     id3v2 -a "$(vorbiscomment --list $f | grep 'ARTIST' | cut -d '=' -f 2)" ${f%.*}.${format}
0066     id3v2 -t "$(vorbiscomment --list $f | grep 'TITLE' | cut -d '=' -f 2)" ${f%.*}.${format}
0067     id3v2 -y "$(vorbiscomment --list $f | grep 'DATE' | cut -d '=' -f 2)" ${f%.*}.${format}
0068     id3v2 --TCOP "$(vorbiscomment --list $f | grep 'COPYRIGHT' | cut -d '=' -f 2)" ${f%.*}.${format}
0069     rm -f $f
0070 done
0071 
0072 echo "Fix symlinks"
0073 for f in $(find . -type l -name \*.ogg)
0074 do
0075     #echo "Processing $f"
0076     target=$(readlink -f $f)
0077     rm $f
0078     ln -s -r ${target%.*}.${format} ${f%.*}.${format}
0079 done