📜 ⬆️ ⬇️

Create m4b from mp3 audiobooks for ipod

I just wanted to listen to an audiobook alone, the problem is that I wanted to listen to it on the ipod, but I could not find it anywhere in the m4b format, only mp3.

After a long googling, a post was found with ideas on how to do it, but without normal implementation. I managed to share my ideas and decisions with the author of this post, but for some reason he lost them after some time.

The bottom line is that .m4b is an AAC file in the mp4 container, but bookmarked and renamed. Therefore, it is necessary to overtake all mp3 in aac and generate a file of bookmarks (chapters), in quicktime format, and then stuff the whole thing into an mp4 container.

Under linux there is only 1 normal AAC encoder - NeroAacEncoder . The code is closed, but it is free and works.
The alternative is in ffmpeg, but it is very raw.
There is also alac encoder \ decoder, also in ffmpeg, but it does not control the bitrate at all - a 10 meter mp3 turns into a 100Mb monster.
')
Initially, it was planned to stuff into the container using MP4Box, which is included in the gpac package. And libmp4v2 should be used for tagging tags and processing chapters-files (only it is necessary to use trunk-r355 snapshot, there are a lot of bugfixes, and the stable version still does not work correctly).

It was then that it turned out that MP4Box has a limitation on stuffing into one container - 20 files (why and why it is not clear). Yes, and chapters-file, with this approach, you need to generate yourself. The result was this script with 140 lines and several problems.

A bit later, a much more optimal solution was found - to transfer mp3 to wav, and then to distill them all in a crowd through NeroAacEnc, which is able to generate chapters by itself and has no restrictions on the number of incoming files. Tags can be arranged NeroAacTag (they are included) in one line, and it is believed that this will be more correct and accurate. True, this does not eliminate the use of mp4chaps (from libmp4v2) for converting nero bookmarks into quicktime bookmarks.

UPD: It's pretty obvious, but still - the files should have the correct names / numbering, so that `ls -1` would output them in the correct order. Not 1..12, but 01..12, for example.
Or, as rightly noted xn__p2a , use "ls -1v" (for output 1..12).

# FIELD SEPARATOR IFS=$'\n' # ALL MP3 TO WAV for i in `ls -1 *.mp3`; do mplayer -nocorrect-pts -vo null -vc null -ao pcm:fast:file="${i%%mp3}wav" "$i"; done # CONCATE ALL WAV TO MP4 WITH AUTOMATIC CREATION OF CHAPTER MARKS for i in `ls -1 *.wav`; do printf %s "-if \"$i\" ";done | xargs ../neroAacEnc -of OUT.mp4 # SET CORRECT TAGS ../neroAacTag -meta:title="MY_TITLE" -meta:artist="MY_AUTHOR" -add-cover:front:BOOK_COVER.jpg OUT.mp4 # CONVERT CHAPTERS FOR IPOD mp4chaps -convert --chapter-qt OUT.mp4 


Of course, now the screw is not aac, but huge wav, which will have to be killed later, and through fifo (as it was in the first script) is somehow more elegant, but everything has become much simpler.

UPD: there is an opinion that using mplayer to get wav from mp3 is overkill.
Some alternatives are:
 ffmpeg -i input.mp3 output.wav mpg123 -w output.wav input.mp3 lame -decode input.mp3 output.wav 


In the new m4b file, chapter titles will be of the type 'Chapter 01', but this can be easily corrected by editing the bookmarks file:

 # EXPORT CHAPTERS TO MP4FILE.CHAPTERS.TXT mp4chaps -x test.mp4 # NOW YOU CAN MODIFY THEM AND IMPORT BACK mp4chaps -i test.mp4 


How and what to edit - your choice.

gtkpod-1.0.0 and libgpod-0.8.0 learned how to support the 5th generation ipod nano, so I use them.

UPD: after a long correspondence with xn__p2a , a third version of the script appeared:
 #!/bin/bash # INPUT FIELD SEPARATOR IFS=$'\n' # JUST MORE CONVINIENT function mpfifo { mplayer -nocorrect-pts -vo null -vc null -ao pcm:fast:file="${1%%mp3}wav" "$1" &>"/dev/null" & } # NEED MORE FIFO!!111 for i in `ls -1v *.mp3`; do mkfifo "${i%%mp3}wav"; done # RUN NEROAACENC for i in `ls -1v *.mp3`; do printf %s " -if \""${i%%mp3}wav"\"";done | xargs ../../neroAacEnc -of test.mp4 & # RUN ALL MP3 for i in `ls -1v *.mp3`; do mpfifo "$i"; done # CONVERT CHAPTERS mp4chaps -convert --chapter-qt test.mp4 

This option is recognized as more elegant, because you need to clean only 0B fifo: `find -maxdepth 1 -type p -exec rm {} +`

PS: It’s a pity it’s impossible to wrap the mplayer exhaust in the neroAacEnc input so that he would take them as separate files (otherwise there will be no auto marking).
PPS: Do NOT install systemwide libmp4v2 trunk 335 - 1/2 things dependent on this will fly off, and gtkpod will forget how to understand m4a \ m4b files.
PPPS: You can wrap individual aac into separate mp4 and rename to m4a if you want to loseless music on ipod.

Source: https://habr.com/ru/post/111862/


All Articles