I came across this joke mp4 file online. (Warning: direct download link to an 8 mb file.) Media players as well as ffmpeg both list the file as having a length of 596523:14:07.00 (!). My first guess was that the video might have used a very low frame rate, but ffmpeg lists a frame rate of 10 fps, with no frames having a variable frame rate. What is going on in the encoding of this file to give it such a long length?
1 Answer
There are several things we can note here:
- The file stops playing after 0:05:30.
- If you remux the file (mkvtools for example) you do have 5:30 displayed as the length.
- The original file does in fact show the ridiculous length.
So, although it is a funny joke, it is not as cool as I first thought. Nobody has figured out how to do an infinite loop of frames or anything similar to that. This appears to be just a header of the file that is not matching the data.
How does the player (or most tools) figure out the length of the video? They do not read the whole file, otherwise the load times of files would be impractical. So at the start of the file there is a marker that says the length, and the player just trusts it.
Let's run through the maths:
596523:14:07.00 = ((596523*60)+14)*60+7 = 2147483647 seconds
2147483647 (base 10) = 7FFFFFFF (base 16)
Oh, that's a nice number. Now let's open the file up with a hex editor, right at the start we see
00000000: 00 00 00 18 66 74 79 70 6d 70 34 32 00 00 00 00 ....ftypmp42....
00000010: 6d 70 34 32 6d 70 34 31 00 01 69 7b 6d 6f 6f 76 mp42mp41..i{moov
00000020: 00 00 00 6c 6d 76 68 64 00 00 00 00 dd 69 a6 fb ...lmvhd.....i..
00000030: dd 69 a6 fb 00 00 00 01 7f ff ff ff 00 01 00 00 .i..............
There's our culprit, right at the 0x38 mark. Let's edit it and see what happens. I actually get a funnier "joke" if I change 7f to ff at the start. To understand why it works, please see How the negative numbers are stored in memory?.