1
1
mirror of https://github.com/wader/fq.git synced 2025-01-08 23:59:50 +03:00

matroska: Add decode_samples option

Also change the option help a bit, maybe medid and support is confusing, we
might evetually decode non-audio/video things.
This commit is contained in:
Mattias Wadman 2023-02-08 11:21:08 +01:00
parent 5b3ed334e6
commit b60aceca9e
7 changed files with 105 additions and 9 deletions

View File

@ -260,7 +260,7 @@ Decode value as avc_au
|Name |Default|Description|
|- |- |-|
|`decode_samples`|true |Decode supported media samples|
|`decode_samples`|true |Decode samples|
### Examples
@ -668,6 +668,24 @@ $ fq -d markdown '[.. | select(.type=="heading" and .level<=2)?.children[0]]' fi
```
## matroska
### Options
|Name |Default|Description|
|- |- |-|
|`decode_samples`|true |Decode samples|
### Examples
Decode file using matroska options
```
$ fq -d matroska -o decode_samples=true . file
```
Decode value as matroska
```
... | matroska({decode_samples:true})
```
### Lookup element using path
```sh
@ -716,7 +734,7 @@ Decode value as mp3
|Name |Default|Description|
|- |- |-|
|`allow_truncated`|false |Allow box to be truncated|
|`decode_samples` |true |Decode supported media samples|
|`decode_samples` |true |Decode samples|
### Examples

View File

