Multi threaded FLAC to mp3/vorbis/FLAC Encoder

This page contains my script which is used for conversion of FLAC files to mp3/ogg vorbis or FLAC. Scroll to the bottom of the page for the download link.

News

Date: 03/03/12

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:

code.google.com/p/flac2all/

And you can keep up to date on the freshmeat page:

freecode.com/projects/flac2all

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 :/

Date: 21/04/11

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.

Date: 30/08/10

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).

Date: 21/02/10

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).

Date: 09/03/09

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!

Date: 30/12/08

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).

Date: 29.04.06

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.

Introduction

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.

This project's goals at this point in time is to perfect the conversion of FLAC to MP3/OGG/FLAC, including proper tagging of converted files. Of course, these goals can change, but only if there is sufficent demand (e.g. demand for conversion to AAC/mp4 format).

Usage

Once you've installed the script (see below), you have two choices for running it:

  1. You can make the file executable, with the command “chmod u+x /path/to/file” and then run it like any other script.

  2. 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 =).

Requirements

This script depends on:

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).

Configuration

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).

Status

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:

Unfinished things to do (in order of importance) in current version before a stable release (including fixing the bugs above):

Things to do for the next version:

Possible future developments:

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).

Submitting code

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.

Patching the code

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).

Download

convertaudio.py

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.