HydrogenAudio

Lossy Audio Compression => MP3 => MP3 - Tech => Topic started by: jaime11 on 2009-09-23 00:23:57

Title: M4B to MP3 (chapter separation)
Post by: jaime11 on 2009-09-23 00:23:57
Hello
I have been searching on the forum but haven't found anything. Basicly what I'm looking for is a program that will input a M4B file and output several MP3 files (1 MP3 per chapter in the M4B file).
I have been using Free M4B to MP3 Converter, but unfortunately, all it does is extract a single MP3 from the M4B.

Anyone knows any other programs for this job?

Thank you
Title: M4B to MP3 (chapter separation)
Post by: DVDdoug on 2009-09-23 00:53:25
NOTE - I've never seen an M4B file, so maybe someone else can give you a better answer.

Do you need to do it automatically?  I don't know how to do it automatically, but with any audio editor you can cut-out sections and save the separate sections in a variety of formats.   (That  assumes the audio editor can open the M4B files.)  If you don't already have an audio editor, Audacity (http://audacity.sourceforge.net/?lang=en) is FREE!!! (open source).

Or, MP3DirectCut[/u] (http://mpesch3.de1.cc/mp3dc.html) (FREE!!!) can take the one-big MP3 file and chop it into little files (manually).
Title: M4B to MP3 (chapter separation)
Post by: MostlyHarmless on 2009-09-23 09:17:55
Would you point me to a link with such file (m4b with chapters), for test purposes? Maybe you can upload some?
Title: M4B to MP3 (chapter separation)
Post by: tedgo on 2009-09-23 10:06:28
Have you tried foobar2000?
It can handle m4a/m4b with chapters and should be able to convert to individual mp3 files.
You'll need lame.exe for converting to mp3, though.
Title: M4B to MP3 (chapter separation)
Post by: jaime11 on 2009-09-23 23:21:53
Hello
Thanks to everyone with their fast replies...

NOTE - I've never seen an M4B file, so maybe someone else can give you a better answer.

Do you need to do it automatically?  I don't know how to do it automatically, but with any audio editor you can cut-out sections and save the separate sections in a variety of formats.   (That  assumes the audio editor can open the M4B files.)  If you don't already have an audio editor, Audacity (http://audacity.sourceforge.net/?lang=en) is FREE!!! (open source).

Or, MP3DirectCut[/u] (http://mpesch3.de1.cc/mp3dc.html) (FREE!!!) can take the one-big MP3 file and chop it into little files (manually).


Thanks, I know such programs. Actually, I'm a frequent user of audacity and use another program called gtk mp3splitter that automatically detects silences in mp3 and splits them accordingly. However, I was thinking that since the M4B file when played in the ipod, the ipod recognizes it's chapters (similar to different tracks). Therefore, I guess the M4B file must contain some kind of information related to the chapter separation inside. I was therefore looking for some program that would use this info and split the M4B file accordingly.




Would you point me to a link with such file (m4b with chapters), for test purposes? Maybe you can upload some?


The file I currently want to split is nearly 200mb long, I'm looking for a smaller M4B file to upload. Thanks!



Have you tried foobar2000?
It can handle m4a/m4b with chapters and should be able to convert to individual mp3 files.
You'll need lame.exe for converting to mp3, though.



I have just tried using foobar2000, it opens the M4B file but when converting it I tried using the option "Convert each track to an individual file" and "generate multi-track files". Unfortunately, both just produced one single MP3 file


We'll keep investigating, thanks for the help!
Title: M4B to MP3 (chapter separation)
Post by: Zarggg on 2009-09-24 16:10:00
Is there any particular reason you need to transcode from AAC to MP3, rather than just splitting the file into multiple AAC (.m4a) files?
Title: M4B to MP3 (chapter separation)
Post by: jaime11 on 2009-09-24 16:56:10
Is there any particular reason you need to transcode from AAC to MP3, rather than just splitting the file into multiple AAC (.m4a) files?


Hello Zarggg,
No, there is no particular reason. Splitting to AAC is ok as long as it keeps the same structure of chapters as in the ipod and it is done automatically. I can always convert it back to MP3. Any ideas?


Thanks.
Title: M4B to MP3 (chapter separation)
Post by: uberwolf on 2009-10-29 00:03:48
Is there any particular reason you need to transcode from AAC to MP3, rather than just splitting the file into multiple AAC (.m4a) files?


Hello Zarggg,
No, there is no particular reason. Splitting to AAC is ok as long as it keeps the same structure of chapters as in the ipod and it is done automatically. I can always convert it back to MP3. Any ideas?


Thanks.


Did you have any luck with this. I also want to do this and my reason - my Cowon Q5W will not play .m4b files so I have to convert to mp3, ogg, flac ect. The files I want to convert are approx 8hrs long and made up of several chapters.
Title: M4B to MP3 (chapter separation)
Post by: Zarggg on 2009-11-02 19:26:26
If you don't have (lossless) sources, and you're willing to run the risk of artifacts, just transcode at a similar bitrate/comparable quality setting. There's really not much other choice if your media player cannot read the formats you're using.
Title: M4B to MP3 (chapter separation)
Post by: uberwolf on 2009-11-03 18:21:44
My idea was to first convert the complete M4b files(10 x 8Hrs) into mp3 files which I did with dBpoweramp with good results. Now I want to chop up these large mp3 files into their revelant chapters. Using Qtime player on the .m4b files I was able to determine the exact time frame and size of each chapter(00:00:00 - 00:28:56, 00:28:58 - 01:06:08 and so on). I did try Cool Edit Pro to cut the files up into the revelant chapters but this re-converts the lame mp3's into mp3 pro files, not what I want. I will try the mp3 direct cut app DVDdoug linked to and see how that works but I suspect that also re-encodes the file, maybe not. My fear is that I will spend a week doing this and only then find out there was a much faster, easier and automatic method to achieve the same result.  There are over 200 chapters in all.
Title: M4B to MP3 (chapter separation)
Post by: Zarggg on 2009-11-04 15:56:14
Have you tried using Audacity? I've had pretty good luck with that program when I needed to chop up audio files in the past.
Title: M4B to MP3 (chapter separation)
Post by: HydrogenNoobie on 2010-09-20 05:22:15
Jamie11,
Did you ever find a solution?  I am looking for the same thing, and several months later, I am not having too much success.  Did you find solution for "a program that will input a M4B file and output several MP3 files (1 MP3 per chapter in the M4B file)"?
Thanks
Title: M4B to MP3 (chapter separation)
Post by: valekhz on 2010-12-04 00:22:42
If anyone is still interested I wrote a little python script to do this. You can find the git repository here: https://github.com/valekhz/m4b-converter (https://github.com/valekhz/m4b-converter). If you don't use git you can just download the python file here: https://github.com/valekhz/m4b-converter/raw/master/m4b.py (https://github.com/valekhz/m4b-converter/raw/master/m4b.py).

You'll need python (only tested with 2.7 so far) and ffmpeg. Place the m4b.py somewhere and drag your *.m4b file onto m4b.py, or use the command line. There's a README in the git repository for more info on how to use it. I haven't been able to test that many .m4b files yet but those I've tried have worked great. I've tested it on Windows 7 and Ubuntu.

Basically it works by parsing the output of ffmpeg -i file.m4b to get the chapter data, encodes the audio and splits it based on the data from ffmpeg. Sorry if the code is a bit messy, haven't been coding in python for a while.
Title: M4B to MP3 (chapter separation)
Post by: nbarzgar on 2010-12-04 07:06:13
If anyone is still interested I wrote a little python script to do this. You can find the git repository here: https://github.com/valekhz/m4b-converter (https://github.com/valekhz/m4b-converter). If you don't use git you can just download the python file here: https://github.com/valekhz/m4b-converter/raw/master/m4b.py (https://github.com/valekhz/m4b-converter/raw/master/m4b.py).

You'll need python (only tested with 2.7 so far) and ffmpeg. Place the m4b.py somewhere and drag your *.m4b file onto m4b.py, or use the command line. There's a README in the git repository for more info on how to use it. I haven't been able to test that many .m4b files yet but those I've tried have worked great. I've tested it on Windows 7 and Ubuntu.

Basically it works by parsing the output of ffmpeg -i file.m4b to get the chapter data, encodes the audio and splits it based on the data from ffmpeg. Sorry if the code is a bit messy, haven't been coding in python for a while.


Thank you,  I also have been looking for this for weeks!
Now my problem: I get the message "no chapter information found", although iTunes shows them and ffmpeg parses a 'subtitle' stream... What can I do?
File-Info:
m4b_Info.txt (http://www.sereshk.de/files/m4b_Info.txt)


By the way, for other newbies in Python - like me - here a few (Windows-)hints:
1. DL Python 2.7 (http://www.python.org/download/releases/2.7/) and install to directory of your choice.
2. The 'PATH' means the directory, where the Python-executable is stored (in my case it was the 'Python 2.7' dir created on HDD during install).
3. Download 'ffmpeg.exe' from here (http://www.videohelp.com/download/ffmpeg-r25512.7z) (for example, other sites exist) and put it in the same dir, as the Python-executable, i.e. the 'PATH'.
4. Put m4b.py into any directory, which has enough space for the .mp3-output files (of course, as valekhz points out you may change the output-dir by editing the .py file, but I wouldn't dare, never having come close to coding such things...)
5. Drag&drop m4b file onto the .py-file, wait (depending on CPU-power), find the new file(s) in a new subdirectory, called the same as the m4b...

Thanks again, valekhz!
Should you be able to help me on my above stated issue, I' be extremely grateful!!
Title: M4B to MP3 (chapter separation)
Post by: valekhz on 2010-12-04 12:25:35
Thank you for writing the guide, nbarzgar.

Thank you,  I also have been looking for this for weeks!
Now my problem: I get the message "no chapter information found", although iTunes shows them and ffmpeg parses a 'subtitle' stream... What can I do?
File-Info:
m4b_Info.txt (http://www.sereshk.de/files/m4b_Info.txt)

If you could post the output of ffmpeg.exe -i myfile.m4b I may be able to help. This particular error message shows up when the script couldn't find/parse chapter data from the output. The current implementation of getting the chapter data is very ugly and if anyone knows of a library that can read the chapters directly I could improve the script.

4. Put m4b.py into any directory, which has enough space for the .mp3-output files (of course, as valekhz points out you may change the output-dir by editing the .py file, but I wouldn't dare, never having come close to coding such things...)

There's a command line option to change the output directory: python m4b.py --output-dir C:\Some\Other\Folder myfile.m4b. You can find the other command line options by running: python m4b.py -h.
Title: M4B to MP3 (chapter separation)
Post by: nbarzgar on 2010-12-05 05:02:57
Thank you for writing the guide, nbarzgar.

welcome...

If you could post the output of ffmpeg.exe -i myfile.m4b I may be able to help. This particular error message shows up when the script couldn't find/parse chapter data from the output. The current implementation of getting the chapter data is very ugly and if anyone knows of a library that can read the chapters directly I could improve the script.


I put the output here (http://www.sereshk.de/files/ffmpeg_info.txt).

Thanks for trying to help and being so fast about it! 
Title: M4B to MP3 (chapter separation)
Post by: valekhz on 2010-12-05 15:11:50
I put the output here (http://www.sereshk.de/files/ffmpeg_info.txt).

Thanks for trying to help and being so fast about it! 

It's possible that Apple have their own implementation of mp4 chapters which ffmpeg can't read. There are a few options available:

You'll be able to test #1 easily and this is the solution I'd prefer. #2 and #3 will not be possible right now since I don't have access to one of those .m4b files. You could try #2 and #3 if you feel like it and feel comfortable enough with the command line. If we're lucky VLC can read it, otherwise there's not much I can do right now.
Title: M4B to MP3 (chapter separation)
Post by: nbarzgar on 2010-12-05 19:30:15
VLC shows the chapters!!
So now what would I do? I know that VLC allows converting, but how would I go about it in this case? Or did you mean yet another solution?
Title: M4B to MP3 (chapter separation)
Post by: valekhz on 2010-12-05 23:45:40
VLC shows the chapters!!
So now what would I do? I know that VLC allows converting, but how would I go about it in this case? Or did you mean yet another solution?

Awesome. I will remove the old chapter code and use VLC's API to get them instead. This will be a lot more reliable than parsing command output. There should be a new version out tomorrow.
Title: M4B to MP3 (chapter separation)
Post by: nbarzgar on 2010-12-08 05:59:29
Awesome. I will remove the old chapter code and use VLC's API to get them instead. This will be a lot more reliable than parsing command output. There should be a new version out tomorrow.


This is wonderful news! Thanks for all the help.
Title: M4B to MP3 (chapter separation)
Post by: valekhz on 2010-12-10 21:42:24
I finally got the time to finish the script. Unfortunately it's not possible to retrieve chapter times through VLC's API so I had to find another solution. libmp4v2 should be able to read both chapter formats but I haven't been able to test both. If it doesn't work it'll have to wait until I have access to one of those m4b files.

Installation is pretty simple:
I compiled the dll with Visual Studio 2010 so you may need the Microsoft Visual C++ 2010 Redistributable Package if you get dll errors when running the script. You can download it from Microsoft's website. Sorry about all these extra dependencies.

If anyone rather want to use the old script (without support for both chapter types) it's still available here (https://github.com/valekhz/m4b-converter/zipball/v0.1).
Title: M4B to MP3 (chapter separation)
Post by: nbarzgar on 2010-12-11 10:58:48
I finally got the time to finish the script.


Just downloaded, followed the steps - and ended up after about 45 min (83 chapters, 15 hrs runtime) with the correctly splitted files!!! (In the course of the process I already had got the message "83 chapter(s) found"...)
This is great work, thank you so much!!

Title: M4B to MP3 (chapter separation)
Post by: HydrogenNoobie on 2010-12-11 22:47:16
valekhz,

Thank you so much for writing this script!  You are doing great work!  I have been looking for a way to do this for some time, and I'm thrilled to see that someone with the right skills has taken an interest.  I didn't visit the site for a couple weeks - and it looks like I missed alot!

While it is *almost* working for my m4b files, unfortunately, it is not quite there just yet.

For background...When I run the original script (from Dec 4), it must be close to being able to parse the chapters, because as it works, I can see the chapter names scrolling by, but it only creates a single mp3 file.  I suspect the problem might be related to the characters in the chapter names, because as it works, I can see that some of the characters (both western, but non-English characters, like "ñ, ǐ, ǚ, á, è, ß" as well as Asian, like "你好") look corrupted.

When I ran the new script from Dec 10 (I think I'm following the instructions right), I simply get an error message "This application has failed to start because MSVCP100.dll was not found. Reinstalling the application may fix this problem."  The first few letters do suggest that the dll you compiled may be creating a need for other components of Microsoft Visual Studio, so I downloaded and installed it.  Now, it does run, and does create multiple mp3's from one m4b.  However, it creates far fewer mp3s than there are chapters.  I also notice that some of the mp3 file names are not the same as the m4b chapter names...again, I suspect it is related to non-English characters.  Do you think there is any way to get chapter names / file names using other character sets?  I will send you a couple of my m4B files as a samples via email in the hope that you are willing to give it a try

Again - I am so happy that you have both the knowledge to deal with this topic and the interest to do so.  Thank you so much!
Title: M4B to MP3 (chapter separation)
Post by: valekhz on 2010-12-12 18:02:50
Unfortunately there's no Unicode support right now that's why you get those issues. Unicode support is essential so I'll see what I can do. A few samples of those m4b files would be very helpful so check your inbox.

When I ran the new script from Dec 10 (I think I'm following the instructions right), I simply get an error message "This application has failed to start because MSVCP100.dll was not found. Reinstalling the application may fix this problem."  The first few letters do suggest that the dll you compiled may be creating a need for other components of Microsoft Visual Studio, so I downloaded and installed it.

That's correct. If anyone else is having the same issue you may need to download the Microsoft Visual C++ 2010 Redistributable Package from Microsoft's website. This is also included in the installation instructions above.
Title: M4B to MP3 (chapter separation)
Post by: daleybox on 2010-12-13 02:36:44
I ran into a couple of problems:

1)  It was saying that the library and/or DLL was not a valid windows dll.  The problem was I was using the supplied DLL, which is a 32-bit and I was using 64-bit python.  Those don't mix, so I installed and used the 32-bit version of python and it worked great.  So, if anyone has that problem, hopefully this will help them.

2)  The other "problem" I have is not really a problem, but more of a request I guess.  The script works well, however, when it extracts the chapters and names to mp3, I have no idea of what order they should have be in.  Could there be an internal counter or something so that you would get something like "Chapter 1 - " prepended to the chapter title?  Otherwise, the only way I see to figure out the order is to listen to each one and hope it starts with the chapter number...
Title: M4B to MP3 (chapter separation)
Post by: valekhz on 2010-12-13 21:59:22
Had some time to figure out the Unicode problem today and it's only an issue on Windows. ffmpeg can't handle Unicode filenames on Windows but does it fine on other platforms. So to fix this I just had to work around it by feeding non-unicode filenames to ffmpeg then rename to the correct one.

Here's the new release (v0.4.2): download (https://github.com/valekhz/m4b-converter/zipball/v0.4.2)
To get filenames like "Chapter 5 - Title.mp3" you can call the script like this:
Code: [Select]
python m4b.py --custom-name 'Chapter %(num)d - %(title)s' myfile.m4b

If you're not familiar with python formatting %(num)d will turn into the chapter number and %(title)s the chapter title. You can do more advanced formatting too, e.g. if you want "Chapter 05" instead you can use %(num)02d, and so on.
Title: M4B to MP3 (chapter separation)
Post by: HydrogenNoobie on 2010-12-13 22:37:22
Valekhz - I prefer no pre-pending of "Chapter nn" to the beginning of the filename.  If you do prepend filenames with chapter numbers, perhaps there could be an option to enable / disable it?

daleybox - If for some reason valekhz does not implement the feature, or if you do not want to wait, there is a pretty easy workaround for you to try...
1) dump the filenames and creation timestamps of the files output by valekhz's m4b-converter into a text file sorted by time created (in Windows, this can be done with "dir /od > dir.txt" - even if they all display the same time to the minute - the OS knows which were created first to the second or better)
2) open this text file in Excel
3) use the "Concatenate" command in Excel to build a DOS command to do the renaming.  I've done this for Windows, and I'm sure equivalent simple steps exist for other OS's.  For example...
[blockquote]=CONCATENATE("copy """,A6,""" ""Chapter ",C6," - ",A6,"""")
where column A has the old file name, column C has the numbering you want to use
[/blockquote]4) copy this row down for all the files, then copy the whole list of commands into a DOS batch file

With this approach, you can then rename or create copies with the new name for all the files at once.  This approach is easy and flexible, and would prevent valekhz from then getting additional requests to support things like:
a) users with m4b files with a Preface or Forward or both asking to offset the first chapter by 1 or 2 (or more) files?
b) users with an audio book that is split into multiple m4b's with multiple chapters per m4b asking to offset so that the first file starts with Chapter Y?
c) users who prefer chapters in roman numerals asking for "chapter i"  and "Chapter ii" instead of "Chapter 1" and "Chapter 2"
d) users whose audio players sorts / plays the files the order Chapter 1, 10, 11,12.....,19, 2, 20, 21....29, 3, 30, 31 asking to make the chapters two digits wide so they sort in the proper order
e) users who speak language X asking to add options to name files "Kapitel 1" or "Capítula 1" instead of "Chapter 1".
f) users who want the author and/or title added along with or instead the file name / chapter name.

While I prefer that the chapter number is not added to the file name, I can solve that myself.  I'm just trying to think about the future in case there are enough people looking to split M4B files that it really matters.
Title: M4B to MP3 (chapter separation)
Post by: HydrogenNoobie on 2010-12-13 22:50:39
valekhz,
I hadn't seen your latest post when I posted.  I will try your new file soon - thank you.  No that I see your post - you can ignore mine.  The Unicode support was a much bigger deal for me.

Thanks again for your work.
Title: M4B to MP3 (chapter separation)
Post by: HydrogenNoobie on 2010-12-14 05:33:17
Wow!  I am both impressed and happy.
Not only does it process my files with special characters correctly, but you handled the chapter request very nicely.  I am impressed with all the options of the command-line version.  I also tried it on a file of size 15MB, and it worked there as well.  I do have a couple findings....

1) I used it on several files, all with special characters.  I didn't see any error messages or crashes, or any real problems at all.

2) I notice that sometimes both the Chinese characters and the Pinyin come out, and sometimes only the Pinyin.  Is that due to the construction of the original m4b or something about the way m4b.py is reading it?  Is there anything that can be done to get the Chinese characters all the time?

3) The question mark ("?") is not allowed as characters in file names, and the period "." is the delimiter between the base filename and the extension.  I notice that "?"'s are removed, and sentences have the "."  However, the characters used in Chinese writing are allowed as file names "?" and "。".  This is not too important, but as a low-priority request - is there any chance to make use these characters when they appear in the chapter name rather than removing the "?" and having double "normal periods" in some file names?  This might best be an option, as these characters may appear unusual to some users.

