#!/usr/bin/env bash if [[ $# -lt 1 || $# -gt 2 ]]; then echo "Usage: $0 " exit 1 fi if [ ! -f $1 ]; then echo "$1 is not a file" fi file=$1 sep=$2 FFMPEG="docker run -ti --rm -v $(pwd):/data -w /data linuxserver/ffmpeg -hide_banner -loglevel error" FFPROBE="docker run -ti --rm -v $(pwd):/data -w /data --entrypoint ffprobe linuxserver/ffmpeg" CLIP_LEN=60 audio_len=$($FFPROBE -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 $file | tr -d '\r\n' | sed 's/\..*$//') max_start=$(expr $audio_len - $CLIP_LEN) # first make a bunch of 60s clips with random start positions echo "Making the clips" for i in {0..59}; do echo -n "$i " rand_start=$(($RANDOM % $max_start)) outfile="clip-$i.wav" $FFMPEG -ss $rand_start -t 60 -i $file $outfile done echo # next loop over those clips and shrink them appropriately echo "Adjusting tempo" for i in {1..59}; do echo -n "$i " outfile="clip-$i.wav" infile="_$outfile.tmp" mv $outfile $infile tempo=$(echo "1 + (0.02 * $i)"| bc) $FFMPEG -i $infile -filter:a "atempo=$tempo" -vn $outfile rm $infile done echo # stitch em together # Using a file here because i need to access it in docker echo "Stitching them together" >_concat for i in {0..59}; do echo "file clip-$i.wav" >>_concat [ "$sep" != "" ] && echo "file $sep" >>_concat done $FFMPEG -f concat -safe 0 -i _concat -c copy powerhour.wav