MP3 Audio CD Burning

Miles Keaton mileskeaton at gmail.com
Wed Sep 8 01:41:15 PDT 2004


On Tue, 7 Sep 2004 22:25:02 -0500, Brian Finniff
<brianfinniff at unixforge.org> wrote:
> Is it possible to burn a CD from an .MP3 file? If so, how would I do that?


You need to install sox:
cd /usr/ports/audio/sox ; make install clean

Then I wrote this little PHP script that seems to work well:

# go through each file in directory
$d = dir($directory);
while($file = $d->read())
        {
        # switch file extention (mp3, wav, flac)
        $ext = substr(strrchr($file, '.'), 1);
        $file = shellescape($file);
        switch($ext)
                {
                # lame + sox  to decode mp3
                case 'mp3':
                        $cmd = 'lame --decode ' . $directory . $file .
' ' . $directory . $file . '.wav';
                        exec($cmd);
                        $cmd = 'sox ' . $directory . $file . '.wav -t
raw -s -w -c 2 ' . $directory . $file . '.raw';
                        exec($cmd);
                        $cmd = 'rm ' . $directory . $file . '.wav';
                        exec($cmd);
                        break;
                # flac + sox to decode flac
                case 'flac':
                        $cmd = 'flac --decode ' . $directory . $file .
' -o ' . $directory . $file . '.wav';
                        exec($cmd);
                        $cmd = 'sox ' . $directory . $file . '.wav -t
raw -s -w -c 2 ' . $directory . $file . '.raw';
                        exec($cmd);
                        $cmd = 'rm ' . $directory . $file . '.wav';
                        exec($cmd);
                        break;
                # wav is ready to sox
                case 'wav':
                        $cmd = 'sox ' . $directory . $file . ' -t raw
-s -w -c 2 ' . $directory . $file . '.raw';
                        exec($cmd);
                        break;
                }
        }
$d->close();

# list them in order, to make burncd command-line
$rawfiles = shell_exec('ls -l1 ' . $directory . '*.raw');
$filenames = explode("\n", trim($rawfiles));
# escape 'em all
foreach($filenames as $key=>$value)
        {
        $filenames[$key] = shellescape($value);
        }
print_r($filenames);

# burn (and eject)
$cmd = 'burncd -dne -f /dev/acd0c -s max audio ' . join(' ', $filenames);
exec($cmd);


More information about the freebsd-questions mailing list