Breaking Eggs And Making Omelettes

Topics On Multimedia Technology and Reverse Engineering


Sega CD Ripper

March 27th, 2007 by Multimedia Mike

I’ve started to plunder my stash of Sega CD games for my Gaming Pathology project. To run the games with the Gens emulator under Windows it is necessary to either install ASPI drivers for accessing the game CD-ROMs in a particular manner, or rip the data and audio tracks into a particular filename sequence in order to play them directly from the hard disk. Since I couldn’t make the former work on my new machine, I proceeded with the latter option.

Sega CD unit

Gens wants the data track, i.e. ISO-9660 CD-ROM filesystem, as ‘title.iso’. Any redbook CD audio tracks after the data track need to be in the same directory, compressed as MP3, and named as ‘title 02.mp3’…’title nn.mp3’. After performing the process more or less manually for Revengers of Vengeance (I automated some parts, but had to manually rename the files in the end, and RoV has 44 audio tracks), I wrote a Python script to help me with other games (and I’m not very good at Python yet but I like these opportunities to learn).

There might be other ways, better ways, but this is my new way. The script relies on cdparanoia and LAME (oh, and dd and rm). I didn’t know any program to query a CD to learn how many audio tracks it had (except my own hacked up program and I didn’t feel like leveraging it), so I just perform a rip loop until cdparanoia returns an error. LAME is instructed to encode at its ‘insane’ profile, sparing no bitrate. Syntax is ‘./ “game title”‘ which will produce an ISO file and a series of MP3 files if redbook audio is present:

$ ./ "Revengers Of Vengeance"
ripping Revengers Of Vengeance
ripping data track...
/bin/dd if=/dev/cdrom of="Revengers Of Vengeance.iso"

ripping audio tracks...
/usr/bin/cdparanoia --quiet 2
/usr/bin/lame --quiet --preset insane cdda.wav "Revengers Of Vengeance 02.mp3"
/bin/rm cdda.wav

[...repeated for each redbook CD audio track...]
  1. #!/usr/bin/python
  3. import os
  4. import commands
  5. from sys import argv
  7. # programs
  8. SOURCE_DRIVE = "/dev/cdrom"
  9. DD_COMMAND = "/bin/dd"
  10. CDPARANOIA_COMMAND = "/usr/bin/cdparanoia --quiet"
  11. LAME_COMMAND = "/usr/bin/lame --quiet --preset insane"
  12. RM_COMMAND = "/bin/rm"
  14. if (len(argv) < 2):
  15.     print "USAGE: <title>"
  16. else:
  17.     title = argv[1]
  18.     print "ripping " + title
  20.     # rip ISO-9660 filesystem in the first track
  21.     data_rip_command = DD_COMMAND + " if=" + SOURCE_DRIVE + " of=\"" + title + ".iso\""
  22.     print "ripping data track..."
  23.     print data_rip_command
  24.     commands.getstatusoutput(data_rip_command)
  25.     print
  27.     # rip CD audio tracks -> MP3 files until cdparanoia reports an error
  28.     print "ripping audio tracks..."
  29.     n = 2
  30.     error = 0
  31.     rm_command = RM_COMMAND + " cdda.wav"
  32.     while (error == 0):
  33.         # rip
  34.         audio_rip_command = '%(cmd)s %(n)d' % \
  35.             { 'cmd': CDPARANOIA_COMMAND, 'n' : n }
  36.         print audio_rip_command
  37.         commands.getstatusoutput(audio_rip_command)
  39.         # encode
  40.         audio_encode_command = '%(cmd)s cdda.wav "%(title)s %(n)02d.mp3"' % \
  41.             { 'cmd' : LAME_COMMAND, 'title' : title, 'n' : n }
  42.         print audio_encode_command
  43.         if (commands.getstatusoutput(audio_encode_command)[0]):
  44.             error = 1
  46.         # cleanup
  47.         print rm_command
  48.         commands.getstatusoutput(rm_command)
  50.         n = n + 1
  51.         print

Posted in Game Hacking, Python | 5 Comments »

5 Responses

  1. yoshi314 Says:

    you can use bin2iso to create a cuefile from a cdrom device. it’ll get printed to stdout.

    not sure if it’s a reliable solution though :]

  2. Cyril Says:

    It’s not strictly necessary to use a dict when formatting strings in Python. For example, line 34 can also be done like this:

    audio_rip_command = ‘%s %d’ % (CDPARANOIA_COMMAND, n)


  3. Multimedia Mike Says:

    Thanks much for that tip, Cyril. I thought that the method I learned from the Python manual seemed unnecessarily complex.

  4. Brief Reviews of Several Sega CD Games | Gaming Pathology Says:

    […] Sega CDs in a format suitable to play from the hard disk using the Gens emulator. You can find the Sega CD ripping script on my more technical blog. So I spent a bunch of time ripping games to the hard drive and concentrating on collecting […]

  5. Jean-Christophe VASSORT » Backup de jeux MegaCD Says:

    […] un petit script python trouvé sur cette page permettant de faire un backup d’un jeu du MegaCD de […]