@ -205,6 +205,10 @@ type ProtoBufIn struct {
Message ProtoBufMessage
}
type MatroskaIn struct {
DecodeSamples bool `doc:"Decode samples"`
}
type MpegDecoderConfig struct {
ObjectType int
ASCObjectType int
@ -296,12 +300,12 @@ func (t TCPStreamIn) MustIsPort(fn func(format string, a ...any), ports ...int)
}
type Mp4In struct {
DecodeSamples bool `doc:"Decode supported media samples"`
DecodeSamples bool `doc:"Decode samples"`
AllowTruncated bool `doc:"Allow box to be truncated"`
}
type AviIn struct {
DecodeSamples bool `doc:"Decode supported media samples"`
DecodeSamples bool `doc:"Decode samples"`
}
type ZipIn struct {

View File

@ -58,6 +58,9 @@ func init() {
Description: "Matroska file",
Groups: []string{format.PROBE},
DecodeFn: matroskaDecode,
DecodeInArg: format.MatroskaIn{
DecodeSamples: true,
},
Dependencies: []decode.Dependency{
{Names: []string{format.AAC_FRAME}, Group: &aacFrameFormat},
{Names: []string{format.AV1_CCR}, Group: &av1CCRFormat},
@ -412,7 +415,9 @@ func decodeMaster(d *decode.D, bitsLimit int64, tag ebml.Tag, dc *decodeContext)
}
func matroskaDecode(d *decode.D, _ any) any {
func matroskaDecode(d *decode.D, in any) any {
mi, _ := in.(format.MatroskaIn)
ebmlHeaderID := uint64(0x1a45dfa3)
if d.PeekBits(32) != ebmlHeaderID {
d.Errorf("no EBML header found")
@ -437,7 +442,11 @@ func matroskaDecode(d *decode.D, _ any) any {
case "A_VORBIS":
t.parentD.RangeFn(t.codecPrivatePos, t.codecPrivateTagSize, func(d *decode.D) {
decodeLacingFn(d, lacingTypeXiph, func(d *decode.D) {
d.FieldFormat("packet", vorbisPacketFormat, nil)
if mi.DecodeSamples {
d.FieldFormat("packet", vorbisPacketFormat, nil)
} else {
d.FieldRawLen("packet", d.BitsLeft())
}
})
})
case "A_AAC":
@ -519,7 +528,7 @@ func matroskaDecode(d *decode.D, _ any) any {
}
decodeLacingFn(d, int(lacing), func(d *decode.D) {
if f != nil {
if mi.DecodeSamples && f != nil {
d.FieldFormat("packet", *f, track.formatInArg)
} else {
d.FieldRawLen("packet", d.BitsLeft())

View File

@ -0,0 +1,56 @@
$ fq -o decode_samples=true 'first(grep_by(.id=="simple_block")) | dv' aac.mkv
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.elements[1].elements[5].elements[2]{}: element 0x227-0x2fa.7 (212)
0x220| a3 | . | id: "simple_block" (0xa3) (Similar to Block, see (#block-structure), but without all the extra information, mostly used to reduced overhead when no extra feature is needed; see (#simpleblock-structure) on SimpleBlock Structure.) 0x227-0x227.7 (1)
| | | type: "binary" 0x228-NA (0)
0x220| 40 d1 | @. | size: 209 0x228-0x229.7 (2)
0x220| 81 | . | track_number: 1 0x22a-0x22a.7 (1)
0x220| 00 00 | .. | timestamp: 0 0x22b-0x22c.7 (2)
| | | flags{}: 0x22d-0x22d.7 (1)
0x220| 80 | . | key_frame: true 0x22d-0x22d (0.1)
0x220| 80 | . | reserved: 0 0x22d.1-0x22d.3 (0.3)
0x220| 80 | . | invisible: false 0x22d.4-0x22d.4 (0.1)
0x220| 80 | . | lacing: "none" (0) 0x22d.5-0x22d.6 (0.2)
0x220| 80 | . | discardable: false 0x22d.7-0x22d.7 (0.1)
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef| packet[0:4]: (aac_frame) 0x22e-0x2fa.7 (205)
| | | [0]{}: element 0x22e-0x23e.6 (16.7)
0x220| de | . | syntax_element: "FIL" (6) 0x22e-0x22e.2 (0.3)
| | | cnt{}: 0x22e.3-0x22f.6 (1.4)
0x220| de | . | count: 15 0x22e.3-0x22e.6 (0.4)
0x220| de 02| ..| esc_count: 1 0x22e.7-0x22f.6 (1)
| | | payload_length: 15 0x22f.7-NA (0)
| | | extension_payload{}: 0x22f.7-0x23e.6 (15)
0x220| 02| .| extension_type: "EXT_FILL" (0) 0x22f.7-0x230.2 (0.4)
0x230|00 |. |
0x230|00 |. | fill_nibble: 0 0x230.3-0x230.6 (0.4)
0x230|00 4c 61 76 63 35 38 2e 39 31 2e 31 30 30 00 |.Lavc58.91.100. | fill_byte: raw bits 0x230.7-0x23e.6 (14)
| | | [1]{}: element 0x23e.7-0x242 (3.2)
0x230| 00 02| ..| syntax_element: "SCE" (0) 0x23e.7-0x23f.1 (0.3)
0x230| 02| .| element_instance_tag: 0 0x23f.2-0x23f.5 (0.4)
0x230| 02| .| global_gain: 151 0x23f.6-0x240.5 (1)
0x240|5c |\ |
| | | ics_info{}: 0x240.6-0x242 (1.3)
0x240|5c |\ | ics_reserved_bit: 0 0x240.6-0x240.6 (0.1)
0x240|5c ab |\. | window_sequence: "LONG_START_SEQUENCE" (1) 0x240.7-0x241 (0.2)
0x240| ab | . | window_shape: 0 0x241.1-0x241.1 (0.1)
0x240| ab | . | max_sfb: 43 0x241.2-0x241.7 (0.6)
0x240| 59 | Y | predictor_data_present: false 0x242-0x242 (0.1)
0x240| 59 | Y | [2]: raw bits byte_align 0x242.1-0x242.7 (0.7)
0x240| a9 8c 72 50 8b 4c aa de 1d 71 72 5c 88| ..rP.L...qr\.| [3]: raw bits data 0x243-0x2fa.7 (184)
0x250|42 08 10 0e 80 0c d5 9f 71 6c 47 12 cb b6 16 71|B.......qlG....q|
* |until 0x2fa.7 (184) | |
$ fq -o decode_samples=false 'first(grep_by(.id=="simple_block")) | dv' aac.mkv
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.elements[1].elements[5].elements[2]{}: element 0x227-0x2fa.7 (212)
0x220| a3 | . | id: "simple_block" (0xa3) (Similar to Block, see (#block-structure), but without all the extra information, mostly used to reduced overhead when no extra feature is needed; see (#simpleblock-structure) on SimpleBlock Structure.) 0x227-0x227.7 (1)
| | | type: "binary" 0x228-NA (0)
0x220| 40 d1 | @. | size: 209 0x228-0x229.7 (2)
0x220| 81 | . | track_number: 1 0x22a-0x22a.7 (1)
0x220| 00 00 | .. | timestamp: 0 0x22b-0x22c.7 (2)
| | | flags{}: 0x22d-0x22d.7 (1)
0x220| 80 | . | key_frame: true 0x22d-0x22d (0.1)
0x220| 80 | . | reserved: 0 0x22d.1-0x22d.3 (0.3)
0x220| 80 | . | invisible: false 0x22d.4-0x22d.4 (0.1)
0x220| 80 | . | lacing: "none" (0) 0x22d.5-0x22d.6 (0.2)
0x220| 80 | . | discardable: false 0x22d.7-0x22d.7 (0.1)
0x220| de 02| ..| packet: raw bits 0x22e-0x2fa.7 (205)
0x230|00 4c 61 76 63 35 38 2e 39 31 2e 31 30 30 00 02|.Lavc58.91.100..|
* |until 0x2fa.7 (205) | |

View File

@ -1,6 +1,11 @@
$ fq -h matroska
matroska: Matroska file decoder
Options
=======
decode_samples=true Decode samples
Decode examples
===============
@ -8,6 +13,10 @@ Decode examples
$ fq -d matroska . file
# Decode value as matroska
... | matroska
# Decode file using matroska options
$ fq -d matroska -o decode_samples=true . file
# Decode value as matroska
... | matroska({decode_samples:true})
Lookup element using path
=========================

View File

@ -5,7 +5,7 @@ Options
=======
allow_truncated=false Allow box to be truncated
decode_samples=true Decode supported media samples
decode_samples=true Decode samples
Decode examples
===============

View File

@ -4,7 +4,7 @@ avi: Audio Video Interleaved decoder
Options
=======
decode_samples=true Decode supported media samples
decode_samples=true Decode samples
Decode examples
===============