Archive for the ‘playlist’ Category

Edit: New version uses multiple parallel processes for huge performance gain on dual/multicore processor systems, and on single core systems it’s recommended to run the new version with “PROCESSES=2” (see below) for proportionately similar benefit.

foma: [f]lac [o]gg [m]p3 [a]ac

foma will convert any audio track (or the audio track from a video file) to any of Ogg Vorbis, MP3, Flac, or M4A. It writes the tags to the new files. You can choose to convert the files in situ, or to output them to a different directory. It never overwrites any audio file. If you input files it will convert the files ; if you input a directory it will create a new identically named directory (either as a nested subdirectory, or to your specified output destination) and then find and convert all the contained audio files to the new directory, writing the metadata and also an extended .m3u playlist, and copy over any images. Optionally it will then run replaygain on the new directory. foma can handle multiple files or directories, or a mix of files and directories, as input. It’s very easy to use as a simple command, or as an -exec or -execdir find command, or as file manager context menu item/custom action.

foma never overwrites your existing audio or image files (it will overwrite .m3u files). If any target conversions already exist then they are skipped and a log appended to ~/foma.log.

foma script is short, modular and well commented so you can easily understand what it does and why. It’s simple to add, remove or modify encoders or taggers. For example you might prefer to completely remove calls to Nero’s proprietary tools, or perhaps add musepack or wavpack encoding and tagging.

Q: Why not just use ffmpeg without calling external encoders?

A: ffmpeg is great for decoding audio and grabbing metadata but it doesn’t support all encoders, or all the options of each supported encoder, and it can have trouble writing tags with some formats. For example my installed version of ffmpeg loses all metadata at the writing stage on converting from ogg (libvorbis) to m4a (libfaac), though flac to m4a works fine. With some formats you might find that writing some metadata fields you want to use is unsupported and the data has been discarded.

I also want to strip replaygain data when converting to a lossy format because almost every lossy codec slightly raises the levels*. Not only does this render the copied replaygain data inaccurate, on a few tracks this will take a brickwall loudness mix into clipping.

By using ffmpeg to decode to PCM WAV then it’s possible to use any encoder that can read from STDIN or a named pipe. In this case it means neroAacEnc is scripted for automated/batch conversions but you could just as well do the same with whatever new encoder comes along, or with other encoders which are unsupported or incompletely supported in free software operating systems (ape and tak come to mind).

Q: Isn’t this an awful lot slower than just using ffmpeg or oggenc or whatever?

edit: following was for the original script. foma is now massively faster than ffmpeg or oggenc or any other script or application which doesn’t run multiple parallel decode/encode processes.

A: Even with the extra metadata handling this script completes (on my 32-bit Debian stable system) almost as quickly as performing the same conversion with the ffmpeg binary; the time penalty is only about 5%). I was also surprised to find that this script can be faster than the K.I.S.S** solution, for example `oggenc -q 4 file.flac` is slower than `foma file.flac` every time. ***On a less positive note if I perform the same conversion on the same machine running Windows XP SP3 32-bit using foobar2k as a frontend for oggenc.exe then the conversion takes only about 70% of the time as ffmpeg in Debian (edit: I had another look at this and foobar achives its good performance by running two processes in parallel; the Windows oggenc binaries don’t really perform any differently to those compiled using GCC, so the following sentence is redundant). It may finally be time to head over to http://funroll-loops.info or http://www.microsoft.com and bow down before the power of the teenagers||greysuits…..

*The only lossy format I’ve encountered which has no effect on the levels is lossy/hybrid wavpack but for compatibility and convenience reasons it’s not a codec I use for lossy compression.

**UNIX mantra: Keep It Simple, Stupid!

***No longer true. New foma with parallel processes now easily outperforms other methods in Debian and in Windows XP.

I couldn’t find a satisfactory command line method to create extended .m3u playlists in Debian. The best is a perl script extm3u.pl which you can find at http://www.splitbrain.org/projects/extm3u. It’s really good and very quick but only supports mp3, ogg and flac files. I modified it to also support mp4/m4a and submitted a patch but the author wasn’t interested enough to respond. In any case I want a tool that will support numerous audio formats so I wrote a bash script which uses normal GNU utilities such as awk and bc along with ffprobe (part of ffmpeg) and consequently can write an extended .m3u for any files that (your installed version of) ffmpeg supports. The script can be found at http://pastebin.com/wPXZuPrU

20 March 2013: New version at http://pastebin.com/dfifNv3z supports opus codec files and has a fix for problem with wrong track duration (introduced by recent changes in ffmpeg/ffprobe)
21 April 2014: New version at same link as above, now works with locales which use , for decimal divider. Thanks to Tina Keil.