sistema_progs

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

ringtone (946B)


      1 #!/usr/bin/env sh
      2 
      3 # Description: Create an mp3 ringtone out of an audio file in any format
      4 #              Needs user to provide start and end where to cut the file
      5 #              Input file audio.ext results in audio_ringtone.mp3
      6 #
      7 #              Tip: To convert a complete media file, set start as 0 and
      8 #              the runtime of the file as end.
      9 #
     10 # Dependencies: date, ffmpeg
     11 #
     12 # Shell: POSIX compliant
     13 # Author: Arun Prakash Jana
     14 
     15 if [ -n "$1" ]; then
     16     printf "start (hh:mm:ss): "
     17     read -r start
     18     st=$(date -d "$start" +%s) || exit 1
     19 
     20     printf "end (hh:mm:ss): "
     21     read -r end
     22     et=$(date -d "$end" +%s) || exit 1
     23 
     24     if [ "$st" -ge "$et" ]; then
     25         printf "error: start >= end "
     26         read -r _
     27         exit 1
     28     fi
     29 
     30     interval=$(( et - st ))
     31 
     32     outfile=$(basename "$1")
     33     outfile="${outfile%.*}"_ringtone.mp3
     34 
     35     ffmpeg -i "$1" -ss "$start" -t "$interval" -vn -sn -acodec libmp3lame -q:a 2 "$outfile"
     36 fi