September 18, 2009

Something about iTunes 9 is possibly breaking/fixing my mp4’s

I recently updated to the latest version of iTunes, iTunes 9. My first reaction to the install of it is well let’s just say, it wasn’t one of those feelings of joy. I’m not going to go into my thoughts about iTunes either, but what I am going to focus on is the something that has changed due to installing it, and the impact it has had on my media.

The problem I am seeing is that all of a sudden ALL of my mp4/m4v videos are showing up with durations that insanely way off the mark. As an example, if I go to the file properties of one of my m4v files, it shows a play time of 2:05:10, but when I open the video in quicktime or through iTunes,
It thinks the video is 65:23:14! The video actually plays fine, but the timer bar is really scaled out, and clicking anywhere on it just goes to dead space once you get past the actual length of the video’s real time scale.

Here is the timescale ticked at 00:00:00
(Things appear to be normal at first glance)

Here is the timescale ticked at the end of the scale, 43:28:15?
(The movie is only 01:48:40 and should not be 43:28:15)

Here is the timescale ticked at 00:32:40
(This point in time is in reference to the above scale also being wrong)

Here is what the tack properties look like from QuickTime
(Notice that somehow only the video track is what is wrong, hmmm)

At first, I thought it was iTunes and or Quicktime that was the culprit, and it is, but not entirely in the way I first thought, as I was also seeing the problem appear in other media players, but then again that could be just a side effect of the root problem. The thing of it is, what is it that has changed to cause this, as this problem was not there before I installed iTunes 9. I think I may have found the culprits, I say culprits, as I think this is a two part problem.

First, iTunes has definitely done something to the mp4 decoder, and second, one of the tools I use for encoding is doing something the others aren’t.

To better understand how I think I found where the problems are, you need to know what tools I am using to create my mp4's.
I do a lot video encoding, my tools of choice for mp4 encoding are:
HandBrake -
Mencoder -

HandBrake has an option to add chapters to an mp4,
but If I am not using HandBrake, I usually use add the chapters after the fact.
The tool that I use to add chapters after the fact has been:
mp4creator ( or
mp4chaps (,
you might say that mp4box (
has the option to also add chapters, which it does,
but it does not have the ability to add quicktime style chapters,
it just does the nero version of chapters.

So for giggles, I went ahead and created some new video encodes and checked the state of the mp4 at each step of the encode process, I also went as far as using previous and upcoming beta’s of the tools I use, and some others, just to be sure.

The first program I tried was HandBrake, I did not see the issue appear, and I also did not see the problem appear if I created it with or without chapters.

The second program I tried was Mencoder, which cannot add chapters, and also I did not see the issue appear .

The third program I tried, which I needed to for adding chapters was mp4creator,
I don’t use mp4creator for muxing, I just use it for adding chapters with the following syntax:

mp4creator.exe -c "mychapters.chap" "mymovie.m4v"

Bam! The file now showed the issue, so after that ah ha moment, I went ahead and tried mp4chaps for adding the chapters, and well sure enough, since it is from the same branch, it too showed the problem.

It also worth noting that even after using any of my tools to remove the chapters track, it did not revert the mp4 back to showing a correct duration.

So what is it that is causing the problem?

I think that either Apple updated the way in which they interpret the contents of mp4/m4v files, or mp4creator and mp4v2 tools are incorrectly modifying the files in some way, in reality it’s probably a little of both.
The reason I say that is because none of this was a problem prior to installing iTunes 9.

So what can you do to fix the problem if you have it?

You can use mp4box to demux the file, and then to remux back.
Doing this will recreate the mp4 container correclty, but sadly without the chapters, as this tool does not have the ability to import quicktime style chapters.
But I can live with that for now, chapters were really only usfull and usable on the pc or apple devices anyway.

You can use the following example to get information about the tracks:

mp4box.exe -info "filename"

You can use the following example to demux and remux the file correctly
(note: you'll want to know the fps of the video, or mp4box defaults to 25fps)

mp4box.exe -raw 1 "filename" -out "filename.h264"

mp4box.exe -raw 2 "filename" -out "filename.aac"

mp4box.exe -add "filename.h264":fps=23.976 -add "filename.aac" "newfilename.mp4"

Here is an example of the newly remuxed video
(Notice that the timescale appears as it should)

Here is an example of the newly remuxed video
(Notice that the end is the actual real intended end length)

Here is an example of the newly remuxed video
(Notice that the properties also show things correctly)

If you happen to run into this problem, I hope this information helps you get your media files back to the way they should be.
In my stumbleing around looking for answers, I ran into this post on sourceforge where the mp4creator program is hosted, it was nice to see that I wasnt the only one who happened to notice this problem.

If you run into any other ways of dealing with this let me know, I would be interested to find alternatives ways of fixing the problem. As I had to write a script that scoured through my Windows Home Server and had it demux and remux the plethora of videos I have on it, and I am glad to say they are all now working again as they should, without the chapter markers of though, which I will tackle another day.

If your looking to revert back to iTunes 8 here are the download links:


  1. I ran into this problem as well. There's a workaround. After you add the chapters, extract the video stream using mp4box, and then remove the video stream using mp4box. You should now have one raw video file and an mp4 containing only the audio and chapters. Remux the mp4, making sure mp4box overwrites the oldfile (ex: "mp4box.exe -add video.h264:23.976 chaptered_audio.mp4"). Your video track will no longer be track 1 in the mp4, but that doesn't seem to break anything.

  2. Hey Rich, when are we gonna see some updates! Always good stuff man... Darron