Skip to content

Commit

Permalink
dolby_metadata: Add as own format and more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
wader committed Aug 21, 2024
1 parent f2a6987 commit 04539fe
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 109 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ It was originally designed to query, inspect and debug media codecs and containe
[aac_frame](doc/formats.md#aac_frame),
adts,
adts_frame,
[adm](doc/formats.md#adm),
aiff,
amf0,
apev2,
Expand All @@ -54,7 +53,6 @@ avc_sei,
avc_sps,
[avi](doc/formats.md#avi),
[avro_ocf](doc/formats.md#avro_ocf),
[axml](doc/formats.md#adm),
[bencode](doc/formats.md#bencode),
bitcoin_blkdat,
[bitcoin_block](doc/formats.md#bitcoin_block),
Expand All @@ -68,11 +66,10 @@ bsd_loopback_frame,
bzip2,
[caff](doc/formats.md#caff),
[cbor](doc/formats.md#cbor),
[chna](doc/formats.md#adm),
[csv](doc/formats.md#csv),
[dolby_metadata](doc/formats.md#dolby_metadata),
dns,
dns_tcp,
[dolby_metadata](doc/formats.md#dolby_metadata),
elf,
ether8023_frame,
exif,
Expand Down
44 changes: 15 additions & 29 deletions doc/formats.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
|[`aac_frame`](#aac_frame) |Advanced&nbsp;Audio&nbsp;Coding&nbsp;frame |<sub></sub>|
|`adts` |Audio&nbsp;Data&nbsp;Transport&nbsp;Stream |<sub>`adts_frame`</sub>|
|`adts_frame` |Audio&nbsp;Data&nbsp;Transport&nbsp;Stream&nbsp;frame |<sub>`aac_frame`</sub>|
|[`adm`](#adm) |Audio&nbsp;Definition&nbsp;Model |<sub>`riff`</sub>|
|`aiff` |Audio&nbsp;Interchange&nbsp;File&nbsp;Format |<sub></sub>|
|`amf0` |Action&nbsp;Message&nbsp;Format&nbsp;0 |<sub></sub>|
|`apev2` |APEv2&nbsp;metadata&nbsp;tag |<sub>`image`</sub>|
Expand All @@ -26,7 +25,6 @@
|`avc_sps` |H.264/AVC&nbsp;Sequence&nbsp;Parameter&nbsp;Set |<sub></sub>|
|[`avi`](#avi) |Audio&nbsp;Video&nbsp;Interleaved |<sub>`avc_au` `hevc_au` `mp3_frame` `flac_frame`</sub>|
|[`avro_ocf`](#avro_ocf) |Avro&nbsp;object&nbsp;container&nbsp;file |<sub></sub>|
|[`axml`](#adm) |Audio&nbsp;Definition&nbsp;Model&nbsp;<axml>&nbsp;Chunk |<sub>`riff`</sub>|
|[`bencode`](#bencode) |BitTorrent&nbsp;bencoding |<sub></sub>|
|`bitcoin_blkdat` |Bitcoin&nbsp;blk.dat |<sub>`bitcoin_block`</sub>|
|[`bitcoin_block`](#bitcoin_block) |Bitcoin&nbsp;block |<sub>`bitcoin_transaction`</sub>|
Expand All @@ -40,11 +38,10 @@
|`bzip2` |bzip2&nbsp;compression |<sub>`probe`</sub>|
|[`caff`](#caff) |Live2D&nbsp;Cubism&nbsp;archive |<sub>`probe`</sub>|
|[`cbor`](#cbor) |Concise&nbsp;Binary&nbsp;Object&nbsp;Representation |<sub></sub>|
|[`chna`](#adm) |Audio&nbsp;Definition&nbsp;Model&nbsp;<chna>&nbsp;Chunk |<sub>`riff`</sub>|
|[`csv`](#csv) |Comma&nbsp;separated&nbsp;values |<sub></sub>|
|[`dolby_metadata`](#dolby_metadata) |Dolby&nbsp;Metadata&nbsp;(Atmos,&nbsp;AC3,&nbsp;Digital&nbspPlus) |<sub>`riff`</sub>|
|`dns` |DNS&nbsp;packet |<sub></sub>|
|`dns_tcp` |DNS&nbsp;packet&nbsp;(TCP) |<sub></sub>|
|[`dolby_metadata`](#dolby_metadata) |Dolby&nbsp;Metadata&nbsp;(Atmos,&nbsp;AC3,&nbsp;Dolby&nbsp;Digital) |<sub></sub>|
|`elf` |Executable&nbsp;and&nbsp;Linkable&nbsp;Format |<sub></sub>|
|`ether8023_frame` |Ethernet&nbsp;802.3&nbsp;frame |<sub>`inet_packet`</sub>|
|`exif` |Exchangeable&nbsp;Image&nbsp;File&nbsp;Format |<sub></sub>|
Expand Down Expand Up @@ -133,7 +130,7 @@
|`vp9_frame` |VP9&nbsp;frame |<sub></sub>|
|`vpx_ccr` |VPX&nbsp;Codec&nbsp;Configuration&nbsp;Record |<sub></sub>|
|[`wasm`](#wasm) |WebAssembly&nbsp;Binary&nbsp;Format |<sub></sub>|
|`wav` |WAV&nbsp;file |<sub>`id3v2` `id3v1` `id3v11`</sub>|
|`wav` |WAV&nbsp;file |<sub>`id3v2` `id3v1` `id3v11` `dolby_metadata`</sub>|
|`webp` |WebP&nbsp;image |<sub>`exif` `vp8_frame` `icc_profile` `xml`</sub>|
|[`xml`](#xml) |Extensible&nbsp;Markup&nbsp;Language |<sub></sub>|
|`yaml` |YAML&nbsp;Ain't&nbsp;Markup&nbsp;Language |<sub></sub>|
Expand Down Expand Up @@ -183,27 +180,6 @@ Decode value as aac_frame
... | aac_frame({object_type:1})
```

## adm
[Audio Definition Model](https://adm.ebu.io/background/what_is_the_adm.html) including 3D Audio.

RIFF / WAV / Broadcast Wave Format (BWF) chunks:
- `<chna>` Chunk, Track UIDs of Audio Definition Model
- `<axml>` Chunk, BWF XML Metadata, e.g. for Audio Definition Model ambisonics and elements

### Examples
Decode ADM configuration from `<chna>` and `<axml>` chunks:
```
$ fq -d wav '.chunks[] | select(.id | IN("chna", "axml")) | tovalue' bwf.wav
```

### Authors
- [@johnnymarnell](https://johnnymarnell.github.io), original author

### References
- https://adm.ebu.io/background/what_is_the_adm.html
- https://tech.ebu.ch/publications/tech3285s7
- https://tech.ebu.ch/publications/tech3285s5

## apple_bookmark
Apple BookmarkData.

Expand Down Expand Up @@ -616,6 +592,8 @@ $ fq -d csv '.[0] as $t | .[1:] | map(with_entries(.key = $t[.key]))' file.csv
```

## dolby_metadata
Dolby Metadata (Atmos, AC3, Dolby Digital).

Dolby Metadata from `<dbmd>` chunk of RIFF / WAV / Broadcast Wave Format (BWF),
including Dolby Atmos, AC3, Dolby Digital \[Plus\], and Dolby Audio Info (e.g. LUFS, True Peak).

Expand All @@ -625,13 +603,20 @@ Decode Dolby metadata from `<dbmd>` chunk:
$ fq -d wav '.chunks[] | select(.id | IN("dbmd")) | tovalue' bwf.wav
```

### References
- https://tech.ebu.ch/files/live/sites/tech/files/shared/tech/tech3285s6.pdf
- https://github.com/DolbyLaboratories/dbmd-atmos-parser
RIFF / WAV / Broadcast Wave Format (BWF) chunks:
- `<chna>` Track UIDs of Audio Definition Model
- `<axml>` BWF XML Metadata, e.g. for Audio Definition Model ambisonics and elements

### Authors
- [@johnnymarnell](https://johnnymarnell.github.io), original author

### References
- https://adm.ebu.io/background/what_is_the_adm.html
- https://tech.ebu.ch/publications/tech3285s7
- https://tech.ebu.ch/publications/tech3285s5
- https://tech.ebu.ch/files/live/sites/tech/files/shared/tech/tech3285s6.pdf
- https://github.com/DolbyLaboratories/dbmd-atmos-parser

## fit
Garmin Flexible and Interoperable Data Transfer.

Expand Down Expand Up @@ -824,6 +809,7 @@ LevelDB Table.
- Zstandard uncompression is not implemented yet.

### Authors

- [@mikez](https://github.com/mikez), original author

### References
Expand Down
1 change: 1 addition & 0 deletions format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ var (
CSV = &decode.Group{Name: "csv"}
DNS = &decode.Group{Name: "dns"}
DNS_TCP = &decode.Group{Name: "dns_tcp"}
Dolby_Metadata = &decode.Group{Name: "dolby_metadata"}
ELF = &decode.Group{Name: "elf"}
Ether_8023_Frame = &decode.Group{Name: "ether8023_frame"}
Exif = &decode.Group{Name: "exif"}
Expand Down
25 changes: 13 additions & 12 deletions format/riff/adm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,22 @@ import (
"github.com/wader/fq/pkg/decode"
)

func chnaDecode(d *decode.D, size int64) {
func chnaDecode(d *decode.D) {
d.FieldU16("num_tracks")
d.FieldU16("num_uids")

audioIdLen := (size - 4) / 40
d.FieldStructNArray("audio_ids", "audio_id", int64(audioIdLen), func(d *decode.D) {
d.FieldU16("track_index")
d.FieldUTF8("uid", 12)
d.FieldUTF8("track_format_id_reference", 14)
d.FieldUTF8("pack_format_id_reference", 11)
d.FieldRawLen("padding", 8)
d.FieldArray("audio_ids", func(d *decode.D) {
for !d.End() {
d.FieldStruct("audio_id", func(d *decode.D) {
d.FieldU16("track_index")
d.FieldUTF8("uid", 12)
d.FieldUTF8("track_format_id_reference", 14)
d.FieldUTF8("pack_format_id_reference", 11)
d.FieldRawLen("padding", 8)
})
}
})
}

func axmlDecode(d *decode.D, size int64) {
// TODO(jmarnell): this chunk is all variable xml, so leave as is?
d.FieldUTF8("xml", int(size))
func axmlDecode(d *decode.D) {
d.FieldUTF8("xml", int(d.BitsLeft())/8)
}
2 changes: 1 addition & 1 deletion format/riff/aiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func aiffDecode(d *decode.D) any {
}
return id, size
},
func(d *decode.D, id string, path path, size int64) (bool, any) {
func(d *decode.D, id string, path path) (bool, any) {
switch id {
case "FORM":
riffType = d.FieldUTF8("format", 4, d.StrAssert(aiffRiffType))
Expand Down
2 changes: 1 addition & 1 deletion format/riff/avi.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func aviDecodeEx(d *decode.D, ai format.AVI_In, extendedChunk bool) {
size := d.FieldU32("size")
return id, int64(size)
},
func(d *decode.D, id string, path path, size int64) (bool, any) {
func(d *decode.D, id string, path path) (bool, any) {
switch id {
case "RIFF":
foundRiffType = d.FieldUTF8("type", 4, d.StrAssert(requiredRiffType))
Expand Down
4 changes: 2 additions & 2 deletions format/riff/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ func (p path) topData() any {
return p[len(p)-1].data
}

func riffDecode(d *decode.D, path path, headFn func(d *decode.D, path path) (string, int64), chunkFn func(d *decode.D, id string, path path, size int64) (bool, any)) {
func riffDecode(d *decode.D, path path, headFn func(d *decode.D, path path) (string, int64), chunkFn func(d *decode.D, id string, path path) (bool, any)) {
id, size := headFn(d, path)

d.FramedFn(size*8, func(d *decode.D) {
hasChildren, data := chunkFn(d, id, path, size)
hasChildren, data := chunkFn(d, id, path)
if hasChildren {
np := append(path, pathEntry{id: id, data: data})
d.FieldArray("chunks", func(d *decode.D) {
Expand Down
Loading

0 comments on commit 04539fe

Please sign in to comment.