trimaudio.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/bin/sh
  2. secmax=240 #max length
  3. sectol=30 #tolerance
  4. secfad=10 #fade
  5. #wav is faster
  6. temp1=$(mktemp /tmp/playlistalo.XXXXXXXX.wav)
  7. temp2=$(mktemp /tmp/playlistalo.XXXXXXXX.wav)
  8. temp3=$(mktemp /tmp/playlistalo.XXXXXXXX.wav)
  9. tempx=$(mktemp /tmp/playlistalo.XXXXXXXX.m4a)
  10. #step 1 rimuove il silenzio
  11. echo "Rimuovo il silenzio"
  12. ffmpeg -i "$1" -to $(($secmax + $sectol + 30)) -af "silenceremove=start_periods=1:start_duration=1:start_threshold=-60dB:detection=peak,aformat=dblp,areverse,silenceremove=start_periods=1:start_duration=1:start_threshold=-60dB:detection=peak,aformat=dblp,areverse" -v quiet -y $temp1
  13. #step 2 tronca e sfuma
  14. len=$(ffprobe -show_entries stream=duration -of default=noprint_wrappers=1:nokey=1 -v quiet $temp1)
  15. len=${len%.*}
  16. if [ $len -gt $(($secmax + $sectol)) ];
  17. then
  18. echo "Tronco e sfumo"
  19. ffmpeg -i $temp1 -to $secmax -af "afade=t=out:st=$(($secmax - $secfad)):d=$secfad" -v quiet -y $temp2
  20. rm $temp1
  21. mv $temp2 $temp3
  22. else
  23. mv $temp1 $temp3
  24. fi
  25. #step3 normalizza
  26. echo "Normalizzo"
  27. #ffmpeg -i $temp3 -af loudnorm -v quiet -y $tempx
  28. ffmpeg-normalize -q -f $temp3 -c:a aac -o $tempx
  29. rm $temp3
  30. mv $tempx "$2"