<p>In the show "<a href="https://hackerpublicradio.org/eps.php?id=1943">hpr1943 :: HPR AudioBook Club 11.5 - Interview with David Collins-Rivera</a>" <a href="https://hackerpublicradio.org/correspondents/0128.html">pokey</a> asked if there was a way to get the duration for media. The following three options springs to mind immediately.</p>
<p>The first option is <a href="https://gitlab.anhonesthost.com/davmo/fix_tags">fix_tags</a> and was written by our own <a href="https://hackerpublicradio.org/correspondents/0225.html">Dave Morriss</a>.</p>
<pre><code>$ date --utc --date="@$(echo $(fix_tags *mp3 *ogg 2&gt;/dev/null | \
awk -F '\\(|\\)' '/length/ {print $2}' | \
sed 's/ sec//g' ) | \
sed 's/ /+/g' | bc )"  +"%T"
03:09:49
</code></pre>
<p>Next up is <a href="https://mediaarea.net/en/MediaInfo">mediainfo</a> which provides a lot of information on media files.</p>
<pre><code>$ 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
</code></pre>
<p>The last option is to use <a href="https://ffmpeg.org/ffprobe.html">ffprobe</a> from the ffmpeg team.</p>
<pre><code>$ date -ud @$(echo $(for i in *mp3 *ogg;\
do  \date -ud 1970-01-01T$(ffprobe -i $i 2&gt;&amp;1 | \
grep Duration | awk '{print $2}'| \
sed 's/,//g' ) +%s;done) | \
sed 's/ /+/g' | bc)  +"%T"
03:09:49
</code></pre>
<p>For complete shownotes <a href="https://hackerpublicradio.org/eps/hpr1952/hpr1952/hpr1952.html">please click here.</a></p>
