Skip to content

Commit

Permalink
mp4: ctts,infe,iinf,trun: More ISOMFF version handling
Browse files Browse the repository at this point in the history
  • Loading branch information
wader committed Apr 17, 2023
1 parent fb8fcff commit 3c6d31b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 19 deletions.
68 changes: 52 additions & 16 deletions format/mp4/boxes.go
Original file line number Diff line number Diff line change
Expand Up @@ -853,13 +853,18 @@ func decodeBox(ctx *decodeContext, d *decode.D, typ string) {
}
})
case "ctts":
d.FieldU8("version")
version := d.FieldU8("version")
d.FieldU24("flags")
entryCount := d.FieldU32("entry_count")
var i uint64
d.FieldStructArrayLoop("entries", "entry", func() bool { return i < entryCount }, func(d *decode.D) {
d.FieldS32("sample_count")
d.FieldS32("sample_offset")
switch version {
case 0:
d.FieldU32("sample_offset")
case 1:
d.FieldS32("sample_offset")
}
i++
})
// TODO: refactor: merge with stco?
Expand Down Expand Up @@ -1006,7 +1011,7 @@ func decodeBox(ctx *decodeContext, d *decode.D, typ string) {
m = t.moof
}

d.FieldU8("version")
version := d.FieldU8("version")
sampleCompositionTimeOffsetsPresent := false
sampleFlagsPresent := false
sampleSizePresent := false
Expand Down Expand Up @@ -1054,7 +1059,11 @@ func decodeBox(ctx *decodeContext, d *decode.D, typ string) {
d.FieldStruct("sample_flags", decodeSampleFlags)
}
if sampleCompositionTimeOffsetsPresent {
d.FieldU32("sample_composition_time_offset")
if version == 0 {
d.FieldU32("sample_composition_time_offset")
} else {
d.FieldS32("sample_composition_time_offset")
}
}
})

Expand Down Expand Up @@ -1166,27 +1175,54 @@ func decodeBox(ctx *decodeContext, d *decode.D, typ string) {
}
})
case "infe":
d.FieldU8("version")
version := d.FieldU8("version")
d.FieldU24("flags")
d.FieldU16("id")
d.FieldU16("protection_index")
d.FieldUTF8Null("item_name")
// TODO: really optional? seems so
if d.NotEnd() {
if version == 0 || version == 1 {
d.FieldU16("item_id")
d.FieldU16("item_protection_index")
d.FieldUTF8Null("item_name")
d.FieldUTF8Null("content_type")
if !d.End() {
d.FieldUTF8Null("content_encoding")
}
}
if d.NotEnd() {
d.FieldUTF8Null("content_encoding")
if version == 1 {
if !d.End() {
d.FieldU32("extension_type")
}
if !d.End() {
d.FieldU32("extension_type_extra")
}
}
if version >= 2 {
switch version {
case 2:
d.FieldU16("item_id")
case 3:
d.FieldU32("item_id")
}
d.FieldU16("item_protection_index")
itemType := d.FieldUTF8("item_type", 4)
d.FieldUTF8Null("item_name")
switch itemType {
case "mime":
d.FieldUTF8Null("content_type")
if !d.End() {
d.FieldUTF8Null("content_encoding")
}
case "uri ":
d.FieldUTF8Null("item_uri_type")
}
}
case "iinf":
version := d.FieldU8("version")
d.FieldU24("flags")
if version == 0 {
_ = d.FieldU16("entry_count")
decodeBoxes(ctx, d)
d.FieldU16("entry_count")
} else {
d.FieldRawLen("data", d.BitsLeft())
d.FieldU32("entry_count")
}
decodeBoxes(ctx, d)
case "iprp":
decodeBoxes(ctx, d)
case "ipco":
Expand Down Expand Up @@ -1609,7 +1645,7 @@ func decodeBox(ctx *decodeContext, d *decode.D, typ string) {
case "pitm":
version := d.FieldU8("version")
d.FieldU24("flags")
if version < 1 {
if version == 0 {
d.FieldU16("item_id")
} else {
d.FieldU32("item_id")
Expand Down
7 changes: 4 additions & 3 deletions format/mp4/testdata/heic.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ $ fq -d mp4 dv heic.mp4
0x0080| 69 6e 66 65 | infe | type: "infe" (Item information entry) 0x86-0x89.7 (4)
0x0080| 02 | . | version: 2 0x8a-0x8a.7 (1)
0x0080| 00 00 00 | ... | flags: 0 0x8b-0x8d.7 (3)
0x0080| 00 01| ..| id: 1 0x8e-0x8f.7 (2)
0x0090|00 00 |.. | protection_index: 0 0x90-0x91.7 (2)
0x0090| 68 76 63 31 49 6d 61 67 65 00 | hvc1Image. | item_name: "hvc1Image" 0x92-0x9b.7 (10)
0x0080| 00 01| ..| item_id: 1 0x8e-0x8f.7 (2)
0x0090|00 00 |.. | item_protection_index: 0 0x90-0x91.7 (2)
0x0090| 68 76 63 31 | hvc1 | item_type: "hvc1" 0x92-0x95.7 (4)
0x0090| 49 6d 61 67 65 00 | Image. | item_name: "Image" 0x96-0x9b.7 (6)
| | | [3]{}: box 0x9c-0x16b.7 (208)
0x0090| 00 00 00 d0| ....| size: 208 0x9c-0x9f.7 (4)
0x00a0|69 70 72 70 |iprp | type: "iprp" (Item Properties Box) 0xa0-0xa3.7 (4)
Expand Down

0 comments on commit 3c6d31b

Please sign in to comment.