Skip to content

Commit

Permalink
mp4: udta: Improve length/lang box probe and support empty value
Browse files Browse the repository at this point in the history
  • Loading branch information
wader committed May 17, 2023
1 parent 4335c30 commit 1da8069
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
9 changes: 7 additions & 2 deletions format/mp4/boxes.go
Original file line number Diff line number Diff line change
Expand Up @@ -1723,9 +1723,14 @@ func decodeBox(ctx *decodeContext, d *decode.D, typ string) {
// TODO: better probe? ffmpeg uses box name heuristics?
// if 16 length field seems to match assume box with length, language and value
// otherwise decode as box with value rest of box
probeLength := d.PeekUintBits(16)

// only probe if there is something
probeLength := int64(0)
if d.BitsLeft() >= 16 {
probeLength = int64(d.PeekUintBits(16))
}
// +2 for length field, +2 for language field
if (probeLength+2+2)*8 == uint64(d.BitsLeft()) {
if (probeLength+2+2)*8 == d.BitsLeft() {
length := d.FieldU16("length")
d.FieldStrFn("language", decodeLang)
d.FieldUTF8("value", int(length))
Expand Down
Binary file added format/mp4/testdata/udta_xtra_empty
Binary file not shown.
32 changes: 32 additions & 0 deletions format/mp4/testdata/udta_xtra_empty.fqtest
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
$ fq -d mp4 -o force=true dv udta_xtra_empty
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.{}: udta_xtra_empty (mp4) 0x0-0x44.7 (69)
| | | boxes[0:1]: 0x0-0x44.7 (69)
| | | [0]{}: box 0x0-0x44.7 (69)
0x00|00 00 00 45 |...E | size: 69 0x0-0x3.7 (4)
0x00| 75 64 74 61 | udta | type: "udta" (User-data) 0x4-0x7.7 (4)
| | | boxes[0:2]: 0x8-0x44.7 (61)
| | | [0]{}: box 0x8-0x3c.7 (53)
0x00| 00 00 00 35 | ...5 | size: 53 0x8-0xb.7 (4)
0x00| 6d 65 74 61| meta| type: "meta" (Metadata container) 0xc-0xf.7 (4)
0x10|00 00 00 00 |.... | maybe_flags: 0 0x10-0x13.7 (4)
| | | boxes[0:2]: 0x14-0x3c.7 (41)
| | | [0]{}: box 0x14-0x34.7 (33)
0x10| 00 00 00 21 | ...! | size: 33 0x14-0x17.7 (4)
0x10| 68 64 6c 72 | hdlr | type: "hdlr" (Handler, declares the media (handler) type) 0x18-0x1b.7 (4)
0x10| 00 | . | version: 0 0x1c-0x1c.7 (1)
0x10| 00 00 00| ...| flags: 0 0x1d-0x1f.7 (3)
0x20|00 00 00 00 |.... | component_type: "" 0x20-0x23.7 (4)
0x20| 6d 64 69 72 | mdir | component_subtype: "mdir" (Metadata) 0x24-0x27.7 (4)
0x20| 00 00 00 00 | .... | component_manufacturer: "" 0x28-0x2b.7 (4)
0x20| 00 00 00 00| ....| component_flags: 0 0x2c-0x2f.7 (4)
0x30|00 00 00 00 |.... | component_flags_mask: 0 0x30-0x33.7 (4)
0x30| 00 | . | component_name: "" 0x34-0x34.7 (1)
| | | [1]{}: box 0x35-0x3c.7 (8)
0x30| 00 00 00 08 | .... | size: 8 0x35-0x38.7 (4)
0x30| 69 6c 73 74 | ilst | type: "ilst" 0x39-0x3c.7 (4)
| | | boxes[0:0]: 0x3d-NA (0)
| | | [1]{}: box 0x3d-0x44.7 (8)
0x30| 00 00 00| ...| size: 8 0x3d-0x40.7 (4)
0x40|08 |. |
0x40| 58 74 72 61| | Xtra| | type: "Xtra" 0x41-0x44.7 (4)
| | | value: "" 0x45-NA (0)

0 comments on commit 1da8069

Please sign in to comment.