Difference between revisions of "Audiobook"

From ArchWiki
Jump to: navigation, search
(Tools: Updated broken m4baker aur link to use git package (which exists))
 
(14 intermediate revisions by 6 users not shown)
Line 1: Line 1:
[[Category:Audio/Video]]
+
[[Category:Multimedia]]
{{Article summary start}}
+
[[ja:オーディオブック]]
{{Article summary text|
+
{{Related articles start}}
The purpose of this article is to detail a process to create an iPod friendly audiobook from digital media using Linux native tools.  It is arranged in goal-oriented scenarios.}}
+
{{Related|iPod}}
{{Article summary heading|Related}}
+
{{Related|Rip Audio CDs}}
{{Article summary wiki|iPod}}
+
{{Related articles end}}
{{Article summary end}}
+
  
An audiobook for iPods is nothing more than a discrete audio stream + metadata wrapped together in an m4b container.  The audio must be an aac encoded stream and the chapter-index metadata has its own Quicktime standard. Multiple tools can be used to create these.
+
Audiobook media can be Audio CDs or downloaded files, several formats exist. For certain hardware media players a specific format will be necessary. This article documents how to create or convert an audiobook of various format types.
{{Wikipedia|.m4b}}
+
  
== Tools ==  
+
== iPod-compatible format ==
=== GUI based tools===
+
*{{AUR|m4baker}} - Used to combine a group of already ripped audiofiles into a single m4b file with chapter marks.
+
  
=== CLI based tools ===
+
The purpose of this section is to detail a process to create an iPod-friendly audiobook from digital media using Linux native tools.
*{{AUR|neroaacenc}} - Aac encoder.
+
*{{Pkg|lame}} - Mp3 encoder/decoder
+
*{{Pkg|gpac}} - Needed for manipulating mp4 files.
+
*{{Pkg|mediainfo}} - Displays many aspects of audio and video files.
+
*{{AUR|makechapterlist}} - Makes a chapter list automatically.
+
  
== Make an m4b file from multiple audio CDs ==
+
An audiobook designed for iPods is largely the same as a MPEG-4 audio file — it contains both an audio stream and information about that stream (metadata). The two differences are: one, it is wrapped in a specifically-named MPEG-4 container ({{ic|.m4b}}); and two, it has a chapter index added to the metadata. The chapter index uses the Quicktime standard.
=== Extract audio from CDs and making multiple tracks, one per chapter ===
+
Use one of the many fine CD rippers available to extract and encode the many CDs in a typical audiobook into aac encoded files.  (Out of scope for this tutorial).
+
{{Note|File extensions need not be .aac but the audio stream DOES need to be in aac format.}}
+
  
