Convert m4b to ogg on Linux

September 23, 2008

I got my hand on some audio books in the m4b format (They are not DRM protected) and I wanted to listen to them on my mp3 player. But the m4b format is a special format for the Ipod and don’t own a Ipod (and I don’t want to own one 😉 )

As I’m a Linux user I decided to write a program which converts them to ogg (which my mp3 player supports). It should be a console program which goes recursively through a directory and its sub directories and converts all mb4 files to ogg. Of course this script does not reinvent the wheel and uses some mighty console programs for the main work. You need to have following stuff installed on your system:

  • oggenc (on Ubuntu/Debian you can it install with apt-get install vorbis-tools)
  • faad (apt-get install faad)
  • python (should be normally already installed, apt-get install python)

Download the m4b2ogg.py script and set the execute permissions. Call m4b2ogg.py -h to get a list of the possible parameters. I hope this script helps also other Linux users – if so drop a line please. Thx.

ps: If you’re searching for converting other media formats into yet an other media formats on linux, take a look at this site.

21 Comments »

RSS feed for comments on this post. TrackBack URI

  1. […] Robert Penz Blog – Python m4b to ogg conversion script. […]

    Pingback by Linux Sand Garden » Blog Archive » Python m4b to ogg conversion script — September 26, 2008 #

  2. Ok, I don’t know what you just said up there, but I can’t get it to work. I’m looking all over the internet for how to install a python script, but I’m having limited (read NO) luck and would appreciate any help you can give. Can you walk me through the process of actually installing this bugger? I’m using Linux Mint 5 (based on Ubuntu 8.04) Thanks!

    Comment by PythonNoooooob — October 10, 2008 #

  3. 1. download the file.
    2. chmod 755 m4b2ogg.py
    3. sudo apt-get install vorbis-tools faad python
    4. ./m4bogg.py -h

    Comment by robert — October 10, 2008 #

  4. Ohhh.. ok. I guess you can call me a Linux Noob, too. I’ve only been a serious user for about 6 months (even though I’ve played with it from time to time since RH7 back in 2000). I’ve got parts 1-3 successfully completed, but 4 still eludes me. :0/ I’ll figure it out.

    Comment by PythonNoooooob — October 13, 2008 #

  5. Ah HA! I figured it out! I wasn’t watching closely enough… i just copied out what you had in line 4 and forgot to match it to the files I actually have (m4b2ogg.py). Now to make it convert something! Thanks a lot Robert!

    Comment by PythonNoooooob — October 13, 2008 #

  6. Hmm.. well, it certainly worked (as far as converting to .ogg), but I thought it would also split the files into appropriate chapters. Know of one that does? I know the M4B files have the chapter markers in them… thanks for any help.

    Comment by PythonNoooooob — October 14, 2008 #

  7. ./m4b2ogg.py -h
    Traceback (most recent call last):
    File “./m4b2ogg.py”, line 29, in ?
    import subprocess
    ImportError: No module named subprocess

    Comment by needhelp — November 8, 2008 #

  8. hmm .. what python version do you have?

    subproccess is available beginning with 2.4 and thats was release released on November 30, 2004. The current version is 2.6, with a second release candidate for 3.0 already following.

    http://docs.python.org/library/subprocess.html

    Comment by robert — November 9, 2008 #

  9. Thank you! I have a plane to catch, need some entertainment on it, and this really helped.

    Comment by db — November 20, 2008 #

  10. It’s would be nice to see any kind of progresbar when program is converting media. Anyway thanks!

    Comment by Roman — December 28, 2008 #

  11. Robert, just wanted you to know that your script (clean!) worked perfectly over here (linuxmint 5). And that despite noobie entitlement issues. Really? A “progress bar”??? Good job, man and thanks.

    Comment by Flameproof — August 9, 2009 #

  12. http://www.oggconvert.com

    online tool to convert ogg files, no downloads

    works better on smaller files because it’s web based

    Comment by Chris — May 22, 2010 #

  13. You can also go too http://www.oggconvert.com/ to convert OGG files to MP3, AAC, FLAC, OGG, WMA, M4A, WAV online. I hope its big help.

    Comment by Tonya Henson — May 26, 2010 #

  14. I have oggconvert installed. I get command not found with m4b2ogg.py.

    [root@localhost brotherred]# chmod 755 m4b2ogg.py
    [root@localhost brotherred]# m4b2ogg.py
    bash: m4b2ogg.py: command not found
    [root@localhost brotherred]#

    What am I doing wrong?

    Comment by Brotherred — August 16, 2010 #

  15. you need to start it like this ./m4b2ogg.py .. otherwise linux does not start something in the current directory

    Comment by robert — August 19, 2010 #

  16. Yeah I should have known. It looks like it is working now. I did not think to set the path after the command so it looks like it is working on all the .m4b files I have, 2 and their copies. I tried a win32 program the same night I searched on this so now ./m4b2ogg.py is working on ./wine/drive_c/somefile.m4b

    Thanx to you it is working though regards

    Comment by Brotherred — August 22, 2010 #

  17. Hey, can someone help me? I have an audiobook (I guess its DRM encrypted). Anyway, bought it off I-tunes with a gift card, and it won’t sync to my Ipod, let along my Android phone. I got the script to work, but get this error at the end.

    carl@carl-workstation:~$ ./m4b2ogg.py
    converting: BeatGRE.m4b
    ERROR: Input file “(stdin)” is not a supported format

    Anyone know what I can do to fix this?

    Comment by Carl — November 4, 2010 #

  18. hmmm … call faad directly to check if it outputs an error message while processing the file.

    Comment by robert — November 4, 2010 #

  19. Thanx!!!
    ^_^ It works!
    Ubuntu 11.10

    Comment by Katyusha — October 29, 2011 #

  20. $ ./m4b2ogg.py -h
    File “./m4b2ogg.py”, line 34
    print “Info: %s already exists” % pathOgg[len(workingDir):]
    ^
    SyntaxError: invalid syntax

    Comment by anonymous — May 11, 2012 #

  21. You’re most likely trying it with python 3.x, please use python 2.x as the syntax has changed.

    Comment by robert — May 16, 2012 #

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Powered by WordPress
Entries and comments feeds. Valid XHTML and CSS. 37 queries. 0.082 seconds.