Skip to content

Commit bedd719

Browse files
committed
mp4: Decode emsg box
1 parent 7b3eb58 commit bedd719

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

format/mp4/boxes.go

+29
Original file line numberDiff line numberDiff line change
@@ -1741,6 +1741,35 @@ func decodeBox(ctx *decodeContext, d *decode.D, typ string) {
17411741
default:
17421742
d.FieldRawLen("data", d.BitsLeft())
17431743
}
1744+
case "emsg":
1745+
// https://aomediacodec.github.io/id3-emsg/
1746+
version := d.FieldU8("version")
1747+
d.FieldU24("flags")
1748+
var schemeIdUri string
1749+
switch version {
1750+
case 0:
1751+
schemeIdUri = d.FieldUTF8Null("scheme_id_uri")
1752+
d.FieldUTF8Null("value")
1753+
d.FieldU32("timescale")
1754+
d.FieldU32("presentation_time_delta")
1755+
d.FieldU32("event_duration")
1756+
d.FieldU32("id")
1757+
case 1:
1758+
d.FieldU32("timescale")
1759+
d.FieldU64("presentation_time")
1760+
d.FieldU32("event_duration")
1761+
d.FieldU32("id")
1762+
schemeIdUri = d.FieldUTF8Null("scheme_id_uri")
1763+
d.FieldUTF8Null("value")
1764+
default:
1765+
d.FieldRawLen("data", d.BitsLeft())
1766+
}
1767+
switch schemeIdUri {
1768+
case "https://aomedia.org/emsg/ID3":
1769+
d.FieldFormat("message_data", &id3v2Group, nil)
1770+
default:
1771+
d.FieldRawLen("message_data", d.BitsLeft())
1772+
}
17441773
default:
17451774
// there are at least 4 ways to encode udta metadata in mov/mp4 files.
17461775
//

format/mp4/testdata/emsg.fqtest

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
$ fq -o force=true -d mp4 dv emsg.mp4
2+
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.{}: emsg.mp4 (mp4) 0x0-0x1a0.7 (417)
3+
| | | boxes[0:1]: 0x0-0x1a0.7 (417)
4+
| | | [0]{}: box 0x0-0x1a0.7 (417)
5+
0x000|00 00 01 a1 |.... | size: 417 0x0-0x3.7 (4)
6+
0x000| 65 6d 73 67 | emsg | type: "emsg" (Event message) 0x4-0x7.7 (4)
7+
0x000| 00 | . | version: 0 0x8-0x8.7 (1)
8+
0x000| 00 00 00 | ... | flags: 0 0x9-0xb.7 (3)
9+
0x000| 68 74 74 70| http| scheme_id_uri: "http://youtube.com/streaming/metadata/segment/1..." 0xc-0x40.7 (53)
10+
0x010|3a 2f 2f 79 6f 75 74 75 62 65 2e 63 6f 6d 2f 73|://youtube.com/s|
11+
* |until 0x40.7 (53) | |
12+
0x040| 00 | . | value: "" 0x41-0x41.7 (1)
13+
0x040| 00 00 00 01 | .... | timescale: 1 0x42-0x45.7 (4)
14+
0x040| 00 00 00 00 | .... | presentation_time_delta: 0 0x46-0x49.7 (4)
15+
0x040| 00 00 00 00 | .... | event_duration: 0 0x4a-0x4d.7 (4)
16+
0x040| 30 d7| 0.| id: 819396933 0x4e-0x51.7 (4)
17+
0x050|01 45 |.E |
18+
0x050| 53 65 71 75 65 6e 63 65 2d 4e 75 6d 62 65| Sequence-Numbe| message_data: raw bits 0x52-0x1a0.7 (335)
19+
0x060|72 3a 20 30 0d 0a 49 6e 67 65 73 74 69 6f 6e 2d|r: 0..Ingestion-|
20+
* |until 0x1a0.7 (end) (335) | |

format/mp4/testdata/emsg.mp4

417 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)