powerhour.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/env bash
  2. if [[ $# -lt 1 || $# -gt 2 ]]; then
  3. echo "Usage: $0 <filename> <separator>"
  4. exit 1
  5. fi
  6. if [ ! -f $1 ]; then
  7. echo "$1 is not a file"
  8. fi
  9. file=$1
  10. sep=$2
  11. FFMPEG="docker run -ti --rm -v $(pwd):/data -w /data linuxserver/ffmpeg -hide_banner -loglevel error"
  12. FFPROBE="docker run -ti --rm -v $(pwd):/data -w /data --entrypoint ffprobe linuxserver/ffmpeg"
  13. CLIP_LEN=60
  14. audio_len=$($FFPROBE -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 $file | tr -d '\r\n' | sed 's/\..*$//')
  15. max_start=$(expr $audio_len - $CLIP_LEN)
  16. # first make a bunch of 60s clips with random start positions
  17. echo "Making the clips"
  18. for i in {0..59}; do
  19. echo -n "$i "
  20. rand_start=$(($RANDOM % $max_start))
  21. outfile="clip-$i.wav"
  22. $FFMPEG -ss $rand_start -t 60 -i $file $outfile
  23. done
  24. echo
  25. # next loop over those clips and shrink them appropriately
  26. echo "Adjusting tempo"
  27. for i in {1..59}; do
  28. echo -n "$i "
  29. outfile="clip-$i.wav"
  30. infile="_$outfile.tmp"
  31. mv $outfile $infile
  32. tempo=$(echo "1 + (0.02 * $i)"| bc)
  33. $FFMPEG -i $infile -filter:a "atempo=$tempo" -vn $outfile
  34. rm $infile
  35. done
  36. echo
  37. # stitch em together
  38. # Using a file here because i need to access it in docker
  39. echo "Stitching them together"
  40. >_concat
  41. for i in {0..59}; do
  42. echo "file clip-$i.wav" >>_concat
  43. [ "$sep" != "" ] && echo "file $sep" >>_concat
  44. done
  45. $FFMPEG -f concat -safe 0 -i _concat -c copy powerhour.wav