trimaudio.sh 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #!/bin/sh
  2. secmax=240 #max length
  3. sectol=15 #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. 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
  12. #step 2 tronca e sfuma
  13. len=$(ffprobe -show_entries stream=duration -of default=noprint_wrappers=1:nokey=1 -v quiet $temp1)
  14. len=${len%.*}
  15. if [ $len -gt $(($secmax + $sectol)) ];
  16. then
  17. ffmpeg -i $temp1 -to $secmax -af "afade=t=out:st=$(($secmax - $secfad)):d=$secfad" -v quiet -y $temp2
  18. rm $temp1
  19. mv $temp2 $temp3
  20. else
  21. mv $temp1 $temp3
  22. fi
  23. #step3 normalizza
  24. #ffmpeg -i $temp3 -af loudnorm $tempx
  25. ffmpeg-normalize -q -f $temp3 -c:a aac -o $tempx
  26. rm $temp3
  27. mv $tempx "$2"