This is a surprisingly subtle problem. It's taken me quite a while and many passes to solve all the corner cases. I've put my solution online here.
My particular use case is making
*.mp4 files for playback on an iPad Air 2 using macOS, but the tools being used are all generally available on Linux, and the solution is readily adapted to other device types.
Here are some of my notes on doing that adaptation, from the project's home page:
The project consists of three Bash shell scripts which drive
atomicparsley to convert files of any type supported by these programs into H.264 *.mp4 files suitable for playing on an iPad Air 2 class device.
The scripts do contain some macOSisms, so the scripts will need some adjustment for use on Linux, or for use on Windows under Cygwin, MSYS, or WSL:
rmtrash program acts like
rm except that the files are moved to the user's Trash folder. Many similar tools exist for other systems, or you could just replace this line in
ipad-h264 with an
rm call or some other "move out of the way" type of command.
open call is a macOS mechanism for opening a file using the GUI program associated with it. I have
*.mp4 files associated with Subler here because the next step after remuxing or transcoding is to look at the tags, apply cover art, etc. Under Cygwin, you can get the same effect with
cygstart. I assume there is a way to get a similar effect on Linux. Alternately, you could just hard-code the next step in place of my
You can download the software from the repository using the links in the Downloads section of the home page.