hpr1952 :: Time now Ladies and Gents
How to get the total duration of a lot of media files.
Hosted by Ken Fallon on Tuesday, 2016-01-26 is flagged as Clean and is released under a CC-BY-SA license.
fix_tags, ffprobe, ffmpeg, bc, sed, awk, grep, time, iso8601, date, mediainfo, xmlstarlet.
1.
The show is available on the Internet Archive at: https://archive.org/details/hpr1952
Listen in ogg,
spx,
or mp3 format. Play now:
Duration: 00:31:00
Bash Scripting.
This is an open series in which Hacker Public Radio Listeners can share their Bash scripting knowledge and experience with the community. General programming topics and Bash commands are explored along with some tutorials for the complete novice.
In the show "hpr1943 :: HPR AudioBook Club 11.5 - Interview with David Collins-Rivera" pokey asked if there was a way to get the duration for media. The following three options springs to mind immediately.
The first option is fix_tags and was written by our own Dave Morriss.
$ date --utc --date="@$(echo $(fix_tags *mp3 *ogg 2>/dev/null | \
awk -F '\\(|\\)' '/length/ {print $2}' | \
sed 's/ sec//g' ) | \
sed 's/ /+/g' | bc )" +"%T"
03:09:49
Next up is mediainfo which provides a lot of information on media files.
$ date -ud @$(echo $(mediainfo --full --Output=XML *mp3 *ogg | \
xmlstarlet sel -T -t -m "Mediainfo/File/track[@type='Audio']/Duration[1]" -v "." -n - | \
sed 's/.\{3\}$//') | \
sed 's/ /+/g' | bc) +"%T"
03:09:49
The last option is to use ffprobe from the ffmpeg team.
$ date -ud @$(echo $(for i in *mp3 *ogg;\
do \date -ud 1970-01-01T$(ffprobe -i $i 2>&1 | \
grep Duration | awk '{print $2}'| \
sed 's/,//g' ) +%s;done) | \
sed 's/ /+/g' | bc) +"%T"
03:09:49
For complete shownotes please click here.