I keep my entire CD collection backed up on my server in FLAC (free lossless audio codec) format. This is partly so that I have a backup if my CDs get damaged beyond repair, and so that I can stream it around the house (thereby avoiding using the CDs at all while at home). Now I wanted a way of converting these files to mp3 or ogg vorbis, so that I could use them in my mp3 player, or to make it easier to carry around (e.g. when going on holiday, I like to use ogg vorbis so that I can fit more songs in a smaller space).
So I made this script which will recursively go through directories and convert any FLAC files to mp3, ogg vorbis, or FLAC.
Yes, it will convert FLAC to FLAC. The reason for this is that some media players which support FLAC, only support up to compression level 2, anything higher they will not be able to play. I store my music with compression-level 8 because it makes most efficient use of space, but cannot be played back on portable players. Those of you with FLAC capable players can use this script to convert all your FLACs to compression level 2 for playback (my player is fine with level 8, so I don't use this option really).
This script will also copy over metadata tags from the FLAC file to the new files. So that you get Album,title,tracknumber, comments and other tags transferred as well.
My goals for this project was to perfect the conversion of FLAC to MP3/OGG/FLAC, including proper tagging of converted files. With time (and requests from others) more codecs were added, and with that the name was changed to "flac2all", so that the future script can encompass any and all formats that people desire :-) (also, it fitted in with the trend to name these programs flac2$x, like flac2mp3, etc...)
Woah... 2017! I started this program as a personal project back in 2003, while I was still a bushy eyed student. In 2006 (primarily due to badgering by friends who really wanted a copy) I released it to the public. 11 years and 3 rewrites later, it is still going strong. While not mainstream, I think it is my most popular OSS project. Quite something :-)
Google code has shut up shop (Google pulling the plug on a service!? Quelle surprise) , and as such I have moved over to github. You can find the project page here:
Due to the fact the hosting providers come and go with time, I figured I will keep my site as the main point source, from where you can find out what the current hosting provider is.
Hopefully the 4th rewrite (version 4) will be ready for beta testing shortly. It would have been nice for it to have been ready for the 10th anniversary of the first publicly downloadable script (if you are so inclined, you can actually find v1 at the bottom of this page), but life got in the way (amazing how getting a full time job kills your hobbies).
Anyway, I have been using v4 exclusively for a while now, and it works for me (tm), so time for other people to break it a bit :-)
Well, been working on the scripts some more. Bug fixes, etc...
Made a silly mistake, as I disabled multithreaded encoding on the stable script and forgot to disable it when committing to SVN. As a result got emails asking why the multithreading script wasn't working, sorry everyone! :)
As for the development branch. That is coming along nicely. Soon it should be possible to throw out a beta for testing. Stay tuned if you want to have a go with the new program! :)
Also, please note that I will no longer be updating this project page. Unless something changes in future, all updates will be on the google code page:
And you can keep up to date on the freshmeat page:
Of course, if any of you are happy to help (even if it is just writing documentation) it would be appreciated. My free time is becoming more and more limited as I move out of student life and into the "real world" with job etc... commitments :/
New version in development!! v1.3 is in progress. If anyone wants to help or have any ideas for inclusion, contact me :)
When I have a working dev version I'll post it here.
Well, this project now has it's own Freshmeat page!
The program also has a new feature. Copying of non-flac files. Some of you emailed me asking if it would be possible for the program to copy over non-flac files (at the moment it just ignores them). The idea being to allow for things like Album-art, cuefiles etc... to be copied over during the conversion.
Revision 1.2.717 now supports this feature. It's rudementary at the moment, but it works! You can download this release from the Freshmeat page or via this direct link.
Let me know if any bugs have crept into this version (all the last revisions have been bug fixes, and the program has been stable for quite some time now).
Well would you believe it. Dreamhost manged to fail again, and (yet again) replaced the download with the faulty version that should never have seen the light of day (well done people). They also managed to lose my last few news updates, so I'm writing this one to just let you all know that there has been movement since almost 1 year ago, and that the script is pretty much stable (we are at version 1.2.624 now).
I've had reports of it running excellently on dual and quad core (and 8 core!) machines with full utlisation and no problems, all good! I've re-uploaded the latest version once again. Get it quick before dreamhost decides to be a pain! ;)
Note: You can check if your script is faulty by the second or third line in the source. If it says "TO BE BINNED" then by all means heed the warning and contact me, so that I can re-correct the mistake (this has happened many times, I suspect it will happen many more as well).
Version 1.2.160 is up! This version finally reimplements ogg vorbis conversion (this was removed to be refactored for multithreading). Now I'm having a go re-encoding my collection for vorbis with 2 encoding threads. So far so good. As all the major parts and now implemented and functioning, I think I can move this program from "alpha" to "beta" status. With more refinement and testing it should be ready for a stable release soon!
I have also fixed a couple of silly bugs that were in the previous version, if there any further issues contact me!
Contrary to what some people think, this project has not been abandoned. Development has slown as my real life (and other projects) take up time, but work has continued. In that vain I announce that the new version is up! The biggest change to this one is the inclusion of multithreading, allowing for multiple files to be encoded simultaniously.
You can specify how many files to encode at once with the "threads" variable. The script is set by default to run two encoding threads, which totally saturates my AMD X2 machine. If you have more cores/cpu's, just increase the value of "threads" to match the number of cores you have.
At the moment the script is re-encoding my FLAC collection to mp3 (~2700 files) using two encoding threads on my dual-core AMD, with no problems, but more testing is needed (I shall update this page with the results when it is done).
Update: System succesfully converted all the music! Next I'm going to try converting all of them to vorbis.
Note: Some people have emailed me saying that the script segfaults after a while (especially when doing lots of files). If this happens to you please let me know (I suspect a memory leak, as I have Gigs of RAM of machine I don't notice).
New version is up!. This version has FLAC to ogg vorbis support, and I have split the code into classes. Things to do for the next version include flac2flac support, code cleanup (especially cross-class calling, and making the script more multi-threading-friendly).
The script has been tested on my collection, and successfully managed to encode everything (~ 1500 files) to ogg vorbis, with full tags. So it's looking good so far.
The below is no longer valid. All usage/documentation can be found on the projects official code repository (mentioned above)
Once you've installed the script (see below), you have two choices for running it:
You can make the file executable, with the command “chmod u+x /path/to/file” and then run it like any other script.
You can run it as is, using “python /path/to/file”directly.
Whichever way you do it, you will be greeted with the following:
You only have two options, [convert type] and [input dir].
You state what you want to convert to, and the directory you want to convert in like this:
convertaudio.py mp3 /flac/
And it will go into all the folders within, and create an exact copy in the current directory except in mp3 format.
So if we had:
/flac/album1/song1.flac /flac/album2/cd1/song2.flac /flac/album2/cd2/song3.flac /flac/random_song.flac
We would end up with:
./flac/album1/song1.mp3 ./flac/album2/cd1/song2.mp3 ./flac/album2/cd2/song3.mp3 ./flac/random_song.mp3
Understand? Good. There is not much else to it =).
This script depends on:
FLAC command line program (including supplementary progs,e.g. metaflac)
LAME command line program
These programs should ideally be available in your PATH variable, if they are not, then edit the script where the path variables are, and place the path there (see below).
I wrote this program in such a way so that it can be used "out of the box" with minimum configuration. Of course, this will not always be the case. For example, you may want different settings for your encoder, so the beginning of the script contains variables which you can edit.
They look like this:
The comments pretty much explain what each variable does. If your programs are available via your $PATH variable, you should not need to modify any *path variables. The *opts variables are of interest though, as they decide what parameters to use with the encoders. As it stands they are set to my requirements, but you can modify them to your liking.
For an overview of what options are available, look at the programs themselves (-h or man files).
"outdir" is useful if you want to save your converted files to a different directory. And the "overwrite" option decides whether or not we should overwrite existing files (by default files are not overwritten).
Currently this program is beta. Most of the basics work but it still needs refinement.
This program will encode to mp3 and ogg vorbis with tags, but there are a few bugs:
the character “ ` ” is unsupported (for single use, e.g. /path/don`t_play_me.flac will not work), this seems to be limitation in the shell, still thinking of a workaround
certain international characters do not work (this seemed to be a filesystem issue with me, but not sure, needs more testing)
Currently there is no way for the script to tell if the disk is full, in which case the script fails with an error.
unlike vorbis tags (used in flac and ogg) where the 'genre' field can contain anything, mp3 tags have a list of genres that they can accept. so for example it your flac genre is "latin jazz" the mp3 encoder will fail with an error in the genre (as 'latin jazz' in not in the mp3 list). there is no way of fixing this 'bug' as it is a limitation of the mp3 standard rather then this script. This has been fixed (using a whitelist of accepted genres by LAME, and those that don't fit get put into the "Other" genre).
A rather limited workaround involves basically removing the code that writes the genre tag, or changing the tags on your flac file(s). Future developments probably will include a list of "acceptable" genres, and upon that we can decide what to do with the genre tag
Unfinished things to do (in order of importance) in current version before a stable release (including fixing the bugs above):
clean up the code (it is very messy), I will probably split it into classes (or for each codec, and the main one). This will also make it easier to manage the code and add other codecs.
Things to do for the next version:
S ee if I can speed up the process (possibly using multi-threading). Kind of goes with the above.
FLAC testing, while works, is not very advanced (currently it's a wrapper for the "flac -T" command). In the future I would like to develop something more advanced, to allow for features like logging to a file (very useful when wanting to check a few thousand files) and listing of full paths of erronous files.
Possible future developments:
Deprecate use of os.popen in favour of direct python bindings to the codecs. This should help portability quite a bit (as it will no longer rely on the shell). But then it will require the script to be built against the source of the codecs.
Saying that, FLAC to mp3 has been extensively tested by me on Linux (Gentoo 2.6, converting my collection, close to 1500 files) so FLAC to MP3 encoding should be ready for external testing, feel free to test it and send your results to me (especially if you are not using Linux, as I have not tested it on other OSs).
This being a GPL project, you are free to modify/fix the code as defined in the GPLv2 license, here we explain how to create patches. If you modify the code, and you call it convertaudio.new.py for example, to create a patch you need the "diff" command:
user@system~$ diff ./convertaudio.py ./convertaudio.new.py > name.patch
This will give you a patch called "name.patch"; which you can email to me (look under the contact page), and it will either be incorporated into the official code (if it is part of this project's goals at that point in time) or placed here as an optional patch for download.
Let's say you have a patch (either from this site or from somewhere else) you can apply it to the code like this:
user@system~$ patch -p0 ./convertaudio.py < ./name.patch
Note that if it does not work. Do not email me straight away. First try with the official unpatched code, if the unpatched code does work then talk to the patch creator about support. If the problem persists, then you can contact me, with the error message that is shown (on the unpatched version).
Currently the script has only been tested on Linux systems. It should work on other Unix and Unix-like OSs (which have the bash shell and fill the requirements) but it has not been tested by me. If you do run it on another Unix system, let me know whether it works or not!
As to whether it works on Windows, I don't know. It should work under cygwin with the proper paths for the executables set, and if anyone tries (under cygwin or not), send me your results.