Skip to content

Commit

Permalink
mp4: Decode emsg box
Browse files Browse the repository at this point in the history
  • Loading branch information
wader committed Aug 31, 2023
1 parent 7b3eb58 commit bedd719
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
29 changes: 29 additions & 0 deletions format/mp4/boxes.go
Original file line number Diff line number Diff line change
Expand Up @@ -1741,6 +1741,35 @@ func decodeBox(ctx *decodeContext, d *decode.D, typ string) {
default:
d.FieldRawLen("data", d.BitsLeft())
}
case "emsg":
// https://aomediacodec.github.io/id3-emsg/
version := d.FieldU8("version")
d.FieldU24("flags")
var schemeIdUri string
switch version {
case 0:
schemeIdUri = d.FieldUTF8Null("scheme_id_uri")
d.FieldUTF8Null("value")
d.FieldU32("timescale")
d.FieldU32("presentation_time_delta")
d.FieldU32("event_duration")
d.FieldU32("id")
case 1:
d.FieldU32("timescale")
d.FieldU64("presentation_time")
d.FieldU32("event_duration")
d.FieldU32("id")
schemeIdUri = d.FieldUTF8Null("scheme_id_uri")
d.FieldUTF8Null("value")
default:
d.FieldRawLen("data", d.BitsLeft())
}
switch schemeIdUri {
case "https://aomedia.org/emsg/ID3":
d.FieldFormat("message_data", &id3v2Group, nil)
default:
d.FieldRawLen("message_data", d.BitsLeft())
}
default:
// there are at least 4 ways to encode udta metadata in mov/mp4 files.
//
Expand Down
20 changes: 20 additions & 0 deletions format/mp4/testdata/emsg.fqtest
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
$ fq -o force=true -d mp4 dv emsg.mp4
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.{}: emsg.mp4 (mp4) 0x0-0x1a0.7 (417)
| | | boxes[0:1]: 0x0-0x1a0.7 (417)
| | | [0]{}: box 0x0-0x1a0.7 (417)
0x000|00 00 01 a1 |.... | size: 417 0x0-0x3.7 (4)
0x000| 65 6d 73 67 | emsg | type: "emsg" (Event message) 0x4-0x7.7 (4)
0x000| 00 | . | version: 0 0x8-0x8.7 (1)
0x000| 00 00 00 | ... | flags: 0 0x9-0xb.7 (3)
0x000| 68 74 74 70| http| scheme_id_uri: "http://youtube.com/streaming/metadata/segment/1..." 0xc-0x40.7 (53)
0x010|3a 2f 2f 79 6f 75 74 75 62 65 2e 63 6f 6d 2f 73|://youtube.com/s|
* |until 0x40.7 (53) | |
0x040| 00 | . | value: "" 0x41-0x41.7 (1)
0x040| 00 00 00 01 | .... | timescale: 1 0x42-0x45.7 (4)
0x040| 00 00 00 00 | .... | presentation_time_delta: 0 0x46-0x49.7 (4)
0x040| 00 00 00 00 | .... | event_duration: 0 0x4a-0x4d.7 (4)
0x040| 30 d7| 0.| id: 819396933 0x4e-0x51.7 (4)
0x050|01 45 |.E |
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)
0x060|72 3a 20 30 0d 0a 49 6e 67 65 73 74 69 6f 6e 2d|r: 0..Ingestion-|
* |until 0x1a0.7 (end) (335) | |
Binary file added format/mp4/testdata/emsg.mp4
Binary file not shown.

0 comments on commit bedd719

Please sign in to comment.