sistema_progs

Programas para customizar o meu entorno de traballo nos meus equipos persoais
Log | Files | Refs

mp3conv (949B)


      1 #!/usr/bin/env sh
      2 
      3 # Description: Extract audio from multimedia files and convert to mp3
      4 #
      5 # Dependencies: ffmpeg compiled with libmp3lame audio codec support
      6 #
      7 # Shell: POSIX compliant
      8 # Author: Arun Prakash Jana
      9 
     10 outdir=_mp3files
     11 
     12 handle_multimedia() {
     13     mime="${1}"
     14     file="${2}"
     15 
     16     case "${mime}" in
     17         audio/* | video/*)
     18             ffmpeg -i "${file}" -vn -codec:a libmp3lame -q:a 2 "${outdir}/${file%.*}.mp3"
     19             ;;
     20         *)
     21             ;;
     22     esac
     23 }
     24 
     25 printf "Process 'a'll in directory or 'c'urrent? "
     26 read -r resp
     27 
     28 if [ "$resp" = "a" ]; then
     29     if ! [ -e "${outdir}" ]; then
     30         mkdir "${outdir}"
     31     fi
     32 
     33     for f in *; do
     34         if [ -f "${f}" ]; then
     35             mimestr="$( file --dereference --brief --mime-type -- "${f}" )"
     36             handle_multimedia "${mimestr}" "${f}"
     37         fi
     38     done
     39 elif [ "$resp" = "c" ] && [ -f "$1" ]; then
     40     ffmpeg -i "${1}" -vn -codec:a libmp3lame -q:a 2 "${1%.*}.mp3"
     41 fi