4) I notice that the special characters are not displayed properly by the "dir" command in Windows DOS command window, although they are displayed correctly in Windows Explorer.  A note to other users: If anyone wants a text file with the filenames (which I use for importing these files into another program), one can browse the directory using Firefox, the copy-paste the file name list to a text file, remove the extra fields (size/timestamp/etc) to get just a list of files.

Thanks again for your great work.
Title: M4B to MP3 (chapter separation)
Post by: daleybox on 2010-12-14 13:19:17
Thanks so much for the chapter naming support, and it's great how it can be customized so others don't have to have it if they don't want!  Thanks again so much, this is great!
Title: M4B to MP3 (chapter separation)
Post by: valekhz on 2010-12-14 19:37:58

2. m4b.py just reads the chapters as constructed by the author so there's nothing the script could do differently to get the chinese characters.

3. "." is valid in filenames and those aren't filtered out. I won't add the question mark thing to the script because it's too specific for this particular case. However, it's really easy to make this change yourself: m4b.py (https://gist.github.com/740925) Changes were made to line 2, 129 and 139. The actual replacement happens at line 139: .replace('?', '?') You can add more replace if you want to change more characters.

4. I have tried many times to get that to work but no success. Your firefox solution is good enough.
Title: M4B to MP3 (chapter separation)
Post by: HydrogenNoobie on 2010-12-17 04:43:14
Valekhz,

2. Ahh.  I suspected that might be the case.  I'm still happy that the majority of the chapters can be parsed.

3. I can understand the the question mark thing is too much of a special case.  And yes - I was able to get my special case to work, thanks to the guidance you provided.

Finally, if you don't mind - one last question:  Several of these files created by the m4B.py have the word / sentence that I want to hear, then 3-4 seconds of silence, then the same word / sentence again.  (same as original m4b chapter)  I actually only want the mp3 to contain the word / phrase once.  Might you be able to make another .py file that takes an mp3 file in, measures the duration of the file, and simply saves only the 1st half under the same name (deleting 2nd half)?  (FYI - I will then run this on all files in a given directory, and then clean up silences and the like with Audacity "Apply Chains" - but audacity doesn't seem to have batch splitting)

