Joining Video files and adding chapters for each [duplicate]

I use mp4v2 in my open-source app to join together iTunes tracks. You can install mp4v2 using Homebrew.

To add chapters, create a text file in the following format:

00:00:00.000 Name of first chapter
00:00:23.500 Name of second chapter
00:02:40.700 Third chapter, etc

You might be able to automate the creation of the chapter file by using ffprobe (see example written in AppleScript and shell script).

For an output file called "OUTPUT.m4a", save the chapters file as "OUTPUT.chapters.txt". Then run mp4chaps -i OUTPUT.m4a in the same directory as the output file to add the chapters to it.