1
1
mirror of https://github.com/wader/fq.git synced 2024-10-04 15:38:17 +03:00

Merge pull request #404 from wader/matroska-lacing

matroska: Add proper lacing support
This commit is contained in:
Mattias Wadman 2022-08-28 21:13:50 +02:00 committed by GitHub
commit e0bd489668
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 3485 additions and 83 deletions

View File

@ -99,6 +99,96 @@ func init() {
}
}
const (
lacingTypeNone = 0b00
lacingTypeXiph = 0b01
lacingTypeFixed = 0b10
lacingTypeEBML = 0b11
)
var lacingTypeNames = scalar.UToSymStr{
lacingTypeNone: "none",
lacingTypeXiph: "xiph",
lacingTypeFixed: "fixed",
lacingTypeEBML: "ebml",
}
func decodeLacingFn(d *decode.D, lacingType int, fn func(d *decode.D)) {
if lacingType == lacingTypeNone {
fn(d)
return
}
// -1 size means rest of buffer, used last sometimes
var laceSizes []int64
switch lacingType {
case lacingTypeXiph:
numLaces := int(d.FieldU8("num_laces"))
d.FieldArray("lace_sizes", func(d *decode.D) {
for i := 0; i < numLaces; i++ {
s := int64(d.FieldUFn("lace_size", decodeXiphLaceSize))
laceSizes = append(laceSizes, s)
}
laceSizes = append(laceSizes, -1)
})
case lacingTypeEBML:
numLaces := int(d.FieldU8("num_laces"))
d.FieldArray("lace_sizes", func(d *decode.D) {
s := int64(d.FieldUFn("lace_size", decodeVint)) // first is unsigned, not ranged shifted
laceSizes = append(laceSizes, s)
for i := 0; i < numLaces-1; i++ {
d := int64(d.FieldUFn("lace_size_delta", decodeRawVint))
// range shifting
switch {
case d&0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1000_0000 == 0b0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_1000_0000:
// value -(2^6^-1) to 2^6^-1 (ie 0_to 2^7^-2 minus 2^6^-1, half of the range)
d -= 0b0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_1011_1111
case d&0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1100_0000_0000_0000 == 0b0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0100_0000_0000_0000:
// value -(2^13^-1) to 2^13^-1
d -= 0b0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0101_1111_1111_1111
case d&0b1111_1111_1111_1111_1111_1111_1111_1111_1110_0000_0000_0000_0000_0000 == 0b0000_0000_0000_0000_0000_0000_0000_0000_0010_0000_0000_0000_0000_0000:
// value -(2^20^-1) to 2^20^-1
d -= 0b0000_0000_0000_0000_0000_0000_0000_0000_0010_1111_1111_1111_1111_1111
case d&0b1111_1111_1111_1111_1111_1111_1111_0000_0000_0000_0000_0000_0000_0000 == 0b0000_0000_0000_0000_0000_0000_0001_0000_0000_0000_0000_0000_0000_0000:
// value -(2^27^-1) to 2^27^-1
d -= 0b0000_0000_0000_0000_0000_0000_0001_0111_1111_1111_1111_1111_1111_1111
case d&0b1111_1111_1111_1111_1111_1000_0000_0000_0000_0000_0000_0000_0000_0000 == 0b0000_0000_0000_0000_0000_1000_0000_0000_0000_0000_0000_0000_0000_0000:
// value -(2^34^-1) to 2^34^-1
d -= 0b0000_0000_0000_0000_0000_1011_1111_1111_1111_1111_1111_1111_1111_1111
case d&0b1111_1111_1111_1100_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000 == 0b0000_0000_0000_0100_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000:
// value -(2^41^-1) to 2^41^-1
d -= 0b0000_0000_0000_0101_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111
case d&0b1111_1110_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000 == 0b0000_0010_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000:
// value -(2^48^-1) to 2^48^-1
d -= 0b0000_0010_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111
}
s += d
laceSizes = append(laceSizes, s)
}
laceSizes = append(laceSizes, -1)
})
case lacingTypeFixed:
numLaces := int(d.FieldU8("num_laces"))
fixedSize := (d.BitsLeft() / 8) / int64(numLaces+1)
for i := 0; i < numLaces+1; i++ {
laceSizes = append(laceSizes, fixedSize)
}
default:
panic("unreachable")
}
d.FieldArray("laces", func(d *decode.D) {
for _, laceSize := range laceSizes {
s := laceSize * 8
if laceSize == -1 {
s = d.BitsLeft()
}
d.FramedFn(s, fn)
}
})
}
// TODO: smarter?
func decodeRawVintWidth(d *decode.D) (uint64, int) {
n := d.U8()
@ -123,6 +213,17 @@ func decodeVint(d *decode.D) uint64 {
return n & m
}
func decodeXiphLaceSize(d *decode.D) uint64 {
var s uint64
for {
n := d.U8()
s += n
if n < 255 {
return s
}
}
}
type track struct {
parentD *decode.D
number int
@ -332,30 +433,8 @@ func matroskaDecode(d *decode.D, _ any) any {
switch t.codec {
case "A_VORBIS":
t.parentD.RangeFn(t.codecPrivatePos, t.codecPrivateTagSize, func(d *decode.D) {
numPackets := d.FieldU8("num_packets")
// TODO: lacing
packetLengths := []int64{}
// Xiph-style lacing (similar to ogg) of n-1 packets, last is reset of block
d.FieldArray("laces", func(d *decode.D) {
for i := uint64(0); i < numPackets; i++ {
l := d.FieldUFn("lace", func(d *decode.D) uint64 {
var l uint64
for {
n := d.U8()
l += n
if n < 255 {
return l
}
}
})
packetLengths = append(packetLengths, int64(l))
}
})
d.FieldArray("packets", func(d *decode.D) {
for _, l := range packetLengths {
d.FieldFormatLen("packet", l*8, vorbisPacketFormat, nil)
}
d.FieldFormatLen("packet", d.BitsLeft(), vorbisPacketFormat, nil)
decodeLacingFn(d, lacingTypeXiph, func(d *decode.D) {
d.FieldFormat("packet", vorbisPacketFormat, nil)
})
})
case "A_AAC":
@ -409,6 +488,7 @@ func matroskaDecode(d *decode.D, _ any) any {
for _, b := range dc.blocks {
b.d.RangeFn(b.r.Start, b.r.Len, func(d *decode.D) {
var lacing uint64
trackNumber := d.FieldUFn("track_number", decodeVint)
d.FieldU16("timestamp")
if b.simple {
@ -416,29 +496,32 @@ func matroskaDecode(d *decode.D, _ any) any {
d.FieldBool("key_frame")
d.FieldU3("reserved")
d.FieldBool("invisible")
d.FieldU2("lacing")
lacing = d.FieldU2("lacing", lacingTypeNames)
d.FieldBool("discardable")
})
} else {
d.FieldStruct("flags", func(d *decode.D) {
d.FieldU4("reserved")
d.FieldBool("invisible")
d.FieldU2("lacing")
lacing = d.FieldU2("lacing", lacingTypeNames)
d.FieldBool("not_used")
})
}
// TODO: lacing etc
// TODO: fixed/unknown?
if t, ok := trackNumberToTrack[int(trackNumber)]; ok {
if f, ok := codecToFormat[t.codec]; ok {
d.FieldFormat("packet", *f, t.formatInArg)
var f *decode.Group
var track *track
track, trackOk := trackNumberToTrack[int(trackNumber)]
if trackOk {
f = codecToFormat[track.codec]
}
decodeLacingFn(d, int(lacing), func(d *decode.D) {
if f != nil {
d.FieldFormat("packet", *f, track.formatInArg)
} else {
d.FieldRawLen("packet", d.BitsLeft())
}
}
if d.BitsLeft() > 0 {
d.FieldRawLen("data", d.BitsLeft())
}
})
})
}

View File

@ -356,7 +356,7 @@ $ fq -d matroska dv aac.mkv
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: 0 0x22d.5-0x22d.6 (0.2)
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)
@ -396,7 +396,7 @@ $ fq -d matroska dv aac.mkv
0x300| 80 | . | key_frame: true 0x301-0x301 (0.1)
0x300| 80 | . | reserved: 0 0x301.1-0x301.3 (0.3)
0x300| 80 | . | invisible: false 0x301.4-0x301.4 (0.1)
0x300| 80 | . | lacing: 0 0x301.5-0x301.6 (0.2)
0x300| 80 | . | lacing: "none" (0) 0x301.5-0x301.6 (0.2)
0x300| 80 | . | discardable: false 0x301.7-0x301.7 (0.1)
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef| packet[0:3]: (aac_frame) 0x302-0x3db.7 (218)
| | | [0]{}: element 0x302-0x305.5 (3.6)
@ -423,7 +423,7 @@ $ fq -d matroska dv aac.mkv
0x3e0| 80 | . | key_frame: true 0x3e2-0x3e2 (0.1)
0x3e0| 80 | . | reserved: 0 0x3e2.1-0x3e2.3 (0.3)
0x3e0| 80 | . | invisible: false 0x3e2.4-0x3e2.4 (0.1)
0x3e0| 80 | . | lacing: 0 0x3e2.5-0x3e2.6 (0.2)
0x3e0| 80 | . | lacing: "none" (0) 0x3e2.5-0x3e2.6 (0.2)
0x3e0| 80 | . | discardable: false 0x3e2.7-0x3e2.7 (0.1)
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef| packet[0:3]: (aac_frame) 0x3e3-0x49c.7 (186)
| | | [0]{}: element 0x3e3-0x3e6.5 (3.6)
@ -450,7 +450,7 @@ $ fq -d matroska dv aac.mkv
0x4a0| 80 | . | key_frame: true 0x4a2-0x4a2 (0.1)
0x4a0| 80 | . | reserved: 0 0x4a2.1-0x4a2.3 (0.3)
0x4a0| 80 | . | invisible: false 0x4a2.4-0x4a2.4 (0.1)
0x4a0| 80 | . | lacing: 0 0x4a2.5-0x4a2.6 (0.2)
0x4a0| 80 | . | lacing: "none" (0) 0x4a2.5-0x4a2.6 (0.2)
0x4a0| 80 | . | discardable: false 0x4a2.7-0x4a2.7 (0.1)
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef| packet[0:3]: (aac_frame) 0x4a3-0x4a7.7 (5)
| | | [0]{}: element 0x4a3-0x4a6.5 (3.6)

View File

@ -366,7 +366,7 @@ $ fq -d matroska dv av1.mkv
0x0230| 80 | . | key_frame: true 0x236-0x236 (0.1)
0x0230| 80 | . | reserved: 0 0x236.1-0x236.3 (0.3)
0x0230| 80 | . | invisible: false 0x236.4-0x236.4 (0.1)
0x0230| 80 | . | lacing: 0 0x236.5-0x236.6 (0.2)
0x0230| 80 | . | lacing: "none" (0) 0x236.5-0x236.6 (0.2)
0x0230| 80 | . | discardable: false 0x236.7-0x236.7 (0.1)
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef| packet[0:3]: (av1_frame) 0x237-0x13ca.7 (4500)
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef| [0]{}: obu (av1_obu) 0x237-0x245.7 (15)

View File

@ -453,7 +453,7 @@ $ fq -d matroska dv avc.mkv
0x00260| 80 | . | key_frame: true 0x26a-0x26a (0.1)
0x00260| 80 | . | reserved: 0 0x26a.1-0x26a.3 (0.3)
0x00260| 80 | . | invisible: false 0x26a.4-0x26a.4 (0.1)
0x00260| 80 | . | lacing: 0 0x26a.5-0x26a.6 (0.2)
0x00260| 80 | . | lacing: "none" (0) 0x26a.5-0x26a.6 (0.2)
0x00260| 80 | . | discardable: false 0x26a.7-0x26a.7 (0.1)
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef| packet[0:2]: (avc_au) 0x26b-0xd2a.7 (2752)
| | | [0]{}: nalu 0x26b-0x51b.7 (689)

View File

@ -371,7 +371,7 @@ $ fq -d matroska dv flac.mkv
0x250| 80 | . | key_frame: true 0x254-0x254 (0.1)
0x250| 80 | . | reserved: 0 0x254.1-0x254.3 (0.3)
0x250| 80 | . | invisible: false 0x254.4-0x254.4 (0.1)
0x250| 80 | . | lacing: 0 0x254.5-0x254.6 (0.2)
0x250| 80 | . | lacing: "none" (0) 0x254.5-0x254.6 (0.2)
0x250| 80 | . | discardable: false 0x254.7-0x254.7 (0.1)
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef| packet{}: (flac_frame) 0x255-0x4b2.7 (606)
| | | header{}: 0x255-0x25c.7 (8)

View File

@ -660,7 +660,7 @@ $ fq -d matroska dv hevc.mkv
0x0b70| 80 | . | key_frame: true 0xb79-0xb79 (0.1)
0x0b70| 80 | . | reserved: 0 0xb79.1-0xb79.3 (0.3)
0x0b70| 80 | . | invisible: false 0xb79.4-0xb79.4 (0.1)
0x0b70| 80 | . | lacing: 0 0xb79.5-0xb79.6 (0.2)
0x0b70| 80 | . | lacing: "none" (0) 0xb79.5-0xb79.6 (0.2)
0x0b70| 80 | . | discardable: false 0xb79.7-0xb79.7 (0.1)
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef| packet[0:1]: (hevc_au) 0xb7a-0x13ce.7 (2133)
| | | [0]{}: nalu 0xb7a-0x13ce.7 (2133)

View File

@ -348,7 +348,7 @@ $ fq -d matroska dv mp3.mkv
0x230|80 |. | key_frame: true 0x230-0x230 (0.1)
0x230|80 |. | reserved: 0 0x230.1-0x230.3 (0.3)
0x230|80 |. | invisible: false 0x230.4-0x230.4 (0.1)
0x230|80 |. | lacing: 0 0x230.5-0x230.6 (0.2)
0x230|80 |. | lacing: "none" (0) 0x230.5-0x230.6 (0.2)
0x230|80 |. | discardable: false 0x230.7-0x230.7 (0.1)
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef| packet{}: (mp3_frame) 0x231-0x300.7 (208)
| | | header{}: 0x231-0x234.7 (4)
@ -420,7 +420,7 @@ $ fq -d matroska dv mp3.mkv
0x300| 80 | . | key_frame: true 0x307-0x307 (0.1)
0x300| 80 | . | reserved: 0 0x307.1-0x307.3 (0.3)
0x300| 80 | . | invisible: false 0x307.4-0x307.4 (0.1)
0x300| 80 | . | lacing: 0 0x307.5-0x307.6 (0.2)
0x300| 80 | . | lacing: "none" (0) 0x307.5-0x307.6 (0.2)
0x300| 80 | . | discardable: false 0x307.7-0x307.7 (0.1)
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef| packet{}: (mp3_frame) 0x308-0x3d8.7 (209)
| | | header{}: 0x308-0x30b.7 (4)
@ -497,7 +497,7 @@ $ fq -d matroska dv mp3.mkv
| | | flags{}: 0x3e8-0x3e8.7 (1)
0x3e0| 00 | . | reserved: 0 0x3e8-0x3e8.3 (0.4)
0x3e0| 00 | . | invisible: false 0x3e8.4-0x3e8.4 (0.1)
0x3e0| 00 | . | lacing: 0 0x3e8.5-0x3e8.6 (0.2)
0x3e0| 00 | . | lacing: "none" (0) 0x3e8.5-0x3e8.6 (0.2)
0x3e0| 00 | . | not_used: false 0x3e8.7-0x3e8.7 (0.1)
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef| packet{}: (mp3_frame) 0x3e9-0x4b9.7 (209)
| | | header{}: 0x3e9-0x3ec.7 (4)

View File

@ -347,9 +347,9 @@ $ fq -d matroska dv mpeg2.mkv
0x0230| 80 | . | key_frame: true 0x233-0x233 (0.1)
0x0230| 80 | . | reserved: 0 0x233.1-0x233.3 (0.3)
0x0230| 80 | . | invisible: false 0x233.4-0x233.4 (0.1)
0x0230| 80 | . | lacing: 0 0x233.5-0x233.6 (0.2)
0x0230| 80 | . | lacing: "none" (0) 0x233.5-0x233.6 (0.2)
0x0230| 80 | . | discardable: false 0x233.7-0x233.7 (0.1)
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef| packet{}: (mpeg_pes_packet) 0x234-0x23f.7 (12)
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef| packet{}: (mpeg_pes_packet) 0x234-0x21ad.7 (8058)
0x0230| 00 00 01 | ... | prefix: 0b1 (valid) 0x234-0x236.7 (3)
0x0230| b3 | . | start_code: "sequence_header" (0xb3) 0x237-0x237.7 (1)
0x0230| 14 00 | .. | horizontal_size: 320 0x238-0x239.3 (1.4)
@ -362,7 +362,7 @@ $ fq -d matroska dv mpeg2.mkv
0x0230| 18| .| constrained_parameters_flag: 0 0x23f.5-0x23f.5 (0.1)
0x0230| 18| .| load_intra_quantizer_matrix: false 0x23f.6-0x23f.6 (0.1)
0x0230| 18| .| load_non_intra_quantizer_matrix: false 0x23f.7-0x23f.7 (0.1)
0x0240|00 00 01 b5 14 8a 00 01 00 00 00 00 01 b8 00 08|................| data: raw bits 0x240-0x21ad.7 (8046)
0x0240|00 00 01 b5 14 8a 00 01 00 00 00 00 01 b8 00 08|................| data: raw bits 0x240-0x21ad.7 (8046)
* |until 0x21ad.7 (8046) | |
| | | [6]{}: element 0x21ae-0x21c9.7 (28)
0x21a0| 1c 53| .S| id: "cues" (0x1c53bb6b) (A Top-Level Element to speed seeking access. All entries are local to the Segment.) 0x21ae-0x21b1.7 (4)

View File

@ -372,7 +372,7 @@ $ fq -d matroska dv opus.mkv
0x240| 80 | . | key_frame: true 0x249-0x249 (0.1)
0x240| 80 | . | reserved: 0 0x249.1-0x249.3 (0.3)
0x240| 80 | . | invisible: false 0x249.4-0x249.4 (0.1)
0x240| 80 | . | lacing: 0 0x249.5-0x249.6 (0.2)
0x240| 80 | . | lacing: "none" (0) 0x249.5-0x249.6 (0.2)
0x240| 80 | . | discardable: false 0x249.7-0x249.7 (0.1)
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef| packet{}: (opus_packet) 0x24a-0x2c2.7 (121)
| | | type: "audio" 0x24a-NA (0)
@ -400,7 +400,7 @@ $ fq -d matroska dv opus.mkv
0x2c0| 80 | . | key_frame: true 0x2c8-0x2c8 (0.1)
0x2c0| 80 | . | reserved: 0 0x2c8.1-0x2c8.3 (0.3)
0x2c0| 80 | . | invisible: false 0x2c8.4-0x2c8.4 (0.1)
0x2c0| 80 | . | lacing: 0 0x2c8.5-0x2c8.6 (0.2)
0x2c0| 80 | . | lacing: "none" (0) 0x2c8.5-0x2c8.6 (0.2)
0x2c0| 80 | . | discardable: false 0x2c8.7-0x2c8.7 (0.1)
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef| packet{}: (opus_packet) 0x2c9-0x341.7 (121)
| | | type: "audio" 0x2c9-NA (0)
@ -432,7 +432,7 @@ $ fq -d matroska dv opus.mkv
| | | flags{}: 0x350-0x350.7 (1)
0x350|00 |. | reserved: 0 0x350-0x350.3 (0.4)
0x350|00 |. | invisible: false 0x350.4-0x350.4 (0.1)
0x350|00 |. | lacing: 0 0x350.5-0x350.6 (0.2)
0x350|00 |. | lacing: "none" (0) 0x350.5-0x350.6 (0.2)
0x350|00 |. | not_used: false 0x350.7-0x350.7 (0.1)
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef| packet{}: (opus_packet) 0x351-0x3c9.7 (121)
| | | type: "audio" 0x351-NA (0)

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -237,11 +237,11 @@ $ fq -d matroska dv vorbis.mkv
0x0170| 63 a2 | c. | id: "codec_private" (0x63a2) (Private data only known to the codec.) 0x172-0x173.7 (2)
| | | type: "binary" 0x174-NA (0)
0x0170| 4c e0 | L. | size: 3296 0x174-0x175.7 (2)
0x0170| 02 | . | num_packets: 2 0x176-0x176.7 (1)
| | | laces[0:2]: 0x177-0x178.7 (2)
0x0170| 1e | . | [0]: 30 lace 0x177-0x177.7 (1)
0x0170| 10 | . | [1]: 16 lace 0x178-0x178.7 (1)
| | | packets[0:3]: 0x179-0xe55.7 (3293)
0x0170| 02 | . | num_laces: 2 0x176-0x176.7 (1)
| | | lace_sizes[0:2]: 0x177-0x178.7 (2)
0x0170| 1e | . | [0]: 30 lace_size 0x177-0x177.7 (1)
0x0170| 10 | . | [1]: 16 lace_size 0x178-0x178.7 (1)
| | | laces[0:3]: 0x179-0xe55.7 (3293)
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef| [0]{}: packet (vorbis_packet) 0x179-0x196.7 (30)
0x0170| 01 | . | packet_type: "Identification" (1) 0x179-0x179.7 (1)
0x0170| 76 6f 72 62 69 73| vorbis| magic: "vorbis" (valid) 0x17a-0x17f.7 (6)
@ -275,7 +275,7 @@ $ fq -d matroska dv vorbis.mkv
0x01b0|43 56 |CV |
0x01b0| 02 00 | .. | codebook_dimensions: 2 0x1b2-0x1b3.7 (2)
0x01b0| 10 00 00 | ... | codebook_entries: 16 0x1b4-0x1b6.7 (3)
0x01b0| 84 74 9a 59 aa 01 22 cc 40| .t.Y..".@| unknown0: raw bits 0x1b7-0xe55.7 (3231)
0x01b0| 84 74 9a 59 aa 01 22 cc 40| .t.Y..".@| data: raw bits 0x1b7-0xe55.7 (3231)
0x01c0|86 81 d0 90 95 00 00 02 00 00 60 84 22 0c 31 20|..........`.".1 |
* |until 0xe55.7 (3231) | |
| | | [4]{}: element 0xe56-0xefa.7 (165)
@ -393,11 +393,11 @@ $ fq -d matroska dv vorbis.mkv
0x0f10|80 |. | key_frame: true 0xf10-0xf10 (0.1)
0x0f10|80 |. | reserved: 0 0xf10.1-0xf10.3 (0.3)
0x0f10|80 |. | invisible: false 0xf10.4-0xf10.4 (0.1)
0x0f10|80 |. | lacing: 0 0xf10.5-0xf10.6 (0.2)
0x0f10|80 |. | lacing: "none" (0) 0xf10.5-0xf10.6 (0.2)
0x0f10|80 |. | discardable: false 0xf10.7-0xf10.7 (0.1)
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef| packet{}: (vorbis_packet) 0xf11-0xf11.7 (1)
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef| packet{}: (vorbis_packet) 0xf11-0xfc6.7 (182)
0x0f10| be | . | packet_type: "Audio" (0) 0xf11-0xf11.7 (1)
0x0f10| b7 f2 81 46 74 15 42 0b 52 08 17 32 8e 43| ...Ft.B.R..2.C| data: raw bits 0xf12-0xfc6.7 (181)
0x0f10| b7 f2 81 46 74 15 42 0b 52 08 17 32 8e 43| ...Ft.B.R..2.C| data: raw bits 0xf12-0xfc6.7 (181)
0x0f20|08 65 84 84 f6 56 3e d0 88 ae 42 68 41 0a e1 42|.e...V>...BhA..B|
* |until 0xfc6.7 (181) | |
| | | [3]{}: element 0xfc7-0x1018.7 (82)
@ -410,11 +410,11 @@ $ fq -d matroska dv vorbis.mkv
0x0fc0| 80 | . | key_frame: true 0xfcc-0xfcc (0.1)
0x0fc0| 80 | . | reserved: 0 0xfcc.1-0xfcc.3 (0.3)
0x0fc0| 80 | . | invisible: false 0xfcc.4-0xfcc.4 (0.1)
0x0fc0| 80 | . | lacing: 0 0xfcc.5-0xfcc.6 (0.2)
0x0fc0| 80 | . | lacing: "none" (0) 0xfcc.5-0xfcc.6 (0.2)
0x0fc0| 80 | . | discardable: false 0xfcc.7-0xfcc.7 (0.1)
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef| packet{}: (vorbis_packet) 0xfcd-0xfcd.7 (1)
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef| packet{}: (vorbis_packet) 0xfcd-0x1018.7 (76)
0x0fc0| be | . | packet_type: "Audio" (0) 0xfcd-0xfcd.7 (1)
0x0fc0| 13 a2| ..| data: raw bits 0xfce-0x1018.7 (75)
0x0fc0| 13 a2| ..| data: raw bits 0xfce-0x1018.7 (75)
0x0fd0|9b 06 0a b6 ff 13 10 ff 25 62 ec 8f d9 f7 a2 11|........%b......|
* |until 0x1018.7 (75) | |
| | | [4]{}: element 0x1019-0x10de.7 (198)
@ -432,11 +432,11 @@ $ fq -d matroska dv vorbis.mkv
| | | flags{}: 0x1028-0x1028.7 (1)
0x1020| 00 | . | reserved: 0 0x1028-0x1028.3 (0.4)
0x1020| 00 | . | invisible: false 0x1028.4-0x1028.4 (0.1)
0x1020| 00 | . | lacing: 0 0x1028.5-0x1028.6 (0.2)
0x1020| 00 | . | lacing: "none" (0) 0x1028.5-0x1028.6 (0.2)
0x1020| 00 | . | not_used: false 0x1028.7-0x1028.7 (0.1)
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef| packet{}: (vorbis_packet) 0x1029-0x1029.7 (1)
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef| packet{}: (vorbis_packet) 0x1029-0x10d7.7 (175)
0x1020| be | . | packet_type: "Audio" (0) 0x1029-0x1029.7 (1)
0x1020| a7 f2 81 46 bb c2| ...F..| data: raw bits 0x102a-0x10d7.7 (174)
0x1020| a7 f2 81 46 bb c2| ...F..| data: raw bits 0x102a-0x10d7.7 (174)
0x1030|48 52 08 27 b8 83 10 ca 08 b1 a7 f2 81 46 bb c2|HR.'.........F..|
* |until 0x10d7.7 (174) | |
| | | [1]{}: element 0x10d8-0x10de.7 (7)

View File

@ -346,7 +346,7 @@ $ fq -d matroska dv vp8.mkv
0x0220| 80 | . | key_frame: true 0x22d-0x22d (0.1)
0x0220| 80 | . | reserved: 0 0x22d.1-0x22d.3 (0.3)
0x0220| 80 | . | invisible: false 0x22d.4-0x22d.4 (0.1)
0x0220| 80 | . | lacing: 0 0x22d.5-0x22d.6 (0.2)
0x0220| 80 | . | lacing: "none" (0) 0x22d.5-0x22d.6 (0.2)
0x0220| 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{}: (vp8_frame) 0x22e-0x146f.7 (4674)
| | | tag{}: 0x22e-0x230.7 (3)

View File

@ -347,7 +347,7 @@ $ fq -d matroska dv vp9.mkv
0x0230| 80 | . | key_frame: true 0x231-0x231 (0.1)
0x0230| 80 | . | reserved: 0 0x231.1-0x231.3 (0.3)
0x0230| 80 | . | invisible: false 0x231.4-0x231.4 (0.1)
0x0230| 80 | . | lacing: 0 0x231.5-0x231.6 (0.2)
0x0230| 80 | . | lacing: "none" (0) 0x231.5-0x231.6 (0.2)
0x0230| 80 | . | discardable: false 0x231.7-0x231.7 (0.1)
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef| packet{}: (vp9_frame) 0x232-0x1769.7 (5432)
0x0230| a2 | . | frame_marker: 2 0x232-0x232.1 (0.2)

View File

@ -352,7 +352,7 @@ $ fq -d mp4 dv mpeg2.mp4
0x0030| 18 | . | constrained_parameters_flag: 0 0x37.5-0x37.5 (0.1)
0x0030| 18 | . | load_intra_quantizer_matrix: false 0x37.6-0x37.6 (0.1)
0x0030| 18 | . | load_non_intra_quantizer_matrix: false 0x37.7-0x37.7 (0.1)
0x0030| 00 00 01 b5 14 8a 00 01| ........| unknown0: raw bits 0x38-0x1fa5.7 (8046)
0x0030| 00 00 01 b5 14 8a 00 01| ........| data: raw bits 0x38-0x1fa5.7 (8046)
0x0040|00 00 00 00 01 b8 00 08 00 40 00 00 01 00 00 0f|.........@......|
* |until 0x1fa5.7 (8046) | |
| | | id: 1 0x22a9-NA (0)

View File

@ -270,7 +270,7 @@ $ fq -d mp4 dv vorbis.mp4
0x0400| 02 00 | .. | codebook_dimensions: 2 0x40d-0x40e.7 (2)
0x0400| 10| .| codebook_entries: 16 0x40f-0x411.7 (3)
0x0410|00 00 |.. |
0x0410| 84 74 9a 59 aa 01 22 cc 40 86 81 d0 90 95| .t.Y..".@.....| unknown0: raw bits 0x412-0x10b0.7 (3231)
0x0410| 84 74 9a 59 aa 01 22 cc 40 86 81 d0 90 95| .t.Y..".@.....| data: raw bits 0x412-0x10b0.7 (3231)
0x0420|00 00 02 00 00 60 84 22 0c 31 20 34 64 25 00 00|.....`.".1 4d%..|
* |until 0x10b0.7 (3231) | |
| | | sl_config_descr{}: 0x10b1-0x10b6.7 (6)
@ -369,17 +369,17 @@ $ fq -d mp4 dv vorbis.mp4
| | | samples[0:3]: 0x2c-0x1dc.7 (433)
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef| [0]{}: sample (vorbis_packet) 0x2c-0xe1.7 (182)
0x0020| be | . | packet_type: "Audio" (0) 0x2c-0x2c.7 (1)
0x0020| b7 f2 81| ...| unknown0: raw bits 0x2d-0xe1.7 (181)
0x0020| b7 f2 81| ...| data: raw bits 0x2d-0xe1.7 (181)
0x0030|46 74 15 42 0b 52 08 17 32 8e 43 08 65 84 84 f6|Ft.B.R..2.C.e...|
* |until 0xe1.7 (181) | |
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef| [1]{}: sample (vorbis_packet) 0xe2-0x12d.7 (76)
0x00e0| be | . | packet_type: "Audio" (0) 0xe2-0xe2.7 (1)
0x00e0| 13 a2 9b 06 0a b6 ff 13 10 ff 25 62 ec| ..........%b.| unknown0: raw bits 0xe3-0x12d.7 (75)
0x00e0| 13 a2 9b 06 0a b6 ff 13 10 ff 25 62 ec| ..........%b.| data: raw bits 0xe3-0x12d.7 (75)
0x00f0|8f d9 f7 a2 11 72 ca 44 3b 21 ba 69 a0 60 fb 3f|.....r.D;!.i.`.?|
* |until 0x12d.7 (75) | |
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef| [2]{}: sample (vorbis_packet) 0x12e-0x1dc.7 (175)
0x0120| be | . | packet_type: "Audio" (0) 0x12e-0x12e.7 (1)
0x0120| a7| .| unknown0: raw bits 0x12f-0x1dc.7 (174)
0x0120| a7| .| data: raw bits 0x12f-0x1dc.7 (174)
0x0130|f2 81 46 bb c2 48 52 08 27 b8 83 10 ca 08 b1 a7|..F..HR.'.......|
* |until 0x1dc.7 (174) | |
| | | id: 1 0x1189-NA (0)

View File

@ -195,9 +195,13 @@ func pesPacketDecode(d *decode.D, _ any) any {
})
})
default:
d.FieldRawLen("data", dataLen)
d.FieldRawLen("stream_data", dataLen)
}
default:
// nop
}
if d.BitsLeft() > 0 {
d.FieldRawLen("data", d.BitsLeft())
}

View File

@ -161,24 +161,24 @@ $ fq -d ogg dv vorbis.ogg
0x000| 42 43 56 | BCV | codecooke_sync: 0x564342 (valid) 0x8-0xa.7 (3)
0x000| 01 00 | .. | codebook_dimensions: 1 0xb-0xc.7 (2)
0x000| 40 00 00| @..| codebook_entries: 64 0xd-0xf.7 (3)
0x001|24 73 18 2a 46 a5 73 16 84 10 1a 42 50 19 e3 1c|$s.*F.s....BP...| unknown0: raw bits 0x10-0xc74.7 (3173)
0x001|24 73 18 2a 46 a5 73 16 84 10 1a 42 50 19 e3 1c|$s.*F.s....BP...| data: raw bits 0x10-0xc74.7 (3173)
* |until 0xc74.7 (end) (3173) | |
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef| [3]{}: packet (vorbis_packet) 0x0-0x1e.7 (31)
0x000|5c |\ | packet_type: "Audio" (0) 0x0-0x0.7 (1)
0x000| dd ab 3a ab ba b0 ff 5a 02 04 10 00 c0 8c da| ..:....Z.......| unknown0: raw bits 0x1-0x1e.7 (30)
0x000| dd ab 3a ab ba b0 ff 5a 02 04 10 00 c0 8c da| ..:....Z.......| data: raw bits 0x1-0x1e.7 (30)
0x001|2d b6 37 df 7c f3 cd 30 0c c3 30 0c c3 7a 00| |-.7.|..0..0..z.||
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef| [4]{}: packet (vorbis_packet) 0x0-0x3b.7 (60)
0x000|9a |. | packet_type: "Audio" (0) 0x0-0x0.7 (1)
0x000| d8 3d 07 6f d2 9e 5b 5c 05 66 22 40 2a 00 00| .=.o..[\.f"@*..| unknown0: raw bits 0x1-0x3b.7 (59)
0x000| d8 3d 07 6f d2 9e 5b 5c 05 66 22 40 2a 00 00| .=.o..[\.f"@*..| data: raw bits 0x1-0x3b.7 (59)
0x001|00 00 00 00 00 00 00 00 00 fa fd 60 9f ce 01 d1|...........`....|
* |until 0x3b.7 (end) (59) | |
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef| [5]{}: packet (vorbis_packet) 0x0-0x33.7 (52)
0x000|be |. | packet_type: "Audio" (0) 0x0-0x0.7 (1)
0x000| d8 dd e6 ae 92 f7 23 3e 6f cc 0d 80 7a 00 00| ......#>o...z..| unknown0: raw bits 0x1-0x33.7 (51)
0x000| d8 dd e6 ae 92 f7 23 3e 6f cc 0d 80 7a 00 00| ......#>o...z..| data: raw bits 0x1-0x33.7 (51)
0x001|00 00 01 06 00 00 00 00 00 00 e0 b9 05 42 5c 27|.............B\'|
* |until 0x33.7 (end) (51) | |
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef| [6]{}: packet (vorbis_packet) 0x0-0x7f.7 (128)
0x000|3e |> | packet_type: "Audio" (0) 0x0-0x0.7 (1)
0x000| 37 dd 37 fe ee 85 47 7c 3c 61 02 9b 31 06 f6| 7.7...G|<a..1..| unknown0: raw bits 0x1-0x7f.7 (127)
0x000| 37 dd 37 fe ee 85 47 7c 3c 61 02 9b 31 06 f6| 7.7...G|<a..1..| data: raw bits 0x1-0x7f.7 (127)
0x001|bb ef 9f 04 62 46 41 04 c0 c0 00 00 f0 3d f4 1d|....bFA......=..|
* |until 0x7f.7 (end) (127) | |

View File

@ -39,12 +39,12 @@ $ fq -d vorbis_packet dv vorbis-setup
0x000| 42 43 56 | BCV | codecooke_sync: 0x564342 (valid) 0x8-0xa.7 (3)
0x000| 01 00 | .. | codebook_dimensions: 1 0xb-0xc.7 (2)
0x000| 40 00 00| @..| codebook_entries: 64 0xd-0xf.7 (3)
0x010|24 73 18 2a 46 a5 73 16 84 10 1a 42 50 19 e3 1c|$s.*F.s....BP...| unknown0: raw bits 0x10-0xc74.7 (3173)
0x010|24 73 18 2a 46 a5 73 16 84 10 1a 42 50 19 e3 1c|$s.*F.s....BP...| data: raw bits 0x10-0xc74.7 (3173)
* |until 0xc74.7 (end) (3173) | |
# ffmpeg -f lavfi -i sine -t 10ms -f ogg pipe:1 | fq - '.packet[3] | tobits' > vorbis-audio
$ fq -d vorbis_packet dv vorbis-audio
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.{}: vorbis-audio (vorbis_packet) 0x0-0x20.7 (33)
0x00|54 |T | packet_type: "Audio" (0) 0x0-0x0.7 (1)
0x00| dd cb ce aa 5e d8 7f 2d 01 42 00 a0 dd 71 77| ....^..-.B...qw| unknown0: raw bits 0x1-0x20.7 (32)
0x00| dd cb ce aa 5e d8 7f 2d 01 42 00 a0 dd 71 77| ....^..-.B...qw| data: raw bits 0x1-0x20.7 (32)
0x10|8b ed cd 37 df 7c 33 3a 0c c3 30 0c c3 30 d4 50|...7.|3:..0..0.P|
0x20|02| |.| |

View File

@ -121,5 +121,9 @@ func vorbisDecode(d *decode.D, _ any) any {
d.FieldU1("frame_bit", d.ValidateU(1))
}
if d.BitsLeft() > 0 {
d.FieldRawLen("data", d.BitsLeft())
}
return nil
}