Code Monkey home page Code Monkey logo

m4b-converter's Introduction

m4b.py

This is a simple python script to convert and split m4b audio books into mp3 files.

Requirements

Installation

Windows

  1. Install python 2.7.
  2. Download ffmpeg and place ffmpeg.exe in this directory or your PATH.
  3. Download libmp4v2.dll or compile your own dll, then place it in this directory.

Ubuntu 10.10

  1. Install packages: sudo apt-get install python2.7 ffmpeg libavcodec-extra-52
  2. Download mp4v2 then compile and install.

Usage

There are two ways to use this script:

  1. Drag your .m4b file(s) onto m4b.py.
  2. Using the command line which also offers more advanced options.

Command Line Help

usage: m4b.py [-h] [-o DIR] [--custom-name "STR"] [--ffmpeg BIN]
              [--encoder BIN] [--encode-opts "STR"] [--ext EXT] [--pipe-wav]
              [--skip-encoding] [--no-mp4v2] [--debug]
              filename [filename ...]

Split m4b audio book by chapters.

positional arguments:
  filename              m4b file(s) to be converted

optional arguments:
  -h, --help            show this help message and exit
  -o DIR, --output-dir DIR
                        directory to store encoded files
  --custom-name "STR"   customize chapter filenames (see README)
  --ffmpeg BIN          path to ffmpeg binary
  --encoder BIN         path to encoder binary (default: ffmpeg)
  --encode-opts "STR"   custom encoding string (see README)
  --ext EXT             extension of encoded files
  --pipe-wav            pipe wav to encoder
  --skip-encoding       do not encode audio (keep as .mp4)
  --no-mp4v2            use ffmpeg to retrieve chapters (not recommended)
  --debug               output debug messages and save to log file

Chapter filenames

You can customize the chapter filenames with --custom-name "STR" where STR is a valid python format string.

Default ("My Title.mp3"):

--custom-name "%(title)s"

Chapter number ("3 - My Title.mp3"):

--custom-name "%(num)d - %(title)s"

Chapter number with leading zero ("03 - My Title.mp3"):

--custom-name "%(num)02d - %(title)s"

Encoding

By default the audio will be encoded with the lame mp3 codec using ffmpeg. The bit rate and sampling freq will be the same as the source file. If you wish to use other settings you can specify your own encoding options with --encode-opts "STR". STR will be passed to the encoder (--encoder or skip to use ffmpeg). Variables available:

%(outfile)s - output filename (required)
%(infile)s - .m4b file
%(bit_rate)d - bit rate of .m4b file
%(sample_rate)d - sampling rate of .m4b file

Examples

Convert multiple audio books (you can also drag multiple m4b files onto m4b.py):

python m4b.py myfile.m4b otherfile.m4b

Include chapter number in the generated filenames: (example: "Chapter 10 - Some Title.mp3")

python m4b.py --custom-name "Chapter %(num)d - %(title)s" myfile.m4b

If you rather want .mp4 files you can skip encoding to speed up the conversion process:

python m4b.py --skip-encoding myfile.m4b

Force sampling freq to 22050 Hz and bit rate to 128 kbit/s:

python m4b.py --encode-opts "-y -i %(infile)s -acodec libmp3lame -ar 22050 -ab 128k %(outfile)s" myfile.m4b

Encode with lame.exe:

python m4b.py --encoder lame.exe --pipe-wav --encode-opts "-V 3 -h - %(outfile)s" myfile.m4b

m4b-converter's People

Contributors

morg42 avatar valekhz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.