Thanks, Eric! It's exactly what I needed.
I was familiar with sox, to a reasonable degree, but somehow had missed
soxi. I suspect soxi and I are going to be good friends, especially when
I find the Fedora package to provide mp3 support.
Thanks again!
Janina
Eric Wong writes:
Janina Sajka <janina(a)rednote.net> wrote:
Hi,
I need to calculate the total playing time of the audio files in a
particular folder. These are variously encoded--flac, ogg, and even some
mp3.
Anyone know how to do this, preferably from the cli? Or, perhaps one of
the music player apps can provide this datum for a folder?
I like using soxi from sox. The following should get you started:
(but do not run shell commands without understanding them :)
find \( -iname '*.flac' -o -iname '*.mp3' -o -iname '*.ogg' \)
-print0 | \
xargs -0 soxi
The find(1) invocation above searches for files with flac, mp3, and ogg
suffixes case-insensitively (-iname) wrapped inside the quoted '()' for
grouping via '-o' ("or").
-print0 in find pairs with the -0 in xargs so it can deal with shell-unfriendly
characters without breaking.
Finally the soxi(1) command does the grunt work of handling all the
command-line arguments for each supported filetype. You can also
parse and sum the time with the output of "soxi -D" instead of just
"soxi" (which shows output in a human-friendly format).
On Debian-based systems, you'll probably want install sox with all the
formats supported: apt-get install sox libsox-fmt-all
See the section 1 manpages for soxi, find, and xargs for more options
and possibilities.
--
Janina Sajka, Phone: +1.443.300.2200
sip:janina@asterisk.rednote.net
Email: janina(a)rednote.net
Linux Foundation Fellow
Executive Chair, Accessibility Workgroup:
http://a11y.org
The World Wide Web Consortium (W3C), Web Accessibility Initiative (WAI)
Chair, Protocols & Formats
http://www.w3.org/wai/pf
Indie UI
http://www.w3.org/WAI/IndieUI/