Skip to content

Instantly share code, notes, and snippets.

@donnaken15
Last active July 14, 2023 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donnaken15/6e4c942aefbf09b1ba7653d200ec908e to your computer and use it in GitHub Desktop.
Save donnaken15/6e4c942aefbf09b1ba7653d200ec908e to your computer and use it in GitHub Desktop.
#!/bin/zsh
echo why did i make this
offset=679074
end=9382322
srate=48000
#resamp=40000
offset=$(evl $offset.0/$srate) # to seconds
end=$(evl $end.0/$srate) # to seconds
len=$(evl $end-$offset)
# beat points to get a narrowed down BPM
set -- 679075 742471 805674 869067 932278 \
995603 1058917 1122208 1185451 1248846 \
1312055 1375381 1438637 1502034 1565242 \
1628567 1691879 1755172
j=0
k=0
a=0
for i in "$@"; do
if [ $j -gt 0 ]; then
a=$(($a+$i-$k))
fi
k=$i
j=$((j + 1))
done
avgl=$(evl $a.0/$(($j-1))/$srate)
cutoff=15 # stop skipping for the last X amount of beats
bcount=$(printf "%.0f" $(evl \(\($len/$avgl\)/2\)-$cutoff))
ffmpeg -hide_banner -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=48000 -f wav -t 0.0001 tmp2.wav -y 2>/dev/null
pcm=$(ffmpeg -hide_banner -i main.opus -ss $offset -to $end -f wav -)
i=0
while [ $i -ne $bcount ]; do
ffmpeg -hide_banner -i pipe: -ss $(evl $avgl\*\($i\*2\)) -t $avgl tmp1.wav -y 2>/dev/null <<< $pcm
ffmpeg -hide_banner -i tmp2.wav -i tmp1.wav -filter_complex "[0:a][1:a]concat=n=2:v=0:a=1" tmp3.wav -y 2>/dev/null <<< $piece
echo length: $(sox --i -D tmp3.wav), position: $(evl $avgl\*\($i\*2\)), $((i + 1)) \< $bcount
rm tmp2.wav
mv tmp3.wav tmp2.wav
i=$((i + 1))
done
# there needs to be ways to pipe this stuff without needing to write a bunch of files
ffmpeg -hide_banner -i pipe: -ss $(evl $avgl\*\($i\*2-1\)) -to $end tmp4.wav -y 2>/dev/null <<< $pcm
ffmpeg -hide_banner -i tmp2.wav -i tmp4.wav -filter_complex "[0:a][1:a]concat=n=2:v=0:a=1" LCC_wesleys_cut.wav -y 2>/dev/null <<< $piece
rm tmp*.wav
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment