Site Map - skip to main content - dyslexic font - mobile - text - print

Hacker Public Radio

Your ideas, projects, opinions - podcasted.

New episodes Monday through Friday.


Our hosting is kindly provided by Josh from AnHonestHost.com. We would appreciate it if you could donate to help reduce his costs in funding the hosting.
He is also accepting bitcoins to 1KsxJr9HtsdaUeU7yaV9bk9bQi21UPBtUq

hpr1952 :: Time now Ladies and Gents

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

<< First, < Previous, Latest >>

Host Image
Hosted by Ken Fallon on 2016-01-26 is flagged as Clean and is released under a CC-BY-SA license.
Listen in ogg, spx, or mp3 format. | Comments (1)

Part of the series: 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 http://hackerpublicradio.org/eps/hpr1952.html


Comments

Subscribe to the comments RSS feed.

Comment #1 posted on 2016-01-28T16:09:26Z 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 P in HPR stand for ?
Are you a spammer →
Who hosted this show →
What does HPR mean to you ?