Sorry to ask you for something else after all you have done, but you seem to have the skills to do this 1000 times easier than I ever could.

Thank you
Title: M4B to MP3 (chapter separation)
Post by: valekhz on 2010-12-17 18:53:02
Valekhz,

2. Ahh.  I suspected that might be the case.  I'm still happy that the majority of the chapters can be parsed.

3. I can understand the the question mark thing is too much of a special case.  And yes - I was able to get my special case to work, thanks to the guidance you provided.

Finally, if you don't mind - one last question:  Several of these files created by the m4B.py have the word / sentence that I want to hear, then 3-4 seconds of silence, then the same word / sentence again.  (same as original m4b chapter)  I actually only want the mp3 to contain the word / phrase once.  Might you be able to make another .py file that takes an mp3 file in, measures the duration of the file, and simply saves only the 1st half under the same name (deleting 2nd half)?  (FYI - I will then run this on all files in a given directory, and then clean up silences and the like with Audacity "Apply Chains" - but audacity doesn't seem to have batch splitting)

Sorry to ask you for something else after all you have done, but you seem to have the skills to do this 1000 times easier than I ever could.

Thank you

No problem. I made an addition to line 19: m4b_half.py (https://gist.github.com/745445). This will save the first half of each chapter so if you don't want to cut all chapters you should run the old version first and save the ones that shouldn't be cut then run this one.
Title: M4B to MP3 (chapter separation)
Post by: HydrogenNoobie on 2010-12-27 19:08:33
Valekhz,

I just wanted to say thank you one last time.  I have been using m4b.py and m4b_half.py for a few days, and found that it really solves the hardest part of the problem I had been having.  You wrote it to be flexible enough to solve the majority of my problems, and even allow me to make some minor tweaks on my own (I'm also replacing ":" with -" to be Windows/Dos compatible and "[" with "(" to be Anki compatible).

Thank you so much for your efforts.
Title: M4B to MP3 (chapter separation)
Post by: valekhz on 2011-01-03 15:55:42
No problem, I'm glad it worked.

I needed a few more features for myself so I'll release them as v0.5 (https://github.com/valekhz/m4b-converter/zipball/v0.5). Changes:
I also cleaned up and simplified the code which means m4b_half and those modifications will need some changes. But you can safely skip this one if you already have the previous version and don't need the new features. The only thing left on my TODO is making the script work with more python versions than 2.7 but this has a low priority.
Title: M4B to MP3 (chapter separation)
Post by: brian2090 on 2011-02-24 03:52:21
....  The script works well, however, when it extracts the chapters and names to mp3, I have no idea of what order they should have be in.  Could there be an internal counter or something so that you would get something like "Chapter 1 - " prepended to the chapter title?  Otherwise, the only way I see to figure out the order is to listen to each one and hope it starts with the chapter number...


  You should try sorting the mp3 files listing by time and date created; the oldest file should be the first chapter, no?  Just seems like that would work for you, then a rename batch could append the chapter index to the filename.
Title: M4B to MP3 (chapter separation)
Post by: js2002 on 2011-07-28 12:57:15
If anyone is still interested I wrote a little python script to do this. You can find the git repository here: https://github.com/valekhz/m4b-converter (https://github.com/valekhz/m4b-converter). If you don't use git you can just download the python file here: https://github.com/valekhz/m4b-converter/raw/master/m4b.py (https://github.com/valekhz/m4b-converter/raw/master/m4b.py).

You'll need python (only tested with 2.7 so far) and ffmpeg. Place the m4b.py somewhere and drag your *.m4b file onto m4b.py, or use the command line. There's a README in the git repository for more info on how to use it. I haven't been able to test that many .m4b files yet but those I've tried have worked great. I've tested it on Windows 7 and Ubuntu.

Basically it works by parsing the output of ffmpeg -i file.m4b to get the chapter data, encodes the audio and splits it based on the data from ffmpeg. Sorry if the code is a bit messy, haven't been coding in python for a while.



Huh?

this is my log: access denied (its german here "zugriff verweigert")

D:\py>m4b.py -o ./doc --ffmpeg ./bin --encoder ./bin --ext mp3 --no-mp4v2 test.m
4b --debug
INFO: m4bsplit started.
DEBUG: Options:
    ffmpeg: ./bin
    custom_name: %(title)s
    skip_encoding: False
    filename: ['test.m4b']
    encoder: ./bin
    ext: mp3
    encode_opts: -y -i %(infile)s -acodec libmp3lame -ar %(sample_rate)d -ab %(b
it_rate)dk %(outfile)s
    output_dir: ./doc
    debug: True
    pipe_wav: False
    no_mp4v2: True
INFO: Initiating script for file 'test.m4b'.
INFO: Loading metadata using ffmpeg...
DEBUG: Retrieving metadata from output of command: ./bin -i test.m4b
Traceback (most recent call last):
  File "D:\py\m4b.py", line 337, in <module>
    main()
  File "D:\py\m4b.py", line 328, in main
    chapters, sample_rate, bit_rate, metadata = load_metadata(args, log, filenam
e)
  File "D:\py\m4b.py", line 205, in load_metadata
    return ffmpeg_metadata(args, log, filename)
  File "D:\py\m4b.py", line 143, in ffmpeg_metadata
    ignore_errors=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  File "D:\py\m4b.py", line 44, in run_command
    proc = subprocess.Popen(cmd, **kwargs)
  File "C:\Python32\lib\subprocess.py", line 741, in __init__
    restore_signals, start_new_session)
  File "C:\Python32\lib\subprocess.py", line 960, in _execute_child
    startupinfo)
