Skip to content

Commit 3c6d31b

Browse files
committed
mp4: ctts,infe,iinf,trun: More ISOMFF version handling
1 parent fb8fcff commit 3c6d31b

File tree

2 files changed

+56
-19
lines changed

2 files changed

+56
-19
lines changed

format/mp4/boxes.go

+52-16
Original file line numberDiff line numberDiff line change
@@ -853,13 +853,18 @@ func decodeBox(ctx *decodeContext, d *decode.D, typ string) {
853853
}
854854
})
855855
case "ctts":
856-
d.FieldU8("version")
856+
version := d.FieldU8("version")
857857
d.FieldU24("flags")
858858
entryCount := d.FieldU32("entry_count")
859859
var i uint64
860860
d.FieldStructArrayLoop("entries", "entry", func() bool { return i < entryCount }, func(d *decode.D) {
861861
d.FieldS32("sample_count")
862-
d.FieldS32("sample_offset")
862+
switch version {
863+
case 0:
864+
d.FieldU32("sample_offset")
865+
case 1:
866+
d.FieldS32("sample_offset")
867+
}
863868
i++
864869
})
865870
// TODO: refactor: merge with stco?
@@ -1006,7 +1011,7 @@ func decodeBox(ctx *decodeContext, d *decode.D, typ string) {
10061011
m = t.moof
10071012
}
10081013

1009-
d.FieldU8("version")
1014+
version := d.FieldU8("version")
10101015
sampleCompositionTimeOffsetsPresent := false
10111016
sampleFlagsPresent := false
10121017
sampleSizePresent := false
@@ -1054,7 +1059,11 @@ func decodeBox(ctx *decodeContext, d *decode.D, typ string) {
10541059
d.FieldStruct("sample_flags", decodeSampleFlags)
10551060
}
10561061
if sampleCompositionTimeOffsetsPresent {
1057-
d.FieldU32("sample_composition_time_offset")
1062+
if version == 0 {
1063+
d.FieldU32("sample_composition_time_offset")
1064+
} else {
1065+
d.FieldS32("sample_composition_time_offset")
1066+
}
10581067
}
10591068
})
10601069

@@ -1166,27 +1175,54 @@ func decodeBox(ctx *decodeContext, d *decode.D, typ string) {
11661175
}
11671176
})
11681177
case "infe":
1169-
d.FieldU8("version")
1178+
version := d.FieldU8("version")
11701179
d.FieldU24("flags")
1171-
d.FieldU16("id")
1172-
d.FieldU16("protection_index")
1173-
d.FieldUTF8Null("item_name")
1174-
// TODO: really optional? seems so
1175-
if d.NotEnd() {
1180+
if version == 0 || version == 1 {
1181+
d.FieldU16("item_id")
1182+
d.FieldU16("item_protection_index")
1183+
d.FieldUTF8Null("item_name")
11761184
d.FieldUTF8Null("content_type")
1185+
if !d.End() {
1186+
d.FieldUTF8Null("content_encoding")
1187+
}
11771188
}
1178-
if d.NotEnd() {
1179-
d.FieldUTF8Null("content_encoding")
1189+
if version == 1 {
1190+
if !d.End() {
1191+
d.FieldU32("extension_type")
1192+
}
1193+
if !d.End() {
1194+
d.FieldU32("extension_type_extra")
1195+
}
1196+
}
1197+
if version >= 2 {
1198+
switch version {
1199+
case 2:
1200+
d.FieldU16("item_id")
1201+
case 3:
1202+
d.FieldU32("item_id")
1203+
}
1204+
d.FieldU16("item_protection_index")
1205+
itemType := d.FieldUTF8("item_type", 4)
1206+
d.FieldUTF8Null("item_name")
1207+
switch itemType {
1208+
case "mime":
1209+
d.FieldUTF8Null("content_type")
1210+
if !d.End() {
1211+
d.FieldUTF8Null("content_encoding")
1212+
}
1213+
case "uri ":
1214+
d.FieldUTF8Null("item_uri_type")
1215+
}
11801216
}
11811217
case "iinf":
11821218
version := d.FieldU8("version")
11831219
d.FieldU24("flags")
11841220
if version == 0 {
1185-
_ = d.FieldU16("entry_count")
1186-
decodeBoxes(ctx, d)
1221+
d.FieldU16("entry_count")
11871222
} else {
1188-
d.FieldRawLen("data", d.BitsLeft())
1223+
d.FieldU32("entry_count")
11891224
}
1225+
decodeBoxes(ctx, d)
11901226
case "iprp":
11911227
decodeBoxes(ctx, d)
11921228
case "ipco":
@@ -1609,7 +1645,7 @@ func decodeBox(ctx *decodeContext, d *decode.D, typ string) {
16091645
case "pitm":
16101646
version := d.FieldU8("version")
16111647
d.FieldU24("flags")
1612-
if version < 1 {
1648+
if version == 0 {
16131649
d.FieldU16("item_id")
16141650
} else {
16151651
d.FieldU32("item_id")

format/mp4/testdata/heic.fqtest

+4-3
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,10 @@ $ fq -d mp4 dv heic.mp4
6161
0x0080| 69 6e 66 65 | infe | type: "infe" (Item information entry) 0x86-0x89.7 (4)
6262
0x0080| 02 | . | version: 2 0x8a-0x8a.7 (1)
6363
0x0080| 00 00 00 | ... | flags: 0 0x8b-0x8d.7 (3)
64-
0x0080| 00 01| ..| id: 1 0x8e-0x8f.7 (2)
65-
0x0090|00 00 |.. | protection_index: 0 0x90-0x91.7 (2)
66-
0x0090| 68 76 63 31 49 6d 61 67 65 00 | hvc1Image. | item_name: "hvc1Image" 0x92-0x9b.7 (10)
64+
0x0080| 00 01| ..| item_id: 1 0x8e-0x8f.7 (2)
65+
0x0090|00 00 |.. | item_protection_index: 0 0x90-0x91.7 (2)
66+
0x0090| 68 76 63 31 | hvc1 | item_type: "hvc1" 0x92-0x95.7 (4)
67+
0x0090| 49 6d 61 67 65 00 | Image. | item_name: "Image" 0x96-0x9b.7 (6)
6768
| | | [3]{}: box 0x9c-0x16b.7 (208)
6869
0x0090| 00 00 00 d0| ....| size: 208 0x9c-0x9f.7 (4)
6970
0x00a0|69 70 72 70 |iprp | type: "iprp" (Item Properties Box) 0xa0-0xa3.7 (4)

0 commit comments

Comments
 (0)