Skip to content

Commit

Permalink
mp4: Fix field name typo for sample_composition_time_offsets_present
Browse files Browse the repository at this point in the history
  • Loading branch information
wader committed Sep 12, 2021
1 parent c7d45ff commit 0801882
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 55 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ For more usage details see [usage.md](doc/usage.md).

[./formats_list.jq]: sh-start

aac_frame, adts, adts_frame, apev2, av1_ccr, av1_frame, av1_obu, avc_annexb, avc_au, avc_dcr, avc_nalu, avc_pps, avc_sei, avc_sps, bzip2, dns, elf, exif, flac, flac_frame, flac_metadatablock, flac_picture, gif, gzip, hevc_annexb, hevc_au, hevc_dcr, hevc_nalu, icc_profile, id3v1, id3v11, id3v2, jpeg, json, matroska, mp3, mp3_frame, mp4, mpeg_asc, mpeg_es, mpeg_pes, mpeg_pes_packet, mpeg_spu, mpeg_ts, ogg, ogg_page, opus_packet, png, protobuf, protobuf_widevine, raw, tar, tiff, vorbis_comment, vorbis_packet, vp8_frame, vp9_cfm, vp9_frame, vpx_ccr, wav, webp, xing
aac_frame, adts, adts_frame, apev2, av1_ccr, av1_frame, av1_obu, avc_annexb, avc_au, avc_dcr, avc_nalu, avc_pps, avc_sei, avc_sps, bzip2, dns, elf, exif, flac, flac_frame, flac_metadatablock, flac_picture, gif, gzip, hevc_annexb, hevc_au, hevc_dcr, hevc_nalu, icc_profile, id3v1, id3v11, id3v2, jpeg, json, matroska, mp3, mp3_frame, mp4, mpeg_asc, mpeg_es, mpeg_pes, mpeg_pes_packet, mpeg_spu, mpeg_ts, ogg, ogg_page, opus_packet, png, protobuf, protobuf_widevine, pssh_playready, raw, tar, tiff, vorbis_comment, vorbis_packet, vp8_frame, vp9_cfm, vp9_frame, vpx_ccr, wav, webp, xing