WindowsError: [Error 5] Zugriff verweigert

D:\py>


this is the output without the no v2 parameter:

D:\py>m4b.py -o ./doc --ffmpeg ./bin --encoder ./bin --ext mp3 test.m4b --debug
INFO: m4bsplit started.
DEBUG: Options:
    ffmpeg: ./bin
    custom_name: %(title)s
    skip_encoding: False
    filename: ['test.m4b']
    encoder: ./bin
    ext: mp3
    encode_opts: -y -i %(infile)s -acodec libmp3lame -ar %(sample_rate)d -ab %(b
it_rate)dk %(outfile)s
    output_dir: ./doc
    debug: True
    pipe_wav: False
    no_mp4v2: False
INFO: Initiating script for file 'test.m4b'.
INFO: Loading metadata using libmp4v2...
Traceback (most recent call last):
  File "D:\py\m4b.py", line 337, in <module>
    main()
  File "D:\py\m4b.py", line 328, in main
    chapters, sample_rate, bit_rate, metadata = load_metadata(args, log, filenam
e)
  File "D:\py\m4b.py", line 208, in load_metadata
    return mp4v2_metadata(filename)
  File "D:\py\m4b.py", line 188, in mp4v2_metadata
    from libmp4v2 import MP4File
ImportError: No module named libmp4v2

