File indexing completed on 2024-12-01 09:38:08
0001 #!/bin/sh 0002 0003 # First create a new directory (aac ac3 mp3) 0004 # Example for aac: 0005 # rsync -a --exclude .git voices.ogg/ voices.aac 0006 # cd voices.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 if [ ! -d af ] 0016 then 0017 echo "ERROR: move to the voice directory first" 0018 exit 1 0019 fi 0020 0021 format=$1 0022 0023 encoder="avconv" 0024 if command -v avconv >/dev/null 2>&1; 0025 then 0026 echo "avconv found" 0027 if [ $format = "aac" ] 0028 then 0029 codec="libvo_aacenc" 0030 elif [ $format = "ac3" ] 0031 then 0032 codec="ac3" 0033 elif [ $format = "mp3" ] 0034 then 0035 codec="libmp3lame" 0036 else 0037 echo "Error, unsupported format $1" 0038 exit 1 0039 fi 0040 elif command -v ffmpeg >/dev/null 2>&1; 0041 then 0042 echo "ffmpeg found" 0043 encoder="ffmpeg" 0044 if [ $format = "aac" ] 0045 then 0046 codec="aac" 0047 elif [ $format = "ac3" ] 0048 then 0049 codec="ac3" 0050 elif [ $format = "mp3" ] 0051 then 0052 codec="mp3" 0053 else 0054 echo "Error, unsupported format $1" 0055 exit 1 0056 fi 0057 else 0058 echo "neither avconv nor ffmpeg found" 0059 exit 1 0060 fi 0061 0062 task() { 0063 #echo "Processing $1" 0064 $encoder -v warning -i $1 -acodec $codec ${1%.*}.${format} </dev/null > /dev/null 2>&1 0065 if [ $? -ne 0 ] 0066 then 0067 echo "ERROR: Failed to convert $f" 0068 fi 0069 rm -f $1 0070 } 0071 0072 parallelCount=4 0073 echo "Transcode ogg files to $format" 0074 start=$SECONDS 0075 for f in $(find . -type f -name \*.ogg) 0076 do 0077 ((i=i%parallelCount)); ((i++==0)) && wait 0078 task $f & 0079 done 0080 duration=$(( SECONDS - start )) 0081 echo "Conversion took $duration seconds" 0082 0083 echo "Fix symlinks" 0084 start=$SECONDS 0085 for f in $(find . -type l -name \*.ogg) 0086 do 0087 #echo "Processing $f" 0088 target=$(readlink -f $f) 0089 rm $f 0090 ln -s -r ${target%.*}.${format} ${f%.*}.${format} 0091 done 0092 duration=$(( SECONDS - start )) 0093 echo "Fix symlinks took $duration seconds" 0094