Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MOV/MP4 parsing issues #330

Merged
merged 1 commit into from
Mar 21, 2018
Merged

Fix MOV/MP4 parsing issues #330

merged 1 commit into from
Mar 21, 2018

Conversation

nagix
Copy link
Collaborator

@nagix nagix commented Mar 20, 2018

Problems

I noticed a few issues of MOV and MP4 parsing.

[QuickTime] Major Brand = Apple QuickTime (.MOV/QT)
[QuickTime] Minor Version = 512
[QuickTime] Compatible Brands = [Apple QuickTime (.MOV/QT)]
[QuickTime] Creation Time = Fri Jan 01 00:00:00 +06:55 1904
[QuickTime] Modification Time = Fri Jan 01 00:00:00 +06:55 1904
[QuickTime] Duration = 01:32:3650                                  <-- Problem 1
[QuickTime] Media Time Scale = 1000
[QuickTime] Duration in Seconds = 5.57
[QuickTime] Preferred Rate = 1
[QuickTime] Preferred Volume = 1
[QuickTime] Preview Time = 0
[QuickTime] Preview Duration = 0
[QuickTime] Poster Time = 0
[QuickTime] Selection Time = 0
[QuickTime] Selection Duration = 0
[QuickTime] Current Time = 0
[QuickTime] Next Track ID = 3
ERROR: End of data reached.
[QuickTime Video] Creation Time = Fri Jan 01 00:00:00 SGT 1904
[QuickTime Video] Modification Time = Fri Jan 01 00:00:00 SGT 1904
[QuickTime Video] Opcolor = 0 0 0
[QuickTime Video] Graphics Mode = Copy
[QuickTime Video] Vendor = FFmpeg
[QuickTime Video] Compression Type = MPEG-4
[QuickTime Video] Temporal Quality = 512
[QuickTime Video] Spatial Quality = 512
[QuickTime Video] Width = 560 pixels
[QuickTime Video] Height = 320 pixels
[QuickTime Video] Compressor Name = mpeg4
[QuickTime Video] Depth = Unknown (0)                              <-- Problem 2
[QuickTime Video] Color Table = Color table within file
[QuickTime Video] Horizontal Resolution = 72
[QuickTime Video] Vertical Resolution = 72
ERROR: End of data reached.                                        <-- Problem 3
[QuickTime Sound] Creation Time = Fri Jan 01 00:00:00 SGT 1904
[QuickTime Sound] Modification Time = Fri Jan 01 00:00:00 SGT 1904
[QuickTime Sound] Balance = 0
[QuickTime Sound] Format = MPEG-4, Advanced Audio Coding (AAC)
[QuickTime Sound] Number of Channels = 1
[QuickTime Sound] Sample Size = 16
[QuickTime Sound] Sample Rate = 44100
[MP4] Major Brand = MP4 v2 [ISO 14496-14]
[MP4] Minor Version = 0
[MP4] Compatible Brands = [MP4 v2 [ISO 14496-14], MP4  Base Media v1 [IS0 14496-12:2003], MP4 Base w/ AVC ext [ISO 14496-12:2005]]
[MP4] Creation Time = Sat Mar 20 22:33:46 SGT 2010
[MP4] Modification Time = Sat Mar 20 22:33:47 SGT 2010
[MP4] Duration = 139:12:500400                                     <-- Problem 1
[MP4] Media Time Scale = 90000
[MP4] Duration in Seconds = 696/125
[MP4] Transformation Matrix = 65536 0 0 0 65536 0 0 0 1073741824
[MP4] Preferred Rate = 1
[MP4] Preferred Volume = 1
[MP4] Next Track ID = 3
ERROR: End of data reached.
[MP4 Video] Vendor = Sat Mar 20 22:33:46 SGT 2010                  <-- Problem 4
[MP4 Video] Temporal Quality = Sat Mar 20 22:33:47 SGT 2010        <-- Problem 4
[MP4 Video] Width = 560 pixels
[MP4 Video] Opcolor = 0 0 0
[MP4 Video] Graphics Mode = Copy
[MP4 Video] Height = 320 pixels
[MP4 Video] Compression Type = JVT/AVC Coding                      <-- Problem 5
[MP4 Video] Depth = Unknown (24)                                   <-- Problem 2
[MP4 Video] Horizontal Resolution = 72
[MP4 Video] Vertical Resolution = 72
[MP4 Video] Frame Rate = 30
[MP4 Sound] Format = Sat Mar 20 22:33:46 SGT 2010                  <-- Problem 4
[MP4 Sound] Number of Channels = 1
[MP4 Sound] Sample Rate = 48000
[MP4 Sound] Balance = 0
[MP4 Sound] Sample Size = 16

Problem 1: Duration is in wrong format.

Problem 2: This QuickTime video should have 24-bit depth, but it shows 0. Also, Depth always shows Unknown (*).

Problem 3: [QuickTime Video] Frame Rate tag is missing. Error at the end of [QuickTime Video] section.

Problem 4: [MP4 Video] Vendor, Temporal Quality and [MP4 Sound] Format tags have wrong values.

Problem 5: 'JVT/AVC Coding' should be Compressor Name, and 'H.264' should be Compression Type.

Solutions

  1. getDurationDescription() is called on TAG_DURATION_SECONDS, not on TAG_DURATION.

  2. The Compressor Name value was read as a variable length string, so the offsets for the following values were wrong. This was fixed. Also, the description for Depth tag was improved.

  3. TimeToSampleAtom was wrongly parsed. Removed extra reads, and fix the frame rate calculation.

  4. Some tag IDs in Mp4VideoDirectory and Mp4SoundDirectory conflicted with ones in Mp4MediaDirectory. This was a problem because they are subclasses of Mp4MediaDirectory. Shifted IDs in these directories.

  5. Added Mp4SoundDirectory.TAG_AUDIO_FORMAT and Mp4VideoDirectory.TAG_COMPRESSION_TYPE parsing. Also, added empty checking of TAG_COMPRESSOR_NAME.

