Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions format/mp4/boxes.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,14 @@ func decodeSampleFlags(d *decode.D) {
}

func decodeBoxWithParentData(ctx *decodeContext, d *decode.D, parentData any, extraTypeMappers ...scalar.StrMapper) {
var typ string
var dataSize uint64
typeMappers := []scalar.StrMapper{boxDescriptions}
if len(extraTypeMappers) > 0 {
typeMappers = append(typeMappers, extraTypeMappers...)
}

boxSize := d.FieldU32("size", boxSizeNames)
typ = d.FieldStr("type", 4, charmap.ISO8859_1, typeMappers...)
typ := d.FieldStr("type", 4, charmap.ISO8859_1, typeMappers...)

switch boxSize {
case boxSizeRestOfFile:
Expand Down Expand Up @@ -555,15 +554,27 @@ func decodeBox(ctx *decodeContext, d *decode.D, typ string) {
d.FieldU24("flags")
entryCount := d.FieldU32("entry_count")
var i uint64
var drefURL string
d.FieldStructArrayLoop("boxes", "box", func() bool { return i < entryCount }, func(d *decode.D) {
size := d.FieldU32("size")
d.FieldUTF8("type", 4)
typ := d.FieldUTF8("type", 4)
d.FieldU8("version")
d.FieldU24("flags")
dataSize := size - 12
d.FieldRawLen("data", int64(dataSize*8))
switch typ {
case "url ":
drefURL = d.FieldUTF8("data", int(dataSize))
default:
d.FieldRawLen("data", int64(dataSize*8))
}
i++
})

if t := ctx.currentTrack(); t != nil {
t.dref = true
t.drefURL = drefURL
}

case "stbl":
decodeBoxes(ctx, d)
case "stsd":
Expand Down Expand Up @@ -1770,6 +1781,7 @@ func decodeBox(ctx *decodeContext, d *decode.D, typ string) {
default:
d.FieldRawLen("message_data", d.BitsLeft())
}

default:
// there are at least 4 ways to encode udta metadata in mov/mp4 files.
//
Expand Down
8 changes: 7 additions & 1 deletion format/mp4/mp4.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ type track struct {
objectType int // if data format is "mp4a"
defaultIVSize int
moofs []*moof // for fmp4
dref bool
drefURL string
}

type pathEntry struct {
Expand Down Expand Up @@ -287,9 +289,13 @@ func mp4Tracks(d *decode.D, ctx *decodeContext) {
trackSDDataFormat = sd.originalFormat
}
}

d.FieldValueStr("data_format", trackSDDataFormat, dataFormatNames)

if t.dref && t.drefURL != "" {
d.FieldValueStr("data_reference_url", t.drefURL)
return
}

switch trackSDDataFormat {
case "lpcm",
"raw ",
Expand Down
2 changes: 1 addition & 1 deletion format/mp4/testdata/aac.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ $ fq -d mp4 dv aac.mp4
0x410| 75 72 6c 20 | url | type: "url " 0x417-0x41b (4)
0x410| 00 | . | version: 0 0x41b-0x41c (1)
0x410| 00 00 01 | ... | flags: 1 0x41c-0x41f (3)
| | | data: raw bits 0x41f-0x41f (0)
| | | data: "" 0x41f-0x41f (0)
| | | [2]{}: box 0x41f-0x53b (284)
0x410| 00| .| size: 284 0x41f-0x423 (4)
0x420|00 01 1c |... |
Expand Down
2 changes: 1 addition & 1 deletion format/mp4/testdata/av1.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ $ fq -d mp4 dv av1.mp4
0x1340| 00 | . | version: 0 0x134d-0x134e (1)
0x1340| 00 00| ..| flags: 1 0x134e-0x1351 (3)
0x1350|01 |. |
| | | data: raw bits 0x1351-0x1351 (0)
| | | data: "" 0x1351-0x1351 (0)
| | | [2]{}: box 0x1351-0x1450 (255)
0x1350| 00 00 00 ff | .... | size: 255 0x1351-0x1355 (4)
0x1350| 73 74 62 6c | stbl | type: "stbl" (Sample table box, container for the time/space map) 0x1355-0x1359 (4)
Expand Down
2 changes: 1 addition & 1 deletion format/mp4/testdata/avc.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ $ fq -d mp4 dv avc.mp4
0x00f00| 00 | . | version: 0 0xf0e-0xf0f (1)
0x00f00| 00| .| flags: 1 0xf0f-0xf12 (3)
0x00f10|00 01 |.. |
| | | data: raw bits 0xf12-0xf12 (0)
| | | data: "" 0xf12-0xf12 (0)
| | | [2]{}: box 0xf12-0x107e (364)
0x00f10| 00 00 01 6c | ...l | size: 364 0xf12-0xf16 (4)
0x00f10| 73 74 62 6c | stbl | type: "stbl" (Sample table box, container for the time/space map) 0xf16-0xf1a (4)
Expand Down
2 changes: 1 addition & 1 deletion format/mp4/testdata/dash.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ $ fq -d mp4 dv dash_audio_init.mp4
0x200|6c 20 |l |
0x200| 00 | . | version: 0 0x202-0x203 (1)
0x200| 00 00 01 | ... | flags: 1 0x203-0x206 (3)
| | | data: raw bits 0x206-0x206 (0)
| | | data: "" 0x206-0x206 (0)
| | | [1]{}: box 0x206-0x31a (276)
0x200| 00 00 01 14 | .... | size: 276 0x206-0x20a (4)
0x200| 73 74 62 6c | stbl | type: "stbl" (Sample table box, container for the time/space map) 0x20a-0x20e (4)
Expand Down
2 changes: 1 addition & 1 deletion format/mp4/testdata/flac.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ $ fq -d mp4 dv flac.mp4
0x410|72 6c 20 |rl |
0x410| 00 | . | version: 0 0x413-0x414 (1)
0x410| 00 00 01 | ... | flags: 1 0x414-0x417 (3)
| | | data: raw bits 0x417-0x417 (0)
| | | data: "" 0x417-0x417 (0)
| | | [2]{}: box 0x417-0x4e1 (202)
0x410| 00 00 00 ca | .... | size: 202 0x417-0x41b (4)
0x410| 73 74 62 6c | stbl | type: "stbl" (Sample table box, container for the time/space map) 0x41b-0x41f (4)
Expand Down
4 changes: 2 additions & 2 deletions format/mp4/testdata/fragmented.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ $ fq -d mp4 dv fragmented.mp4
0x00180| 00 | . | version: 0 0x18d-0x18e (1)
0x00180| 00 00| ..| flags: 1 0x18e-0x191 (3)
0x00190|01 |. |
| | | data: raw bits 0x191-0x191 (0)
| | | data: "" 0x191-0x191 (0)
| | | [2]{}: box 0x191-0x284 (243)
0x00190| 00 00 00 f3 | .... | size: 243 0x191-0x195 (4)
0x00190| 73 74 62 6c | stbl | type: "stbl" (Sample table box, container for the time/space map) 0x195-0x199 (4)
Expand Down Expand Up @@ -405,7 +405,7 @@ $ fq -d mp4 dv fragmented.mp4
0x00370| 75 72 6c 20 | url | type: "url " 0x371-0x375 (4)
0x00370| 00 | . | version: 0 0x375-0x376 (1)
0x00370| 00 00 01 | ... | flags: 1 0x376-0x379 (3)
| | | data: raw bits 0x379-0x379 (0)
| | | data: "" 0x379-0x379 (0)
| | | [2]{}: box 0x379-0x443 (202)
0x00370| 00 00 00 ca | .... | size: 202 0x379-0x37d (4)
0x00370| 73 74 62| stb| type: "stbl" (Sample table box, container for the time/space map) 0x37d-0x381 (4)
Expand Down
2 changes: 1 addition & 1 deletion format/mp4/testdata/hevc.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ $ fq -d mp4 dv hevc.mp4
0x0a00| 00 | . | version: 0 0xa0e-0xa0f (1)
0x0a00| 00| .| flags: 1 0xa0f-0xa12 (3)
0x0a10|00 01 |.. |
| | | data: raw bits 0xa12-0xa12 (0)
| | | data: "" 0xa12-0xa12 (0)
| | | [2]{}: box 0xa12-0x1439 (2599)
0x0a10| 00 00 0a 27 | ...' | size: 2599 0xa12-0xa16 (4)
0x0a10| 73 74 62 6c | stbl | type: "stbl" (Sample table box, container for the time/space map) 0xa16-0xa1a (4)
Expand Down
2 changes: 1 addition & 1 deletion format/mp4/testdata/in24.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ $ fq dv in24.mp4
0x2e0|20 | |
0x2e0| 00 | . | version: 0 0x2e1-0x2e2 (1)
0x2e0| 00 00 01 | ... | flags: 1 0x2e2-0x2e5 (3)
| | | data: raw bits 0x2e5-0x2e5 (0)
| | | data: "" 0x2e5-0x2e5 (0)
| | | [3]{}: box 0x2e5-0x3cb (230)
0x2e0| 00 00 00 e6 | .... | size: 230 0x2e5-0x2e9 (4)
0x2e0| 73 74 62 6c | stbl | type: "stbl" (Sample table box, container for the time/space map) 0x2e9-0x2ed (4)
Expand Down
2 changes: 1 addition & 1 deletion format/mp4/testdata/lpcm.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ $ fq dv lpcm.mp4
0x410| 75 72 6c 20 | url | type: "url " 0x415-0x419 (4)
0x410| 00 | . | version: 0 0x419-0x41a (1)
0x410| 00 00 01 | ... | flags: 1 0x41a-0x41d (3)
| | | data: raw bits 0x41d-0x41d (0)
| | | data: "" 0x41d-0x41d (0)
| | | [3]{}: box 0x41d-0x4f1 (212)
0x410| 00 00 00| ...| size: 212 0x41d-0x421 (4)
0x420|d4 |. |
Expand Down
2 changes: 1 addition & 1 deletion format/mp4/testdata/mp3.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ $ fq -d mp4 dv mp3.mp4
0x420| 75 72 6c 20 | url | type: "url " 0x423-0x427 (4)
0x420| 00 | . | version: 0 0x427-0x428 (1)
0x420| 00 00 01 | ... | flags: 1 0x428-0x42b (3)
| | | data: raw bits 0x42b-0x42b (0)
| | | data: "" 0x42b-0x42b (0)
| | | [2]{}: box 0x42b-0x503 (216)
0x420| 00 00 00 d8 | .... | size: 216 0x42b-0x42f (4)
0x420| 73| s| type: "stbl" (Sample table box, container for the time/space map) 0x42f-0x433 (4)
Expand Down
2 changes: 1 addition & 1 deletion format/mp4/testdata/mpeg2.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ $ fq -d mp4 dv mpeg2.mp4
0x2130|72 6c 20 |rl |
0x2130| 00 | . | version: 0 0x2133-0x2134 (1)
0x2130| 00 00 01 | ... | flags: 1 0x2134-0x2137 (3)
| | | data: raw bits 0x2137-0x2137 (0)
| | | data: "" 0x2137-0x2137 (0)
| | | [2]{}: box 0x2137-0x2247 (272)
0x2130| 00 00 01 10 | .... | size: 272 0x2137-0x213b (4)
0x2130| 73 74 62 6c | stbl | type: "stbl" (Sample table box, container for the time/space map) 0x213b-0x213f (4)
Expand Down
2 changes: 1 addition & 1 deletion format/mp4/testdata/opus.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ $ fq -d mp4 dv opus.mp4
0x310| 75 72 6c 20| url | type: "url " 0x31c-0x320 (4)
0x320|00 |. | version: 0 0x320-0x321 (1)
0x320| 00 00 01 | ... | flags: 1 0x321-0x324 (3)
| | | data: raw bits 0x324-0x324 (0)
| | | data: "" 0x324-0x324 (0)
| | | [2]{}: box 0x324-0x3d7 (179)
0x320| 00 00 00 b3 | .... | size: 179 0x324-0x328 (4)
0x320| 73 74 62 6c | stbl | type: "stbl" (Sample table box, container for the time/space map) 0x328-0x32c (4)
Expand Down
2 changes: 1 addition & 1 deletion format/mp4/testdata/png.mp4.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ $ fq dv png.mp4
0x210| 75 72 6c 20 | url | type: "url " 0x212-0x216 (4)
0x210| 00 | . | version: 0 0x216-0x217 (1)
0x210| 00 00 01 | ... | flags: 1 0x217-0x21a (3)
| | | data: raw bits 0x21a-0x21a (0)
| | | data: "" 0x21a-0x21a (0)
| | | [2]{}: box 0x21a-0x33e (292)
0x210| 00 00 01 24 | ...$ | size: 292 0x21a-0x21e (4)
0x210| 73 74| st| type: "stbl" (Sample table box, container for the time/space map) 0x21e-0x222 (4)
Expand Down
2 changes: 1 addition & 1 deletion format/mp4/testdata/png_no_hdlr.mp4.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ $ fq dv png_no_hdlr.mp4
0x180|75 72 6c 20 |url | type: "url " 0x180-0x184 (4)
0x180| 00 | . | version: 0 0x184-0x185 (1)
0x180| 00 00 01 | ... | flags: 1 0x185-0x188 (3)
| | | data: raw bits 0x188-0x188 (0)
| | | data: "" 0x188-0x188 (0)
| | | [2]{}: box 0x188-0x2ac (292)
0x180| 00 00 01 24 | ...$ | size: 292 0x188-0x18c (4)
0x180| 73 74 62 6c| stbl| type: "stbl" (Sample table box, container for the time/space map) 0x18c-0x190 (4)
Expand Down
2 changes: 1 addition & 1 deletion format/mp4/testdata/stz2.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ $ fq -d mp4 'dv' stz2.mp4
0x1b0|6c 20 |l |
0x1b0| 00 | . | version: 0 0x1b2-0x1b3 (1)
0x1b0| 00 00 01 | ... | flags: 1 0x1b3-0x1b6 (3)
| | | data: raw bits 0x1b6-0x1b6 (0)
| | | data: "" 0x1b6-0x1b6 (0)
| | | [2]{}: box 0x1b6-0x27c (198)
0x1b0| 00 00 00 c6 | .... | size: 198 0x1b6-0x1ba (4)
0x1b0| 73 74 62 6c | stbl | type: "stbl" (Sample table box, container for the time/space map) 0x1ba-0x1be (4)
Expand Down
Loading