Burn an Audio CD - Ubuntu 18.04

How to use the cdrecord utility to burn MP3 files to an audio CD

by Hadley Bradley

Twice a week, I have a long commute of around 200 miles, and to make the journey bearable I listen to several podcasts. However, the CD player in my car doesn’t support playing MP3 files directly. I wrote Bash script which burns the first 80 minutes of each podcast on to a CD

To achieve this you will need the following Linux command line utilities, most Linux distributions will have these programs in their repositories. First you’ll need cdrecord to actually burn the podcast to a CD-RW. The mpg123 program is used to convert the original MP3 file into a WAV file. Finally, we use the sox utility, to extract the first 80 minutes of audio, so that it will fit onto a standard CD-RW disk.

Finding the SCSI bus ID of your CD-RW drive

To use the cdrecord command to burn a file to the CD-RW, you will need to find out the SCSI bus ID of your CD-RW drive. By issuing the -scanbus switch, you can obtain a list like the one shown below. In this example, my CD-RW drive’s ID is 0,1,0 - which I’ll use later in the recording process.

cdrecord -scanbus

    0,0,0     0) *
    0,1,0     1) * HL-DT-ST DVD-RW GWA-4082N CC15 Removable CD-ROM
    0,2,0     2) *

Converting the MP3 and trimming the audio to 80 minutes

The following command line, will convert the file input.mp3 to a WAV file called output.wav

mpg123  --rate 44100 
        --buffer 3072
        -w output.wav input.mp3

We then use the sox command, to trim or extract the first 80 minutes of audio by specifying the start location of zero and an endpoint of 80:00. The resulting file will be called cd.wav. If the first ten minutes of the podcast is just idle chatter or adverts, then you can trim from 10:00 to 90:00 thus grabbing eighty minutes of content.

sox output.wav cd.wav trim 0 80:00

Blanking the CD-RW and burning the audio file to disk

Before we burn the cd.wav file to the CD-RW, we first need to erase the contents of the disk to end up with a blank disk. Here we need to pass in the device ID of the drive, which we determined by using the scanbus command earlier.

cdrecord -silent blank=fast dev=0,1,0

Now that we have a blank disk we can burn the file cd.wav to the CD. In this command we specify the write speed of the drive (32) and tell the command to eject the CD when finished.

cdrecord dev=0,1,0 
         -audio cd.wav