Here is the output of the fixed code.

[QuickTime] Major Brand = Apple QuickTime (.MOV/QT)
[QuickTime] Minor Version = 512
[QuickTime] Compatible Brands = [Apple QuickTime (.MOV/QT)]
[QuickTime] Creation Time = Fri Jan 01 00:00:00 +06:55 1904
[QuickTime] Modification Time = Fri Jan 01 00:00:00 +06:55 1904
[QuickTime] Duration = 5570
[QuickTime] Media Time Scale = 1000
[QuickTime] Duration in Seconds = 00:00:06
[QuickTime] Preferred Rate = 1
[QuickTime] Preferred Volume = 1
[QuickTime] Preview Time = 0
[QuickTime] Preview Duration = 0
[QuickTime] Poster Time = 0
[QuickTime] Selection Time = 0
[QuickTime] Selection Duration = 0
[QuickTime] Current Time = 0
[QuickTime] Next Track ID = 3
ERROR: End of data reached.
[QuickTime Video] Creation Time = Fri Jan 01 00:00:00 SGT 1904
[QuickTime Video] Modification Time = Fri Jan 01 00:00:00 SGT 1904
[QuickTime Video] Opcolor = 0 0 0
[QuickTime Video] Graphics Mode = Copy
[QuickTime Video] Vendor = FFmpeg
[QuickTime Video] Compression Type = MPEG-4
[QuickTime Video] Temporal Quality = 512
[QuickTime Video] Spatial Quality = 512
[QuickTime Video] Width = 560 pixels
[QuickTime Video] Height = 320 pixels
[QuickTime Video] Compressor Name = mpeg4
[QuickTime Video] Depth = 24-bit color
[QuickTime Video] Color Table = None
[QuickTime Video] Horizontal Resolution = 72
[QuickTime Video] Vertical Resolution = 72
[QuickTime Video] Frame Rate = 30
[QuickTime Sound] Creation Time = Fri Jan 01 00:00:00 SGT 1904
[QuickTime Sound] Modification Time = Fri Jan 01 00:00:00 SGT 1904
[QuickTime Sound] Balance = 0
[QuickTime Sound] Format = MPEG-4, Advanced Audio Coding (AAC)
[QuickTime Sound] Number of Channels = 1
[QuickTime Sound] Sample Size = 16
[QuickTime Sound] Sample Rate = 44100
[MP4] Major Brand = MP4 v2 [ISO 14496-14]
[MP4] Minor Version = 0
[MP4] Compatible Brands = [MP4 v2 [ISO 14496-14], MP4  Base Media v1 [IS0 14496-12:2003], MP4 Base w/ AVC ext [ISO 14496-12:2005]]
[MP4] Creation Time = Sat Mar 20 22:33:46 SGT 2010
[MP4] Modification Time = Sat Mar 20 22:33:47 SGT 2010
[MP4] Duration = 501120
[MP4] Media Time Scale = 90000
[MP4] Duration in Seconds = 00:00:06
[MP4] Transformation Matrix = 65536 0 0 0 65536 0 0 0 1073741824
[MP4] Preferred Rate = 1
[MP4] Preferred Volume = 1
[MP4] Next Track ID = 3
ERROR: End of data reached.
[MP4 Video] Creation Time = Sat Mar 20 22:33:46 SGT 2010
[MP4 Video] Modification Time = Sat Mar 20 22:33:47 SGT 2010
[MP4 Video] ISO 639-2 Language Code = und
[MP4 Video] Opcolor = 0 0 0
[MP4 Video] Graphics Mode = Copy
[MP4 Video] Compression Type = H.264
[MP4 Video] Width = 560 pixels
[MP4 Video] Height = 320 pixels
[MP4 Video] Compressor Name = JVT/AVC Coding
[MP4 Video] Depth = 24-bit color
[MP4 Video] Horizontal Resolution = 72
[MP4 Video] Vertical Resolution = 72
[MP4 Video] Frame Rate = 30
[MP4 Sound] Creation Time = Sat Mar 20 22:33:46 SGT 2010
[MP4 Sound] Modification Time = Sat Mar 20 22:33:47 SGT 2010
[MP4 Sound] ISO 639-2 Language Code = eng
[MP4 Sound] Balance = 0
[MP4 Sound] Format = MPEG-4, Advanced Audio Coding (AAC)
[MP4 Sound] Number of Channels = 1
[MP4 Sound] Sample Size = 16
[MP4 Sound] Sample Rate = 48000

@payton
Copy link
Collaborator

payton commented Mar 21, 2018

Thanks for the fixes, they look great!

@drewnoakes Looks good to me

@drewnoakes
Copy link
Owner

Great stuff, thanks again @nagix.

What unit is the duration in?

Feel free to merge commits @payton :)

@nagix
Copy link
Collaborator Author

nagix commented Mar 21, 2018

  • time scale: long unsigned time unit per second (default = 600)
  • duration: long unsigned time length (in time units)

As the time scale can differ from file to file, the duration in seconds is calculated by (duration / time scale).

@payton payton merged commit fc8aeb3 into drewnoakes:master Mar 21, 2018
@drewnoakes
Copy link
Owner

@nagix, ok I see. I missed the Duration in Seconds item in the output, which provides the human friendly description I was after. Thanks again.

@nagix nagix deleted the issue-330 branch March 22, 2018 03:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants