Site Map - skip to main content

Hacker Public Radio

Your ideas, projects, opinions - podcasted.

New episodes every weekday Monday through Friday.
This page was generated by The HPR Robot at


hpr1952 :: Time now Ladies and Gents

How to get the total duration of a lot of media files.

<< First, < Previous, , Latest >>

Thumbnail of Ken Fallon
Hosted by Ken Fallon on 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 shownote please visit https://hackerpublicradio.org/eps/hpr1952.html


Comments

Subscribe to the comments RSS feed.

Comment #1 posted on 2016-01-28 16:09:26 by Dave Morriss

Great show idea

I always enjoy shows like this. I found I either needed to be reading the notes as I listened or I needed to listen twice.

I liked the way you explained those pipelines by breaking them into their components.

Maybe the next release of 'fix_tags' should have a -sum option to sum up all the audio lengths :-)

Leave Comment

Note to Verbose Commenters
If you can't fit everything you want to say in the comment below then you really should record a response show instead.

Note to Spammers
All comments are moderated. All links are checked by humans. We strip out all html. Feel free to record a show about yourself, or your industry, or any other topic we may find interesting. We also check shows for spam :).

Provide feedback
Your Name/Handle:
Title:
Comment:
Anti Spam Question: What does the letter P in HPR stand for?
Are you a spammer?
What is the HOST_ID for the host of this show?
What does HPR mean to you?