Skip to content

Instantly share code, notes, and snippets.

@ryanfb
Last active June 12, 2020 14:33
Show Gist options
  • Save ryanfb/6bc0f62c123c5fd9441d6d91db5ba8d8 to your computer and use it in GitHub Desktop.
Save ryanfb/6bc0f62c123c5fd9441d6d91db5ba8d8 to your computer and use it in GitHub Desktop.
Set MP3 id3v2 duration from actual MP3 duration
#!/bin/bash
for i in *.mp3; do
duration=`echo "$(( $(sox "$i" -n stat 2>&1|fgrep 'Length'|cut -d':' -f2|xargs) * 1000 ))"| awk '{printf("%d\n",$0+=$0<0?0:0.9)}'`
echo "$i: $duration"
id3v2 --TLEN "$duration" "$i"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment