trimaudio.sh 1007 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/bin/sh
  2. secmax=240
  3. secfad=5
  4. #wav is faster
  5. temp1=$(mktemp /tmp/playlistalo.XXXXXXXX.wav)
  6. temp2=$(mktemp /tmp/playlistalo.XXXXXXXX.wav)
  7. temp3=$(mktemp /tmp/playlistalo.XXXXXXXX.wav)
  8. tempx=$(mktemp /tmp/playlistalo.XXXXXXXX.m4a)
  9. #step 1 rimuove il silenzio
  10. ffmpeg -i "$1" -to $(($secmax + 15)) -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
  11. #step 2 tronca e sfuma
  12. len=$(ffprobe -show_entries stream=duration -of default=noprint_wrappers=1:nokey=1 -v quiet $temp1)
  13. len=${len%.*}
  14. if [ $len -gt $secmax ];
  15. then
  16. ffmpeg -i $temp1 -to $secmax -af "afade=t=out:st=$(($secmax - $secfad)):d=$secfad" -v quiet -y $temp2
  17. rm $temp1
  18. mv $temp2 $temp3
  19. else
  20. mv $temp1 $temp3
  21. fi
  22. #step3 normalizza
  23. #ffmpeg -i $temp3 -af loudnorm $tempx
  24. ffmpeg-normalize -q -f $temp3 -c:a aac -o $tempx
  25. rm $temp3
  26. mv $tempx "$2"