0

I'm writing a code which creates MP4 files. To check it I've created an MP4 file.

The file is played correctly by VLC and Firefox, but not by ffplay or by Chrome. I guess the file contains error which VLC can cope with but more aggressive MP4 reader cannot.

I've thought about repairing the file and check what are the differences to fix my code. However I tried some programs to repair MP4 files, without success until now.

Can someone reccommend another way to debug the problem, or a good tool to fix MP4 files? The file is a fragmented MP4 contains both the init section (ftyp, moov boxes) and one fragment section (moof and empty sidx).

Here is the video file:

https://www.dropbox.com/s/rojxzvkfxfj31u8/400k00001-3_serialized.mp4?dl=0

EDIT: It doesn't work also in Firefox, when using Media Source Extensions like in this example: http://people.mozilla.org/~jyavenard/tests/mse_mp4/paper.html

(don't forget to enable MSE on Firefox, as explained here: http://www.linuxveda.com/2015/04/02/enable-mse-native-html5-support-firefox-linux/)

EDIT2: In chrome://media-internals, I see the following error with the above example: Append: stream parsing failed. Data size=131072 append_window_start=0 append_window_end=inf

(Change the URL to be the file and change the codec to be 'avc1.4d401f' instead of 'avc1.64000d,mp4a.40.2').

MaMazav
  • 1,773
  • 3
  • 19
  • 33
  • You should show your code that created the MP4 file. – llogan May 12 '15 at 16:57
  • 1
    Your file appears to be badly authored, even the encoding date is wrong (1904..). VLC also complains about it, but chooses to ignore the issues: [000000010050d158] mp4 demux warning: no chunk defined [000000010050d158] mp4 demux debug: track[Id 0x1] read 0 chunk [000000010050d158] mp4 demux warning: STTS table of 0 entries [000000010050d158] mp4 demux debug: track[Id 0x1] read 0 samples length:0s So LordNeckbeard is absolutely right. You need to show your code :) – feepk May 16 '15 at 16:42

1 Answers1

2

Finally solved the problem by fixing some errors in the file. Here are the fixes if someone encounters similar problems:

  • duration in the MVHD box should be zero.
  • MEHD box should be contained in the MVEX box. The MEHD box contains the fragment_duration field.
  • sample_flags (in the TREX box) should 6 reserved MSBits should be '1' instead of '0'.
  • volume field in TKHD box should be 0 instead of 1 (1 is for audio).
  • dimensions was wrong, both in TKHD and STSD boxes.
  • codec parameters in avcC box was wrong. Exactly the same error as the third comment in: https://stackoverflow.com/a/11869227/2463642. See this answer for correct parsing: html5 video tag codecs attribute
  • MFHD contained sequence_number of zero. Should start from 1.
  • TFDT box was missing. Should be contained in TRAF box and indicate the base_media_decode_time of each fragment.
  • TRUN was missing a data_offset field. It caused FFMPEG to think that the data starts at the beginning of the MOOF box.
  • sample_flags was wrong in the TRUN box. All samples marked as a "difference frame", no key frame to start at... Here is an explanation about those flags: https://msdn.microsoft.com/en-us/library/ff469599.aspx
Community
  • 1
  • 1
MaMazav
  • 1,773
  • 3
  • 19
  • 33