D:\py>
Title: M4B to MP3 (chapter separation)
Post by: js2002 on 2011-07-28 14:55:58
fixed 1 problem in line 44:

    proc = subprocess.Popen("runas /user:Admin cmd.exe", **kwargs)

as admin i come little bit closer...
but then ist stops at:

INFO: Loading metadata using ffmpeg...
DEBUG: Retrieving metadata from output of command: ./bin -i test.m4b
Title: M4B to MP3 (chapter separation)
Post by: alexf on 2011-08-23 22:40:53
thanks to valekhz for creating this script
Title: M4B to MP3 (chapter separation)
Post by: swavek on 2011-10-15 18:58:59
First off, many thanks to valekhz for building this tool. There is only one other program out there that I found (Bigasoft Audio Converter), but it doesn't have command-line support and so this tool still reigns supreme.

In hopes that valekhz is still open to tweaking the tool, I ran into one problem. For some reason, the tool crashes on The Economist podcasts with this message:
Traceback (most recent call last):
  File "C:\Programs\Python27\m4b.py", line 337, in <module>
    main()
  File "C:\Programs\Python27\m4b.py", line 334, in main
    split(args, log, output_dir, encoded_file, chapters)
  File "C:\Programs\Python27\m4b.py", line 290, in split
    chapter_name = unicode(chapter_name, 'utf-8')
UnicodeDecodeError: 'utf8' codec can't decode byte 0xff in position 0: invalid start byte

Here is an example file I tried to split: http://dl.dropbox.com/u/19007038/13%20Inte...C%20The%20E.m4a (http://dl.dropbox.com/u/19007038/13%20International%20-%2014_07_2011%2C%20The%20E.m4a)
(I know it's an m4a extension, but the same issue happens on m4b's)

Thanks to valekhz or anyone else who can help with this!
Title: M4B to MP3 (chapter separation)
Post by: ertdredge on 2011-10-16 03:57:38
As with everyone who's posted, major props to valekhz for building and maintaining this.

I got this working on Mac (Snow Leopard 10.6) with some fiddling:


Which all sums up to something like this:


...and then, open a fresh Terminal window (to pick up the new Python version that the Python installer adds to your path), and

Code: [Select]
sudo port install ffmpeg
sudo port install mp4v2
export DYLD_LIBRARY_PATH=/opt/local/lib
cd /tmp
curl -O http://trac.macports.org/export/38059/trunk/dports/audio/lame/Portfile
sudo port install


Then cd back to where you downloaded and unzipped valekhz-m4b-converter and do the expected

Code: [Select]
python m4b.py filename.m4a


Voila.  You can add the export DYLD_LIBRARY_PATH=/opt/local/lib into your ~/.bash_profile for future convenience.  Possibly you don't need to do all of this in OS 10.7 but I'm dragging my feet on the upgrade.

Thanks again, valekhz!