[#]: sh-end

Expand Down
3 changes: 2 additions & 1 deletion doc/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ To add own functions you can use `init.fq` that will be read from
|`matroska` |Matroska&nbsp;file |<sub>`aac_frame` `av1_ccr` `av1_frame` `avc_au` `avc_dcr` `flac_frame` `flac_metadatablock` `hevc_au` `hevc_dcr` `image` `mp3_frame` `mpeg_asc` `mpeg_pes_packet` `mpeg_spu` `opus_packet` `vorbis_packet` `vp8_frame` `vp9_cfm` `vp9_frame`</sub>|
|`mp3` |MP3&nbsp;file |<sub>`id3v2` `id3v1` `id3v11` `apev2` `mp3_frame`</sub>|
|`mp3_frame` |MPEG&nbsp;audio&nbsp;layer&nbsp;3&nbsp;frame |<sub>`xing`</sub>|
|`mp4` |MPEG-4&nbsp;file&nbsp;and&nbsp;similar |<sub>`aac_frame` `av1_ccr` `av1_frame` `flac_frame` `flac_metadatablock` `id3v2` `image` `jpeg` `mp3_frame` `avc_au` `avc_dcr` `mpeg_es` `hevc_au` `hevc_dcr` `mpeg_pes_packet` `opus_packet` `protobuf_widevine` `vorbis_packet` `vp9_frame` `vpx_ccr`</sub>|
|`mp4` |MPEG-4&nbsp;file&nbsp;and&nbsp;similar |<sub>`aac_frame` `av1_ccr` `av1_frame` `flac_frame` `flac_metadatablock` `id3v2` `image` `jpeg` `mp3_frame` `avc_au` `avc_dcr` `mpeg_es` `hevc_au` `hevc_dcr` `mpeg_pes_packet` `opus_packet` `protobuf_widevine` `pssh_playready` `vorbis_packet` `vp9_frame` `vpx_ccr`</sub>|
|`mpeg_asc` |MPEG-4&nbsp;Audio&nbsp;Specific&nbsp;Config |<sub></sub>|
|`mpeg_es` |MPEG&nbsp;Elementary&nbsp;Stream |<sub>`mpeg_asc` `vorbis_packet`</sub>|
|`mpeg_pes` |MPEG&nbsp;Packetized&nbsp;elementary&nbsp;stream |<sub>`mpeg_pes_packet` `mpeg_spu`</sub>|
Expand All @@ -179,6 +179,7 @@ To add own functions you can use `init.fq` that will be read from
|`png` |Portable&nbsp;Network&nbsp;Graphics&nbsp;file |<sub>`icc_profile` `exif`</sub>|
|`protobuf` |Protobuf |<sub></sub>|
|`protobuf_widevine` |Widevine&nbsp;protobuf |<sub>`protobuf`</sub>|
|`pssh_playready` |PlayReady&nbsp;PSSH |<sub></sub>|
|`raw` |Raw&nbsp;bits |<sub></sub>|
|`tar` |Tar&nbsp;archive |<sub>`probe`</sub>|
|`tiff` |Tag&nbsp;Image&nbsp;File&nbsp;Format |<sub>`icc_profile`</sub>|
Expand Down
12 changes: 9 additions & 3 deletions format/mp4/boxes.go
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ func init() {
dataOffsetPresent := false
d.FieldStructFn("flags", func(d *decode.D) {
d.FieldU12("unused0")
sampleCompositionTimeOffsetsPresent = d.FieldBool("sample_composition_time_sffsets_present")
sampleCompositionTimeOffsetsPresent = d.FieldBool("sample_composition_time_offsets_present")
sampleFlagsPresent = d.FieldBool("sample_flags_present")
sampleSizePresent = d.FieldBool("sample_size_present")
sampleDurationPresent = d.FieldBool("sample_duration_present")
Expand Down Expand Up @@ -1004,8 +1004,14 @@ func init() {
}
},
"sinf": decodeBoxes,
"frma": func(_ *decodeContext, d *decode.D) {
d.FieldUTF8("format", 4)
"frma": func(ctx *decodeContext, d *decode.D) {
format := d.FieldUTF8("format", 4)

// set to original data format
// TODO: how to handle multiple descriptors? track current?
if ctx.currentTrack != nil && len(ctx.currentTrack.sampleDescriptions) > 0 {
ctx.currentTrack.sampleDescriptions[0].originalFormat = format
}
},
"schm": func(_ *decodeContext, d *decode.D) {
d.FieldU8("version")
Expand Down
31 changes: 17 additions & 14 deletions format/mp4/mp4.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ type moof struct {
}

type sampleDescription struct {
dataFormat string
dataFormat string
originalFormat string
}

type track struct {
Expand Down Expand Up @@ -203,8 +204,14 @@ func mp4Decode(d *decode.D, in interface{}) interface{} {

d.FieldStructFn("track", func(d *decode.D) {
// TODO: handle progressive/fragmented mp4 differently somehow?
if t.moofs == nil && len(t.sampleDescriptions) > 0 {
d.FieldStrFn("data_format", func() (string, string) { return t.sampleDescriptions[0].dataFormat, "" })

trackSdDataFormat := "unknown"
if len(t.sampleDescriptions) > 0 {
sd := t.sampleDescriptions[0]
trackSdDataFormat = sd.dataFormat
if sd.originalFormat != "" {
trackSdDataFormat = sd.originalFormat
}
}

d.FieldArrayFn("samples", func(d *decode.D) {
Expand All @@ -231,12 +238,7 @@ func mp4Decode(d *decode.D, in interface{}) interface{} {
}

sampleSize := t.stsz[sampleNr]
dataFormat := "unknown"
if len(t.sampleDescriptions) > 0 {
dataFormat = t.sampleDescriptions[0].dataFormat
}

decodeSampleRange(d, t, dataFormat, "sample", int64(sampleOffset)*8, int64(sampleSize)*8, t.decodeOpts...)
decodeSampleRange(d, t, trackSdDataFormat, "sample", int64(sampleOffset)*8, int64(sampleSize)*8, t.decodeOpts...)

// log.Printf("%s %d/%d %d/%d sample=%d/%d chunk=%d size=%d %d-%d\n", t.dataFormat, stscIndex, len(t.stsc), i, stscEntry.samplesPerChunk, sampleNr, len(t.stsz), chunkNr, sampleSize, sampleOffset, sampleOffset+uint64(sampleSize))

Expand All @@ -256,12 +258,13 @@ func mp4Decode(d *decode.D, in interface{}) interface{} {
for _, sz := range m.samplesSizes {
// log.Printf("moof sample %s %d-%d\n", t.dataFormat, sampleOffset, int64(sz))

dataFormat := "unknown"
if len(t.sampleDescriptions) > 0 {
dataFormat = t.sampleDescriptions[0].dataFormat
}
dataFormat := trackSdDataFormat
if m.defaultSampleDescriptionIndex != 0 && int(m.defaultSampleDescriptionIndex-1) < len(t.sampleDescriptions) {
dataFormat = t.sampleDescriptions[m.defaultSampleDescriptionIndex-1].dataFormat
sd := t.sampleDescriptions[m.defaultSampleDescriptionIndex-1]
dataFormat = sd.dataFormat
if sd.originalFormat != "" {
dataFormat = sd.originalFormat
}
}

// log.Printf("moof %#+v dataFormat: %#+v\n", m, dataFormat)
Expand Down
5 changes: 2 additions & 3 deletions format/mp4/testdata/aac.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@ $ fq -d mp4 verbose /aac.mp4
0x580| 00 00 01 | ... | flags: 1 0x589-0x58b.7 (3)
0x580| 00 00 00 00| ....| reserved: 0 0x58c-0x58f.7 (4)
0x590|4c 61 76 66 35 38 2e 34 35 2e 31 30 30| |Lavf58.45.100| | data: "Lavf58.45.100" 0x590-0x59c.7 (13)
| | | tracks: [1] 0x2c-0x59c.7 (1393)
| | | [0]: track {} 0x2c-0x59c.7 (1393)
| | | tracks: [1] 0x2c-0x291.7 (614)
| | | [0]: track {} 0x2c-0x291.7 (614)
| | | samples: [4] 0x2c-0x291.7 (614)
| | | [0]: sample {} (aac_frame) 0x2c-0xf8.7 (205)
| | | elements: [3] 0x2c-0x40.7 (21)
Expand Down Expand Up @@ -430,4 +430,3 @@ $ fq -d mp4 verbose /aac.mp4
0x290|b4 |. |
0x290|b4 |. | [1]: byte_align 00 0x290.6-0x290.7 (0.2)
0x290| 70 | p | data: 70 0x291-0x291.7 (1)
| | | data_format: "mp4a" 0x59d-NA (0)
5 changes: 2 additions & 3 deletions format/mp4/testdata/av1.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ $ fq -d mp4 verbose /av1.mp4
0x14a0| 00 00 00 00 | .... | reserved: 0 0x14a1-0x14a4.7 (4)
0x14a0| 4c 61 76 66 35 38 2e 34 35 2e 31| Lavf58.45.1| data: "Lavf58.45.100" 0x14a5-0x14b1.7 (13)
0x14b0|30 30| |00| |
| | | tracks: [1] 0x2c-0x14b1.7 (5254)
| | | [0]: track {} 0x2c-0x14b1.7 (5254)
| | | tracks: [1] 0x2c-0x11bf.7 (4500)
| | | [0]: track {} 0x2c-0x11bf.7 (4500)
| | | samples: [1] 0x2c-0x11bf.7 (4500)
| | | [0]: sample {} (av1_frame) 0x2c-0x11bf.7 (4500)
| | | frame: [3] 0x2c-0x11bf.7 (4500)
Expand Down Expand Up @@ -336,4 +336,3 @@ $ fq -d mp4 verbose /av1.mp4
0x0040| f0 22| ."| size: 4464 0x4e-0x4f.7 (2)
0x0050|f6 0a 4f ae f3 fe ec e7 30 4f 3f 13 9c 75 c9 6a|..O.....0O?..u.j| data: f60a4faef3feece7304f3f139c75c96a... 0x50-0x11bf.7 (4464)
* |until 0x11bf.7 (4464) | |
| | | data_format: "av01" 0x14b2-NA (0)
5 changes: 2 additions & 3 deletions format/mp4/testdata/avc.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,8 @@ $ fq -d mp4 verbose /avc.mp4
0x0de0| 00 00 00 00 | .... | reserved: 0 0xde2-0xde5.7 (4)
0x0de0| 4c 61 76 66 35 38 2e 34 35 2e| Lavf58.45.| data: "Lavf58.45.100" 0xde6-0xdf2.7 (13)
0x0df0|31 30 30| |100| |
| | | tracks: [1] 0x30-0xdf2.7 (3523)
| | | [0]: track {} 0x30-0xdf2.7 (3523)
| | | tracks: [1] 0x30-0xaef.7 (2752)
| | | [0]: track {} 0x30-0xaef.7 (2752)
| | | samples: [1] 0x30-0xaef.7 (2752)
| | | [0]: sample {} (avc_au) 0x30-0xaef.7 (2752)
| | | access_unit: [2] 0x30-0xaef.7 (2752)
Expand Down Expand Up @@ -425,4 +425,3 @@ $ fq -d mp4 verbose /avc.mp4
0x02e0| 84 00 2b ff fe f5 db f3 2c| ..+.....,| data: 080057fffdebb7e65958ccce7bffda76... 0x2e7.1-0xaef.7 (2056.7)
0x02f0|ac 66 67 3d ff ed 3b 60 00 21 74 ff c0 cf 1f fc|.fg=..;`.!t.....|
* |until 0xaef.7 (2057) | |
| | | data_format: "avc1" 0xdf3-NA (0)
5 changes: 2 additions & 3 deletions format/mp4/testdata/flac.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ $ fq -d mp4 verbose /flac.mp4
0x530| 00 00 00 00 | .... | reserved: 0 0x532-0x535.7 (4)
0x530| 4c 61 76 66 35 38 2e 34 35 2e| Lavf58.45.| data: "Lavf58.45.100" 0x536-0x542.7 (13)
0x540|31 30 30| |100| |
| | | tracks: [1] 0x2c-0x542.7 (1303)
| | | [0]: track {} 0x2c-0x542.7 (1303)
| | | tracks: [1] 0x2c-0x289.7 (606)
| | | [0]: track {} 0x2c-0x289.7 (606)
| | | samples: [1] 0x2c-0x289.7 (606)
| | | [0]: sample {} (flac_frame) 0x2c-0x289.7 (606)
| | | header: {} 0x2c-0x33.7 (8)
Expand Down Expand Up @@ -370,4 +370,3 @@ $ fq -d mp4 verbose /flac.mp4
0x280| 00 00 00 | ... | value: 0 0x285.1-0x287.1 (2.1)
0x280| 00 | . | byte_align: Correct (0x0) 0x287.2-0x287.7 (0.6)
0x280| 82 cb | .. | footer_crc: Correct (82cb) 0x288-0x289.7 (2)
| | | data_format: "fLaC" 0x543-NA (0)

0 comments on commit 0801882

Please sign in to comment.