=== Use m4baker to assemble the indiviual tracks into a single m4b file ===
+
The basic process is this: the audio source is decoded/uncompressed (it is usually preferably to have a decoded audio-only file as this will simplify the concatenation/splitting of files later and prevent mixing of metadata tags); after this, the audio files are encoded to the [[Wikipedia:Advanced_Audio_Coding|AAC]] format — with a MPEG-4 container; last, the chapter index and audio information tags are added.
Usage of m4baker is very straightforward.  Detailed usage is explained on the [[http://code.google.com/p/m4baker/w/list project wiki]].  Be aware that the default qualitizer setting for faac is 100.  Some sources may require tweaking.  Faac takes values of 10 - 500 for the -q option.
+
  
== Make an m4b file from a single mp3 file or from multiple mp3 files ==
+
Multiple tools are available to help create audiobook files.
=== Predominantly using m4baker ===
+
{{Note|This guide assumes that the requisite mp3 file(s) do not correspond to the natural chapter breaks of the narrative. }}
+
  
Users have several options to define chapter marks.  One is to define arbitrary "chapter markers" using a set time interval (i.e. 10 min) to define the chapter breaks.  Another method can make use of silence detection to automatically break up chapter points.  In either case, a single file is required.
+
=== Tools ===
==== Make a single mp3 file  ====
+
If not already starting from one, simply concatenate them into a single file:
+
$ MP4Box -cat 1.mp3 -cat 2.mp3 final.mp3
+
  
==== Split the file into chapters ====
+
* {{AUR|m4baker-git}} — GUI program to combine numerous AAC-encoded audio files into a single m4b file with a chapter index
Split the single file into chapters.  In this example, a contains time of 10 min is used:
+
$ mp3splt -f -t 10.0 final.mp3 -o @n
+
  
See the mp3splt manpage for additional options and for an explanation of the options used above.
+
: m4baker usage is straightforward and detailed on the [http://code.google.com/p/m4baker/w/list project wiki] — its usage will not be covered here.
  
This example uses the auto silence mode wherein the file is scanned for periods of silence and split points generated from them. 
+
* {{pkg|faac}} — open source AAC encoder
 +
* {{AUR|neroaacenc}} — proprietary AAC encoder
 +
* {{pkg|gpac}} — multimedia framework for manipulating MPEG-4 media
 +
* {{pkg|lame}} — MP3 encoder and decoder
  
$ mp3splt -f -s -p -min=3 final.mp3
+
=== Extracting or decoding ===
  
{{Note|This mode is NOT general and requires considerable tweaking to work.  See the man page for more options.}}
+
The audio source file(s) will either need to be extracted, if a disc media, or to be decoded, if an encoded file.
  
==== Use m4baker to assemble the indiviual tracks into a single m4b file ====
+
If the audiobook is a ''disc media'', various [[Optical_disc_drive#Ripping|digital audio extraction utilities]] are available. A common way to extract audio from a CD to WAV-formatted files is:
Usage of m4baker is very straightforward.  Detailed usage is explained on the [[http://code.google.com/p/m4baker/w/list project wiki]]. Be aware that the default qualitizer setting for faac is 100.  Some sources may require tweaking.  Faac takes values of 10 - 500 for the -q option.
+
  
=== Using only CLI tools ===
+
  cdparanoia -B
==== Decode and make aac formatted file(s) ====
+
Since iPods require aac formatted audio, mp3 files need to be transcoded into aac. First, decode the source mp3 file to wav.  Repeat if multiple mp3 files constitute an entire book:
+
$ lame --decode book.mp3
+
  
Encode the wav file(s) to aac:
+
If the audiobook is a ''audio file'', various programs can decode it. For example, for MP3s:
$ neroAacEnc -q 0.7 -if book.wav -of book.aac
+
  
{{Tip|If multiple files are used, make use of a for loop to process them in one line.}}
+
  lame --decode part-01.mp3
  $ for i in *.mp3; do lame --decode "$i"; done
+
$ for i in *.wav; do neroAacEnc -q 0.7 -if "$i" -of "${i%.*}".aac; done
+
  
==== Optionally combine multiple aac files into a single file ====
+
(If no splitting of concatenation will be required, files can be directly encoded to AAC with a MPEG-4 container.)
Multiple aac files need to be concatenated into a single file:
+
$ MP4Box -cat 1.aac -cat 2.aac book.aac
+
  
==== Create metadata for chapter marks ====
+
=== Concatenation or splitting ===
Determine the overall length of the aac:
+
$ mediainfo --inform="Audio;%Duration/String3%" book.aac
+
19:04:53.874
+
  
In this example, the file is 19h 4m and 54 s long.  
+
Audiobooks parts are typically saved in about one hour, ten minute segments (usually the time extent of a audio CD). They can be concatenated or split as desired.
  
Create a chapter list to break up the file into "chapters" or more digestible parts.  The list itself is nothing more than a text file in a specific format (Nero chapter format to be precise).  Use {{ic|makechapterlist}} to make this automatically.
+
Join ''WAV'' files:
  
{{Note|The current version of makechapterlist simply makes chapter marks at 10 minute intervalsTo have the chapter marks coincide with the actual chapter breaks in the audio file, knowledge about when a chapter begins/ends is needed.}}
+
sndfile-concat track-01.wav track-02.wav… disc-1.wav # or more easily
 +
sndfile-concat track*.wav disc-1.wav
  
The example file calls for roughly 19h 5m of content, but the script uses 10 m intervals so a sane value is simply 19x6=114 chapters.
+
Join ''MPEG-4 compatible audio'' files (AAC, AVI, MP3…):
$ makechapterlist
+
Writes chapter files using a 10 min interval for each chapter
+
  
  How many chapters are needed: 114
+
  MP4Box -cat track-01.aac -cat track-02.aac… disc-1.aac
Done!  /home/facade/chapter.list written.
+
  
==== Hardcode the metadata into the audio file ====
+
Split a wav file ({{AUR|wavsplit}} can do this (untested)).
The next step is to merge the metadata in {{ic|chapter.list}} with the audio file.  This is accomplished using {{ic|MP4Box}}:
+
$ MP4Box -add book.aac -chap chapters.list book.mp4
+
  
The resulting file now needs to be converted to Quicktime chapter markers using {{ic|mp4chaps}}:
+
Split a ''MP3'' files into 10 minute intervals:
$ mp4chaps –convert –chapter-qt book.mp4
+
  
==== Rename the merged file ====
+
mp3splt -f -t 10.0 part-01.mp3 -o @n
  
The final step is to simply rename the mp4 file to the m4b extension:
+
Split a ''MP3'' by chapters/tracks (this method scans for silence and assumes them to be chapter/track marks, splitting them on those marks — these settings are generalized and will likely required further adjusting to work):
$ mv book.mp4 book.m4b
+
  
Users can now optionally edit the tags in the file with any number of tools.  Using {{Pkg|vlc}} is easy.  Simply load the file and hit {{Keypress|Ctrl}} + {{Keypress|i}} to bring up a tag window. Save the metadata before exiting.
+
  mp3splt -f -s -p -min=3 part-01.mp3
  
== Add chapter marks to an existing m4b file without them ==
+
Split ''MPEG 4 compatible audio'' files (metadata repair will likely be necessary) into 10 minute intervals.
  
This process is identical to [[Audiobook#3._Create_metadata_for_chapter_marks|steps 3-5]] detailed in Scenario 2.
+
MP4Box -split 600 target.mp4
  
== Break up an m4b file into individual files ==
+
=== Encoding ===
Some stereo systems in cars are not capable of using the metadata (chapter marks) within an m4b file.  It is therefore necessary to break up the m4b file into individual "chapter" files.
+
  
=== Into equal chunks ===
+
Multiple programs exist that can encode to AAC.
# Rename the m4b file to mp4
+
# Invoke the -split ''sec'' option of MP4Box:
+
  
$ mv target.m4b target.mp4
+
To encode with the open source encoder FAAC:
$ MP4Box -split 600 target.mp4
+
  
=== Based on metadata in original m4b file ===
+
faac -q 80 -o part-01.aac part-01.wav
 +
faac -q 80 -o part-01.m4b part-01.wav -w  # with a MPEG-4 container(wrapper)
 +
 
 +
To encode with the proprietary encoder Nero:
 +
 
 +
neroAacEnc -q 0.7 -of part-01.aac -if part-01.wav
 +
 
 +
{{Note|The FAAC quantizer quality setting of 55 (~64kbps) is recommended when encoding from an audiobook CD. This setting is for an audio source that is already an encoded file. The FAAC setting of 80 should reasonably accommodate sound quality while preserving file size close to the original file. ''Whenever converting from one lossy format to another, there will always be some amount of information lost.''}}
 +
 
 +
{{Warning|Though {{ic|ffmpeg}} can convert MP3 to an AAC encoding in one step ({{ic|ffmpeg -i track1.mp3 -acodec aac -strict -2 track1.aac}}), support for AAC is experimental.}}
 +
 
 +
=== Chapter index merging ===
 +
 
 +
To merge a chapter index into a audio file it must be decided what type of index to use: one, ''recurring intervals'' with periodic chapter times; or two, ''particular intervals'' with definitive chapter times and names.
 +
 
 +
Add a MPEG-4 container to the audio file:
 +
 
 +
MP4Box -add disc-1.aac disc-1.m4b
 +
 
 +
==== Recurring intervals ====
 +
 
 +
To merge a chapter index with chapters at every 10 minutes:
 +
 
 +
mp4chaps --every 600 disc-1.m4b
 +
 
 +
==== Particular intervals ====
 +
 
 +
The method requires writing a chapter index as a text file and merging it into the audio file.
 +
 
 +
{{Note|{{ic|mp4chaps}} will complain about ''not'' seeing a video stream when attempting to merge the chapter index with the {{ic|--import}} option (a bug should probably be filed). An alternate method is to use {{ic|MP4Box}}. Though MP4Box is typically seen used for video files it has the ability to add chapters while not introducing a video stream. Because of this the resulting media will be able to play on iPods and iTunes as expected.}}
 +
 
 +
The chapter index will need to be written as a text file before being merged into audio file. There are two standards for chapter indexes: one, the Quicktime standard; and two, the Nero standard. Either can be initially merged.
 +
 
 +
The Quicktime standard looks like this (thousandths of a second can also be added {{ic|.000}}):
 +
 
 +
00:00:00 Track 01
 +
00:08:40 Track 02
 +
...
 +
 
 +
The Nero standard looks like this:
 +
 
 +
CHAPTER1=00:00:00
 +
CHAPTER1NAME=Track 01
 +
CHAPTER2=00:08:40
 +
CHAPTER2NAME=Track 02
 +
...
 +
 
 +
To merge the chapter index file:
 +
 
 +
MP4Box -chap disc-1.chapters.txt disc-1.m4b
 +
 
 +
To merge the chapter index file in one step along with the audio file and a container:
 +
 
 +
MP4Box -chap disc-1.chapters.txt -add disc-1.aac disc-1.m4b
 +
 
 +
The chapter index will need to be converted to the Quicktime standard (though MP4Box will recognize both chapter index standards when importing, it imports using the Nero standard). Convert to the Quicktime standard with:
 +
 
 +
mp4chaps --convert --chapter-qt disc-1.m4b
 +
 
 +
The chapter index can now be tested, for example, with VLC.
 +
 
 +
=== Tagging ===
 +
 
 +
A number of [[List_of_applications/Multimedia#Audio_tag_editors|tagging programs]] can be used. The basic command line programs (likely already installed — {{ic|mp4tag}}, {{ic|mp4art}}, {{ic|mp4file}}, {{ic|mp4info}}…) have numerous abilities:
 +
 
 +
  mp4tags -album "An Good Audiobook" -artist "John Doe" -disk 2 -disks 10 -genre Nonfiction -albumartist "Ms. Foo Bar" -song "Disc 2" -year 2004 disc1.m4b
 +
 
 +
Add coverart:
 +
 
 +
mp4art --add a-good-audiobook.jpg disc-1.m4b
 +
 
 +
Optimize the container:
 +
 
 +
mp4file --optimize *.m4b
 +
 
 +
=== Example of batching ===
 +
 
 +
A number of audio files can be processed using a loop:
 +
 
 +
for m in *.mp3; do
 +
  lame --decode "$m"
 +
  faac -q 80 -o "${m%.*}".aac "$m"
 +
done
 +
 
 +
To write tags for sequential disc numbering:
 +
 
 +
for b in *.m4b; do
 +
  [ "$n" ] && n=$((10#$n + 1))
 +
  [ -z "$n" ] && n=1
 +
  mp4tags -album "An Good Audiobook"… -disk $(printf "%02u" $n)… "$b"
 +
done
 +
 
 +
== Audible format ==
 +
 
 +
It can be a laborious process to convert and Audible book format — [http://linuxtidbits.wordpress.com/2011/09/21/audible-com-and-linux-arghh/ article].
 +
 
 +
A much easier way is to use this script to fetch your activation bytes from the Audible website — [https://github.com/inAudible-NG/audible-activator/ link].
 +
 
 +
You can then use {{pkg|mpv}} to listen to the file:
 +
 
 +
$ mpv --demuxer-lavf-o=activation_bytes=<your activation bytes> <filename>.aax
 +
 
 +
Or you can write the file to unencrypted .mp4 with {{pkg|ffmpeg}} [http://ffmpeg.org/ffmpeg-all.html#Audible-AAX/ (documentation)]:
 +
 
 +
$ ffmpeg -activation_bytes <your activation bytes> -i <filename>.aax -vn -c:a copy <output>.mp4
 +
 
 +
The resulting file will have chapter headers intact.
 +
 
 +
== See also ==
 +
 
 +
* [[Wikipedia:.m4b]]
 +
* {{AUR|RipIT}} — thorough DAE with the ability to create chapter indexes with the {{ic|--book}} option.

Latest revision as of 02:25, 9 March 2016

Related articles

Audiobook media can be Audio CDs or downloaded files, several formats exist. For certain hardware media players a specific format will be necessary. This article documents how to create or convert an audiobook of various format types.

iPod-compatible format

The purpose of this section is to detail a process to create an iPod-friendly audiobook from digital media using Linux native tools.

An audiobook designed for iPods is largely the same as a MPEG-4 audio file — it contains both an audio stream and information about that stream (metadata). The two differences are: one, it is wrapped in a specifically-named MPEG-4 container (.m4b); and two, it has a chapter index added to the metadata. The chapter index uses the Quicktime standard.

The basic process is this: the audio source is decoded/uncompressed (it is usually preferably to have a decoded audio-only file as this will simplify the concatenation/splitting of files later and prevent mixing of metadata tags); after this, the audio files are encoded to the AAC format — with a MPEG-4 container; last, the chapter index and audio information tags are added.

Multiple tools are available to help create audiobook files.

Tools

  • m4baker-gitAUR — GUI program to combine numerous AAC-encoded audio files into a single m4b file with a chapter index
m4baker usage is straightforward and detailed on the project wiki — its usage will not be covered here.
  • faac — open source AAC encoder
  • neroaacencAUR — proprietary AAC encoder
  • gpac — multimedia framework for manipulating MPEG-4 media
  • lame — MP3 encoder and decoder

Extracting or decoding

The audio source file(s) will either need to be extracted, if a disc media, or to be decoded, if an encoded file.

If the audiobook is a disc media, various digital audio extraction utilities are available. A common way to extract audio from a CD to WAV-formatted files is:

cdparanoia -B

If the audiobook is a audio file, various programs can decode it. For example, for MP3s:

lame --decode part-01.mp3

(If no splitting of concatenation will be required, files can be directly encoded to AAC with a MPEG-4 container.)

Concatenation or splitting

Audiobooks parts are typically saved in about one hour, ten minute segments (usually the time extent of a audio CD). They can be concatenated or split as desired.

Join WAV files:

sndfile-concat track-01.wav track-02.wav… disc-1.wav  # or more easily
sndfile-concat track*.wav disc-1.wav

Join MPEG-4 compatible audio files (AAC, AVI, MP3…):

MP4Box -cat track-01.aac -cat track-02.aac… disc-1.aac

Split a wav file (wavsplitAUR can do this (untested)).

Split a MP3 files into 10 minute intervals:

mp3splt -f -t 10.0 part-01.mp3 -o @n

Split a MP3 by chapters/tracks (this method scans for silence and assumes them to be chapter/track marks, splitting them on those marks — these settings are generalized and will likely required further adjusting to work):

mp3splt -f -s -p -min=3 part-01.mp3

Split MPEG 4 compatible audio files (metadata repair will likely be necessary) into 10 minute intervals.

MP4Box -split 600 target.mp4

Encoding

Multiple programs exist that can encode to AAC.

To encode with the open source encoder FAAC:

faac -q 80 -o part-01.aac part-01.wav
faac -q 80 -o part-01.m4b part-01.wav -w  # with a MPEG-4 container(wrapper)

To encode with the proprietary encoder Nero:

neroAacEnc -q 0.7 -of part-01.aac -if part-01.wav
Note: The FAAC quantizer quality setting of 55 (~64kbps) is recommended when encoding from an audiobook CD. This setting is for an audio source that is already an encoded file. The FAAC setting of 80 should reasonably accommodate sound quality while preserving file size close to the original file. Whenever converting from one lossy format to another, there will always be some amount of information lost.
Warning: Though ffmpeg can convert MP3 to an AAC encoding in one step (ffmpeg -i track1.mp3 -acodec aac -strict -2 track1.aac), support for AAC is experimental.

Chapter index merging

To merge a chapter index into a audio file it must be decided what type of index to use: one, recurring intervals with periodic chapter times; or two, particular intervals with definitive chapter times and names.

Add a MPEG-4 container to the audio file:

MP4Box -add disc-1.aac disc-1.m4b

Recurring intervals

To merge a chapter index with chapters at every 10 minutes:

mp4chaps --every 600 disc-1.m4b

Particular intervals

The method requires writing a chapter index as a text file and merging it into the audio file.

Note: mp4chaps will complain about not seeing a video stream when attempting to merge the chapter index with the --import option (a bug should probably be filed). An alternate method is to use MP4Box. Though MP4Box is typically seen used for video files it has the ability to add chapters while not introducing a video stream. Because of this the resulting media will be able to play on iPods and iTunes as expected.

The chapter index will need to be written as a text file before being merged into audio file. There are two standards for chapter indexes: one, the Quicktime standard; and two, the Nero standard. Either can be initially merged.

The Quicktime standard looks like this (thousandths of a second can also be added .000):

00:00:00 Track 01
00:08:40 Track 02
...

The Nero standard looks like this:

CHAPTER1=00:00:00
CHAPTER1NAME=Track 01
CHAPTER2=00:08:40
CHAPTER2NAME=Track 02
...

To merge the chapter index file:

MP4Box -chap disc-1.chapters.txt disc-1.m4b

To merge the chapter index file in one step along with the audio file and a container:

MP4Box -chap disc-1.chapters.txt -add disc-1.aac disc-1.m4b

The chapter index will need to be converted to the Quicktime standard (though MP4Box will recognize both chapter index standards when importing, it imports using the Nero standard). Convert to the Quicktime standard with:

mp4chaps --convert --chapter-qt disc-1.m4b

The chapter index can now be tested, for example, with VLC.

Tagging

A number of tagging programs can be used. The basic command line programs (likely already installed — mp4tag, mp4art, mp4file, mp4info…) have numerous abilities:

 mp4tags -album "An Good Audiobook" -artist "John Doe" -disk 2 -disks 10 -genre Nonfiction -albumartist "Ms. Foo Bar" -song "Disc 2" -year 2004 disc1.m4b

Add coverart:

mp4art --add a-good-audiobook.jpg disc-1.m4b

Optimize the container:

mp4file --optimize *.m4b

Example of batching

A number of audio files can be processed using a loop:

for m in *.mp3; do
  lame --decode "$m"
  faac -q 80 -o "${m%.*}".aac "$m"
done

To write tags for sequential disc numbering:

for b in *.m4b; do
  [ "$n" ] && n=$((10#$n + 1))
  [ -z "$n" ] && n=1
  mp4tags -album "An Good Audiobook"… -disk $(printf "%02u" $n)… "$b"
done

Audible format

It can be a laborious process to convert and Audible book format — article.

A much easier way is to use this script to fetch your activation bytes from the Audible website — link.

You can then use mpv to listen to the file:

$ mpv --demuxer-lavf-o=activation_bytes=<your activation bytes> <filename>.aax

Or you can write the file to unencrypted .mp4 with ffmpeg (documentation):

$ ffmpeg -activation_bytes <your activation bytes> -i <filename>.aax -vn -c:a copy <output>.mp4

The resulting file will have chapter headers intact.

See also

  • Wikipedia:.m4b
  • RipITAUR — thorough DAE with the ability to create chapter indexes with the --book option.