Title: M4B to MP3 (chapter separation)
Post by: fyrebender360 on 2011-11-09 22:23:19
Absolutely brilliant!!!!  Thanks for all the hard work valekhz.
Title: M4B to MP3 (chapter separation)
Post by: Jaantat on 2012-06-16 15:30:10
I tried all different versions but still it makes just one mp3 file
Can someone help me out?
i can see that it reads the chapter names but it wont make multiple files

Code: [Select]
C:\Python27>python m4b.py --debug game.m4b
INFO: m4bsplit started.
DEBUG: Options:
ffmpeg: ffmpeg
custom_name: %(title)s
skip_encoding: False
filename: ['game.m4b']
encoder: ffmpeg
ext: mp3
encode_opts: -y -i %(infile)s -acodec libmp3lame -ar %(sample_rate)d -ab %(b
it_rate)dk %(outfile)s
output_dir:
debug: True
pipe_wav: False
no_mp4v2: False
INFO: Initiating script for file 'game.m4b'.
INFO: Loading metadata using libmp4v2...
INFO:
Metadata:
  Chapters: 135
  Bit rate: 64 kbit/s
  Sampling freq: 22050 Hz
DEBUG:
  Chapter data:
  <Chapter Title="00 - Prologue 1", Start=0:00:00, End=0:10:00, Dura
tion=0:10:00>
<Chapter Title="Part 1.1", Start=0:10:00, End=0:20:00, Duration=0:10:00>
<Chapter Title="Part 1.2", Start=0:20:00, End=0:24:33.005000, Duration=0:04:33.0
05000>
-----------------------
-----------------------
<Chapter Title="Part 38.3", Start=16:09:59.963000, End=16:17:54.605000, Duration
=0:07:54.642000>
INFO: Encoding audio...
DEBUG: Encoding with command: ffmpeg -y -i game.m4b -acodec libmp3lame -ar 22050
 -ab 64k game\temp\game.mp3
ffmpeg version N-41416-g718607b Copyright © 2000-2012 the FFmpeg developers
  built on Jun  8 2012 12:46:19 with gcc 4.6.3
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-ru
ntime-cpudetect --enable-avisynth --enable-bzlib --enable-frei0r --enable-libass
 --enable-libcelt --enable-libopencore-amrnb --enable-libopencore-amrwb --enable
-libfreetype --enable-libgsm --enable-libmp3lame --enable-libnut --enable-libope
njpeg --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libth
eora --enable-libutvideo --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-
libvorbis --enable-libvpx --ena  libavutil   51. 56.100 / 51. 56.100
  libavcodec 54. 25.100 / 54. 25.100
  libavformat 54.  6.101 / 54.  6.101
  libavdevice 54.  0.100 / 54.  0.100
  libavfilter 2. 78.101 /  2. 78.101
  libswscale   2.  1.100 /  2.  1.100
  libswresample  0. 15.100 /  0. 15.100
  libpostproc 52.  0.100 / 52.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'game.m4b':
  Metadata:
major_brand : M4A
minor_version  : 0
compatible_brands: 3gp5isom
creation_time  : 2011-04-30 13:52:34
genre   : Audiobook
media_type   : 2
encoder : Chapter and Verse V 1.4
title   : 01 - A Game of Thrones - Part 1
artist   : George R.R. Martin
album   : A Game of Thrones
composer : George R.R. Martin
track   : 1/2
  Duration: 16:17:54.64, start: 0.000000, bitrate: 60 kb/s
Chapter #0.0: start 0.000000, end 600.000000
Metadata:
  title   : 00 - Prologue 1
Chapter #0.1: start 600.000000, end 1200.000000
Metadata:
  title   : Part 1.1
-----------------------------
-------------------------------
Metadata:
  title   : Part 38.1
Chapter #0.133: start 57600.000000, end 58200.000000
Metadata:
  title   : Part 38.2
Chapter #0.134: start 58200.000000, end 58674.642721
Metadata:
  title   : Part 38.3
Stream #0:0(und): Audio: aac (mp4a / 0x6134706D), 22050 Hz, stereo, s16, 59
kb/s
Metadata:
  creation_time  : 2011-04-30 13:52:34
Stream #0:1(und): Subtitle: mov_text (text / 0x74786574)
Metadata:
  creation_time  : 2011-04-30 13:54:41
Output #0, mp3, to 'game\temp\game.mp3':
  Metadata:
major_brand : M4A
minor_version  : 0
compatible_brands: 3gp5isom
TDEN : 2011-04-30 13:52:34
TCON : Audiobook
media_type   : 2
TRCK : 1/2
TIT2 : 01 - A Game of Thrones - Part 1
TPE1 : George R.R. Martin
TALB : A Game of Thrones
TCOM : George R.R. Martin
TSSE : Lavf54.6.101
Chapter #0.0: start 0.000000, end 600.000000
Metadata:
  title   : 00 - Prologue 1
Chapter #0.1: start 600.000000, end 1200.000000
Metadata:
  title   : Part 1.1
Chapter #0.2: start 1200.000000, end 1473.005442
Metadata:
  title   : Part 1.2
Chapter #0.3: start 1473.005442, end 1800.000000
  ------------------
-------------------
Metadata:
  title   : Part 38.2
Chapter #0.134: start 58200.000000, end 58674.642721
Metadata:
  title   : Part 38.3
Stream #0:0(und): Audio: mp3, 22050 Hz, stereo, s16, 64 kb/s
Metadata:
  creation_time  : 2011-04-30 13:52:34
Stream mapping:
  Stream #0:0 -> #0:0 (aac -> libmp3lame)
Press [q] to stop, [?] for help
size=  458397kB time=16:17:54.65 bitrate=  64.0kbits/s
video:0kB audio:458396kB global headers:0kB muxing overhead 0.000119%
INFO: Splitting chapter  1/135 '00 - Prologue 1'...
DEBUG: Splitting with command: ffmpeg -y -acodec copy -t 600.0 -ss 0.0 -i game\t
emp\game.mp3 game\_tmp_1.mp3
ERROR:
An error occurred while splitting audio file.
  Command: ffmpeg -y -acodec copy -t 600.0 -ss 0.0 -i game\temp\game.mp3 game\_t
mp_1.mp3
  Return code: 1
  Output: ---->
ffmpeg version N-41416-g718607b Copyright © 2000-2012 the FFmpeg developers
  built on Jun  8 2012 12:46:19 with gcc 4.6.3
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-ru
ntime-cpudetect --enable-avisynth --enable-bzlib --enable-frei0r --enable-libass
 --enable-libcelt --enable-libopencore-amrnb --enable-libopencore-amrwb --enable
