Benutzer-Werkzeuge

Webseiten-Werkzeuge


programming:shell:m4pconvert

Convert aac (m4p) to mp3

aac_to_mp3.sh

#!/bin/bash
#
# Shell script for m4a to mp3 conversion
#
# The scripts reads all m4a files recursively from a directory tree
# It creates the mp3 file from the m4a, and removes the m4a file
#
# Please run the script from the Base Directory in which your Music is stored
# make sure, that you have the appropriate permissions to create and delete files
# in the directory tree
 
# ------------------------------------------------------------------------------
# function to list all m4a files into a file
# ------------------------------------------------------------------------------
 
list_songs(){
 
  echo "creating list of m4a files...."
  sleep 2
  find . -type f -name *.m4a > $FILE
  echo "added `wc -l $FILE` entries"
  echo "done."
  sleep 2
 
}
 
# ------------------------------------------------------------------------------
# function to convert a single file from m4a to mp3
# ------------------------------------------------------------------------------
 
m4a_to_mp3(){
 
  m4a_file="$@" # get all args
  echo "processing file $m4a_file ..."
 
  # convert m4a file to wav
  faad "$m4a_file"
 
  # generating filenames
  wav_file=`echo "$m4a_file"|sed -e 's/.m4a/.wav/'`
  mp3_file=`echo "$m4a_file"|sed -e 's/.m4a/.mp3/'`
 
  #echo "wav file: $wav_file"
  #echo "mp3 file: $mp3_file"
 
  # preserve track info, lame will use it for id3 tagging
  faad -i "$m4a_file" 2>.id3info.txt
  title=`grep 'title: ' .id3info.txt|sed -e 's/title: //'`
  artist=`grep 'artist: ' .id3info.txt|sed -e 's/artist: //'`
  album=`grep 'album: ' .id3info.txt|sed -e 's/album: //'`
  track=`grep 'track: ' .id3info.txt|sed -e 's/track: //'`
  year=`grep 'year: ' .id3info.txt|sed -e 's/year: //'`
 
  # convert wav to mp3
  lame -h -b 192 --tt "$title" --ta "$artist" --tl "$album" --tn "$track" --ty "$year" "$wav_file" "$mp3_file"
  #lame --alt-preset 160 --tt "$title" --ta "$artist" --tl "$album" --tn "$track" --ty "$year" "$wav_file" "$mp3_file"
 
  # cleaning up
  #echo "cleaning up ..."
  rm .id3info.txt
  #echo "removing trackinfo.txt done."
  rm "$wav_file"
  #echo "removing $wav_file done."
  rm "$m4a_file"
  #echo "removing $m4a_file done."
 
}
 
################################################################################
# Main
################################################################################
FILE="songlist.txt"
 
# create list of m4a Files (> songlist.txt)
list_songs
 
# check file songlist.txt
  if [ ! -s $FILE ]; then
    echo "$FILE does not exists, or list is empty"
    echo "nothing to do."
    exit 1
  elif [ ! -r $FILE ]; then
    echo "$FILE is not readable"
    exit 1
  fi
 
# process $FILE line by line (< songlist.txt)
exec 3<&0
exec 0<$FILE
while read line
do
   m4a_to_mp3 $line
done
exec 0<&3
 
exit 0
programming/shell/m4pconvert.txt · Zuletzt geändert: von 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki