trimaudio.sh 837 B

1234567891011121314151617181920212223242526
  1. #!/bin/sh
  2. secmax=240
  3. secfad=5
  4. temp1=/tmp/$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1).m4a
  5. temp2=/tmp/$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1).m4a
  6. #step 1 rimuove il silenzio
  7. 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
  8. # step 2 tronca e sfuma
  9. len=$(ffprobe -show_entries stream=duration -of default=noprint_wrappers=1:nokey=1 -v quiet $temp1)
  10. len=${len%.*}
  11. if [ $len -gt $secmax ];
  12. then
  13. ffmpeg -i $temp1 -to $secmax -af "afade=t=out:st=$(($secmax - $secfad)):d=$secfad" -v quiet -y $temp2
  14. mv $temp2 "$2"
  15. rm $temp1
  16. else
  17. mv $temp1 "$2"
  18. fi