-libfreetype --enable-libgsm --enable-libmp3lame --enable-libnut --enable-libope
njpeg --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libth
eora --enable-libutvideo --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-
libvorbis --enable-libvpx --ena  libavutil   51. 56.100 / 51. 56.100
  libavcodec 54. 25.100 / 54. 25.100
  libavformat 54.  6.101 / 54.  6.101
  libavdevice 54.  0.100 / 54.  0.100
  libavfilter 2. 78.101 /  2. 78.101
  libswscale   2.  1.100 /  2.  1.100
  libswresample  0. 15.100 /  0. 15.100
  libpostproc 52.  0.100 / 52.  0.100
Unknown decoder 'copy'
Title: M4B to MP3 (chapter separation)
Post by: cynepnaxa on 2012-07-15 02:35:09
Many thanks to valekhz! Note for customers. Valekhz's script is working fine. If smtg not work follow instruction from begin or see run options.

On Ubuntu 12.04 you just run in terminal in any folder:

sudo apt-get install python2.7 ffmpeg libavcodec-extra-53 mp4v2-utils libmp4v2-dev libmp4v2-2 git
git clone https://github.com/valekhz/m4b-converter.git (https://github.com/valekhz/m4b-converter.git)
cd ./m4b-converter
python m4b.py --no-mp4v2 PATH_TO_YOUR_M4B_FILE_ABSOLUTE_OR_RELATIVE_FROM_NEW_DIR_m4b-converter


First off, many thanks to valekhz for building this tool. There is only one other program out there that I found (bigsoftasses Audio Converter), but it doesn't have command-line support and so this tool still reigns supreme.

In hopes that valekhz is still open to tweaking the tool, I ran into one problem. For some reason, the tool crashes on The Economist podcasts with this message:
Traceback (most recent call last):
  File "C:\Programs\Python27\m4b.py", line 337, in <module>
    main()
  File "C:\Programs\Python27\m4b.py", line 334, in main
    split(args, log, output_dir, encoded_file, chapters)
  File "C:\Programs\Python27\m4b.py", line 290, in split
    chapter_name = unicode(chapter_name, 'utf-8')
UnicodeDecodeError: 'utf8' codec can't decode byte 0xff in position 0: invalid start byte

Here is an example file I tried to split: http://dl.dropbox.com/u/19007038/13%20Inte...C%20The%20E.m4a (http://dl.dropbox.com/u/19007038/13%20International%20-%2014_07_2011%2C%20The%20E.m4a)
(I know it's an m4a extension, but the same issue happens on m4b's)

Thanks to valekhz or anyone else who can help with this!


--no-mp4v2 works for me
Title: M4B to MP3 (chapter separation)
Post by: cynepnaxa on 2012-07-17 01:08:19
Valekhz's script is working fine.

And soon i found problems with unicode filenames on linux. I fix it, but then i found that it's looks like already fixed in Ramovsky's branch:
https://github.com/ramovsky/m4b-converter (https://github.com/ramovsky/m4b-converter)
Title: M4B to MP3 (chapter separation)
Post by: vitos on 2012-08-22 11:29:11
As with everyone who's posted, major props to valekhz for building and maintaining this.

I got this working on Mac (Snow Leopard 10.6) with some fiddling:


Thank you!
(especially that you registered here just for sharing this useful extra information for OS X users)
Title: M4B to MP3 (chapter separation)
Post by: theviki on 2012-08-31 12:48:53
If this is still relevant, I found an easier way.
(The script works great though)
This is much more simpler.
1. Get bigsoftasses Audio Converter from here: http://www.bigsoftasses.com/audio-converter.html (http://www.bigsoftasses.com/audio-converter.html)
    Or the full version for free from here (Windows only): http://adf.ly/CQezy (http://adf.ly/CQezy)
* To install it, run 'Software' and follow the onscreen instructions.
  Run the program.
  Register with any name, and key from 'Serial.txt'.
2. Follow this article: http://www.bigsoftasses.com/articles/convert-m...-converter.html (http://www.bigsoftasses.com/articles/convert-m4b-with-m4b-converter.html)

I do not encourage piracy, and please support the developers by buying the product, like I have.
Please use it for testing purposes only, and uninstall it when you're done.
Title: M4B to MP3 (chapter separation)
Post by: nmallears on 2013-06-18 17:15:51
I tried all different versions but still it makes just one mp3 file
Can someone help me out?
i can see that it reads the chapter names but it wont make multiple files

Code: [Select]
C:\Python27>python m4b.py --debug game.m4b
INFO: m4bsplit started.
DEBUG: Options:
ffmpeg: ffmpeg
custom_name: %(title)s
skip_encoding: False
filename: ['game.m4b']
encoder: ffmpeg
ext: mp3
encode_opts: -y -i %(infile)s -acodec libmp3lame -ar %(sample_rate)d -ab %(b
it_rate)dk %(outfile)s
output_dir:
debug: True
pipe_wav: False
no_mp4v2: False
INFO: Initiating script for file 'game.m4b'.
INFO: Loading metadata using libmp4v2...
INFO:
Metadata:
  Chapters: 135
  Bit rate: 64 kbit/s
  Sampling freq: 22050 Hz
DEBUG:
  Chapter data:
  <Chapter Title="00 - Prologue 1", Start=0:00:00, End=0:10:00, Dura
tion=0:10:00>
<Chapter Title="Part 1.1", Start=0:10:00, End=0:20:00, Duration=0:10:00>
<Chapter Title="Part 1.2", Start=0:20:00, End=0:24:33.005000, Duration=0:04:33.0
05000>
-----------------------
-----------------------
<Chapter Title="Part 38.3", Start=16:09:59.963000, End=16:17:54.605000, Duration
=0:07:54.642000>
INFO: Encoding audio...
DEBUG: Encoding with command: ffmpeg -y -i game.m4b -acodec libmp3lame -ar 22050
 -ab 64k game\temp\game.mp3
ffmpeg version N-41416-g718607b Copyright © 2000-2012 the FFmpeg developers
  built on Jun  8 2012 12:46:19 with gcc 4.6.3
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-ru
ntime-cpudetect --enable-avisynth --enable-bzlib --enable-frei0r --enable-libass
 --enable-libcelt --enable-libopencore-amrnb --enable-libopencore-amrwb --enable
-libfreetype --enable-libgsm --enable-libmp3lame --enable-libnut --enable-libope
njpeg --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libth
eora --enable-libutvideo --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-
libvorbis --enable-libvpx --ena  libavutil   51. 56.100 / 51. 56.100
  libavcodec 54. 25.100 / 54. 25.100
  libavformat 54.  6.101 / 54.  6.101
  libavdevice 54.  0.100 / 54.  0.100
  libavfilter 2. 78.101 /  2. 78.101
  libswscale   2.  1.100 /  2.  1.100
  libswresample  0. 15.100 /  0. 15.100
  libpostproc 52.  0.100 / 52.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'game.m4b':
  Metadata:
major_brand : M4A
minor_version  : 0
compatible_brands: 3gp5isom
creation_time  : 2011-04-30 13:52:34
genre   : Audiobook
media_type   : 2
encoder : Chapter and Verse V 1.4
title   : 01 - A Game of Thrones - Part 1
artist   : George R.R. Martin
album   : A Game of Thrones
composer : George R.R. Martin
track   : 1/2
  Duration: 16:17:54.64, start: 0.000000, bitrate: 60 kb/s
Chapter #0.0: start 0.000000, end 600.000000
Metadata:
  title   : 00 - Prologue 1
Chapter #0.1: start 600.000000, end 1200.000000
Metadata:
  title   : Part 1.1
-----------------------------
-------------------------------
Metadata:
  title   : Part 38.1
Chapter #0.133: start 57600.000000, end 58200.000000
Metadata:
  title   : Part 38.2
Chapter #0.134: start 58200.000000, end 58674.642721
Metadata:
  title   : Part 38.3
Stream #0:0(und): Audio: aac (mp4a / 0x6134706D), 22050 Hz, stereo, s16, 59
kb/s
Metadata:
  creation_time  : 2011-04-30 13:52:34
Stream #0:1(und): Subtitle: mov_text (text / 0x74786574)
Metadata:
  creation_time  : 2011-04-30 13:54:41
Output #0, mp3, to 'game\temp\game.mp3':
  Metadata:
major_brand : M4A
minor_version  : 0
compatible_brands: 3gp5isom
TDEN : 2011-04-30 13:52:34
TCON : Audiobook
media_type   : 2
TRCK : 1/2
TIT2 : 01 - A Game of Thrones - Part 1
TPE1 : George R.R. Martin
TALB : A Game of Thrones
TCOM : George R.R. Martin
TSSE : Lavf54.6.101
Chapter #0.0: start 0.000000, end 600.000000
Metadata:
  title   : 00 - Prologue 1
Chapter #0.1: start 600.000000, end 1200.000000
Metadata:
  title   : Part 1.1
Chapter #0.2: start 1200.000000, end 1473.005442
Metadata:
  title   : Part 1.2
Chapter #0.3: start 1473.005442, end 1800.000000
  ------------------
-------------------
Metadata:
  title   : Part 38.2
Chapter #0.134: start 58200.000000, end 58674.642721
Metadata:
  title   : Part 38.3
Stream #0:0(und): Audio: mp3, 22050 Hz, stereo, s16, 64 kb/s
Metadata:
  creation_time  : 2011-04-30 13:52:34
Stream mapping:
  Stream #0:0 -> #0:0 (aac -> libmp3lame)
Press [q] to stop, [?] for help
size=  458397kB time=16:17:54.65 bitrate=  64.0kbits/s
video:0kB audio:458396kB global headers:0kB muxing overhead 0.000119%
INFO: Splitting chapter  1/135 '00 - Prologue 1'...
DEBUG: Splitting with command: ffmpeg -y -acodec copy -t 600.0 -ss 0.0 -i game\t
emp\game.mp3 game\_tmp_1.mp3
ERROR:
An error occurred while splitting audio file.
  Command: ffmpeg -y -acodec copy -t 600.0 -ss 0.0 -i game\temp\game.mp3 game\_t
mp_1.mp3
  Return code: 1
  Output: ---->
ffmpeg version N-41416-g718607b Copyright © 2000-2012 the FFmpeg developers
  built on Jun  8 2012 12:46:19 with gcc 4.6.3
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-ru
ntime-cpudetect --enable-avisynth --enable-bzlib --enable-frei0r --enable-libass
 --enable-libcelt --enable-libopencore-amrnb --enable-libopencore-amrwb --enable
-libfreetype --enable-libgsm --enable-libmp3lame --enable-libnut --enable-libope
njpeg --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libth
eora --enable-libutvideo --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-
libvorbis --enable-libvpx --ena  libavutil   51. 56.100 / 51. 56.100
  libavcodec 54. 25.100 / 54. 25.100
  libavformat 54.  6.101 / 54.  6.101
  libavdevice 54.  0.100 / 54.  0.100
  libavfilter 2. 78.101 /  2. 78.101
  libswscale   2.  1.100 /  2.  1.100
  libswresample  0. 15.100 /  0. 15.100
  libpostproc 52.  0.100 / 52.  0.100
Unknown decoder 'copy'


I know this was a year ago, but I had the same issue, and tracked down the cause, so to document it for anyone else who comes along later like me:

The problem is that the ffmpeg folks changed how they parse the command line somewhere around early November of 2011, so if your version of ffmpeg is too recent, it won't work with the ffmpeg commands generated by this script. See here: https://bugs.archlinux.org/task/27647 (https://bugs.archlinux.org/task/27647) for more details.

So your options are to "downgrade" ffmpeg, or update the script to rearrange the ffmpeg commands.
Title: M4B to MP3 (chapter separation)
Post by: bitbanger on 2014-10-30 18:06:09
I know this was a year ago, but I had the same issue, and tracked down the cause, so to document it for anyone else who comes along later like me:

The problem is that the ffmpeg folks changed how they parse the command line somewhere around early November of 2011, so if your version of ffmpeg is too recent, it won't work with the ffmpeg commands generated by this script. See here: https://bugs.archlinux.org/task/27647 (https://bugs.archlinux.org/task/27647) for more details.

So your options are to "downgrade" ffmpeg, or update the script to rearrange the ffmpeg commands.


(Another 18 months later) Thanks for that @nmallears.  I ran into the same issue using the most current build of ffmpeg.  Since I wanted to use the latest ffmpeg build, I dug in and determined the solution is pretty easy.  The command line change is simple.

In m4b.py, in the function split, change the assignment for the split_cmd variable from
Code: [Select]
split_cmd = '%(ffmpeg)s -y -acodec copy -t %(duration)s -ss %(start)s -i %(outfile)s %(infile)s'

to
Code: [Select]
split_cmd = '%(ffmpeg)s -y -t %(duration)s -ss %(start)s -i %(outfile)s -acodec copy %(infile)s'

The codec command line option needs to be moved to be relevant for the input file in our case.    The changes to the ffmpeg command line parser now include enforcement that parameters pertaining to the input file must follow the input filename on the command line.  Likewise, commands pertaining to the output file (none in this case) must follow it as well.
I moved the switches for -acodec copy farther down the parameter list.  m4b.py Works correctly now with ffmpeg version N-67227-g39680ca Built Oct 27th, 2014 and Python 2.7.8  By the way, don't try Python 3.x as more work would have to be done to get it to run.

Props go out to valekhz for coming up with this slick solution.  Sure beats paying 25 USD for a commercial app that likely uses ffmpeg anyway