1
1
mirror of https://github.com/wader/fq.git synced 2024-11-23 00:57:15 +03:00

*_annexb: Refactor into avc/hevc_annexb

This commit is contained in:
Mattias Wadman 2021-08-31 23:42:41 +02:00
parent 9f55b6e619
commit 4242bf6013
12 changed files with 107 additions and 27 deletions

View File

@ -87,7 +87,7 @@ For more usage details see [usage.md](doc/usage.md).
[./formats_list.jq]: sh-start
aac_frame, adts, adts_frame, apev2, av1_ccr, av1_frame, av1_obu, avc_au, avc_dcr, avc_nalu, avc_pps, avc_sei, avc_sps, bzip2, dns, elf, exif, flac, flac_frame, flac_metadatablock, flac_picture, gif, gzip, hevc_au, hevc_dcr, hevc_nalu, icc_profile, id3v1, id3v11, id3v2, jpeg, json, matroska, mp3, mp3_frame, mp4, mpeg_annexb, mpeg_asc, mpeg_es, mpeg_pes, mpeg_pes_packet, mpeg_spu, mpeg_ts, ogg, ogg_page, opus_packet, png, protobuf, protobuf_widevine, raw, tar, tiff, vorbis_comment, vorbis_packet, vp8_frame, vp9_cfm, vp9_frame, vpx_ccr, wav, webp, xing
aac_frame, adts, adts_frame, apev2, av1_ccr, av1_frame, av1_obu, avc_annexb, avc_au, avc_dcr, avc_nalu, avc_pps, avc_sei, avc_sps, bzip2, dns, elf, exif, flac, flac_frame, flac_metadatablock, flac_picture, gif, gzip, hevc_annexb, hevc_au, hevc_dcr, hevc_nalu, icc_profile, id3v1, id3v11, id3v2, jpeg, json, matroska, mp3, mp3_frame, mp4, mpeg_asc, mpeg_es, mpeg_pes, mpeg_pes_packet, mpeg_spu, mpeg_ts, ogg, ogg_page, opus_packet, png, protobuf, protobuf_widevine, raw, tar, tiff, vorbis_comment, vorbis_packet, vp8_frame, vp9_cfm, vp9_frame, vpx_ccr, wav, webp, xing
[#]: sh-end

View File

@ -156,6 +156,7 @@ To add own functions you can use `init.fq` that will be read from
|`av1_ccr` |AV1&nbsp;Codec&nbsp;Configuration&nbsp;Record |<sub></sub>|
|`av1_frame` |AV1&nbsp;frame |<sub>`av1_obu`</sub>|
|`av1_obu` |AV1&nbsp;Open&nbsp;Bitstream&nbsp;Unit |<sub></sub>|
|`avc_annexb` |H.264/AVC&nbsp;Annex&nbsp;B |<sub>`avc_nalu`</sub>|
|`avc_au` |H.264/AVC&nbsp;Access&nbsp;Unit |<sub>`avc_nalu`</sub>|
|`avc_dcr` |H.264/AVC&nbsp;Decoder&nbsp;Configuration&nbsp;Record |<sub>`avc_nalu`</sub>|
|`avc_nalu` |H.264/AVC&nbsp;Network&nbsp;Access&nbsp;Layer&nbsp;Unit |<sub>`avc_sps` `avc_pps` `avc_sei`</sub>|
@ -172,6 +173,7 @@ To add own functions you can use `init.fq` that will be read from
|`flac_picture` |FLAC&nbsp;metadatablock&nbsp;picture |<sub>`image`</sub>|
|`gif` |Graphics&nbsp;Interchange&nbsp;Format |<sub></sub>|
|`gzip` |gzip&nbsp;compression |<sub>`probe`</sub>|
|`hevc_annexb` |H.265/HEVC&nbsp;Annex&nbsp;B |<sub>`hevc_nalu`</sub>|
|`hevc_au` |H.265/HEVC&nbsp;Access&nbsp;Unit |<sub>`hevc_nalu`</sub>|
|`hevc_dcr` |H.265/HEVC&nbsp;Decoder&nbsp;Configuration&nbsp;Record |<sub>`hevc_nalu`</sub>|
|`hevc_nalu` |H.265/HEVC&nbsp;Network&nbsp;Access&nbsp;Layer&nbsp;Unit |<sub></sub>|
@ -185,7 +187,6 @@ To add own functions you can use `init.fq` that will be read from
|`mp3` |MP3&nbsp;file |<sub>`id3v2` `id3v1` `id3v11` `apev2` `mp3_frame`</sub>|
|`mp3_frame` |MPEG&nbsp;audio&nbsp;layer&nbsp;3&nbsp;frame |<sub>`xing`</sub>|
|`mp4` |MPEG-4&nbsp;file&nbsp;and&nbsp;similar |<sub>`aac_frame` `av1_ccr` `av1_frame` `flac_frame` `flac_metadatablock` `id3v2` `image` `jpeg` `mp3_frame` `avc_au` `avc_dcr` `mpeg_es` `hevc_au` `hevc_dcr` `mpeg_pes_packet` `opus_packet` `protobuf_widevine` `vorbis_packet` `vp9_frame` `vpx_ccr`</sub>|
|`mpeg_annexb` |H.264/AVC&nbsp;Annex&nbsp;B |<sub>`avc_nalu`</sub>|
|`mpeg_asc` |MPEG-4&nbsp;Audio&nbsp;Specific&nbsp;Config |<sub></sub>|
|`mpeg_es` |MPEG&nbsp;Elementary&nbsp;Stream |<sub>`mpeg_asc` `vorbis_packet`</sub>|
|`mpeg_pes` |MPEG&nbsp;Packetized&nbsp;elementary&nbsp;stream |<sub>`mpeg_pes_packet` `mpeg_spu`</sub>|
@ -211,7 +212,7 @@ To add own functions you can use `init.fq` that will be read from
|`webp` |WebP&nbsp;image |<sub>`vp8_frame`</sub>|
|`xing` |Xing&nbsp;header |<sub></sub>|
|`image` |Group |<sub>`gif` `jpeg` `png` `tiff` `webp`</sub>|
|`probe` |Group |<sub>`adts` `bzip2` `elf` `flac` `gif` `gzip` `jpeg` `json` `matroska` `mp3` `mp4` `mpeg_annexb` `mpeg_ts` `ogg` `png` `tar` `tiff` `wav` `webp`</sub>|
|`probe` |Group |<sub>`adts` `bzip2` `elf` `flac` `gif` `gzip` `jpeg` `json` `matroska` `mp3` `mp4` `mpeg_ts` `ogg` `png` `tar` `tiff` `wav` `webp`</sub>|
[#]: sh-end

View File

@ -45,16 +45,17 @@ const (
XING = "xing"
MP4 = "mp4"
MPEG_ASC = "mpeg_asc"
AVC_ANNEXB = "avc_annexb"
AVC_DCR = "avc_dcr"
AVC_SPS = "avc_sps"
AVC_PPS = "avc_pps"
AVC_SEI = "avc_sei"
AVC_NALU = "avc_nalu"
AVC_AU = "avc_au"
HEVC_ANNEXB = "hevc_annexb"
HEVC_AU = "hevc_au"
HEVC_NALU = "hevc_nalu"
HEVC_DCR = "hevc_dcr"
MPEG_ANNEXB = "mpeg_annexb"
MPEG_ES = "mpeg_es"
MPEG_PES = "mpeg_pes"
MPEG_PES_PACKET = "mpeg_pes_packet"

View File

@ -1,25 +1,9 @@
package mpeg
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
)
var annexBAVCNALUFormat []*decode.Format
func init() {
registry.MustRegister(&decode.Format{
Name: format.MPEG_ANNEXB,
Description: "H.264/AVC Annex B",
Groups: []string{format.PROBE},
DecodeFn: annexBDecode,
Dependencies: []decode.Dependency{
{Names: []string{format.AVC_NALU}, Formats: &annexBAVCNALUFormat},
},
})
}
func annexBFindStartCode(d *decode.D) (int64, int64, error) {
offset, v, err := d.TryPeekFind(32, 8, func(v uint64) bool {
return annexBDecodeStartCodeLen(v) > 0
@ -38,7 +22,7 @@ func annexBDecodeStartCodeLen(v uint64) int64 {
}
}
func annexBDecode(d *decode.D, in interface{}) interface{} {
func annexBDecode(d *decode.D, _ interface{}, format []*decode.Format) interface{} {
currentOffset, currentPrefixLen, err := annexBFindStartCode(d)
// TODO: really restrict to 0?
if err != nil || currentOffset != 0 {
@ -56,7 +40,7 @@ func annexBDecode(d *decode.D, in interface{}) interface{} {
}
naluLen := nextOffset
d.FieldFormatLen("nalu", naluLen, avcNALUFormat)
d.FieldFormatLen("nalu", naluLen, format)
currentPrefixLen = nextPrefixLen
}

22
format/mpeg/avc_annexb.go Normal file
View File

@ -0,0 +1,22 @@
package mpeg
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
)
var annexBAVCNALUFormat []*decode.Format
func init() {
registry.MustRegister(&decode.Format{
Name: format.AVC_ANNEXB,
Description: "H.264/AVC Annex B",
DecodeFn: func(d *decode.D, in interface{}) interface{} {
return annexBDecode(d, in, annexBAVCNALUFormat)
},
Dependencies: []decode.Dependency{
{Names: []string{format.AVC_NALU}, Formats: &annexBAVCNALUFormat},
},
})
}

View File

@ -0,0 +1,22 @@
package mpeg
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
)
var annexBHEVCNALUFormat []*decode.Format
func init() {
registry.MustRegister(&decode.Format{
Name: format.HEVC_ANNEXB,
Description: "H.265/HEVC Annex B",
DecodeFn: func(d *decode.D, in interface{}) interface{} {
return annexBDecode(d, in, annexBHEVCNALUFormat)
},
Dependencies: []decode.Dependency{
{Names: []string{format.HEVC_NALU}, Formats: &annexBHEVCNALUFormat},
},
})
}

View File

@ -1,7 +1,7 @@
# ffmpeg -y -f lavfi -i testsrc -t 10ms -f h264 mpeg_annexb.h264
/mpeg_annexb.h264:
$ fq -d mpeg_annexb verbose /mpeg_annexb.h264
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f| |.: {} /mpeg_annexb.h264 (mpeg_annexb) 0x0-0xae4.7 (2789)
# ffmpeg -y -f lavfi -i testsrc -t 10ms -f h264 avc_annexb
/avc_annexb:
$ fq -d avc_annexb verbose /avc_annexb
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f| |.: {} /avc_annexb (avc_annexb) 0x0-0xae4.7 (2789)
| | | nalus: [8] 0x0-0xae4.7 (2789)
0x0000|00 00 00 01 |.... | [0]: start_code 00000001 0x0-0x3.7 (4)
| | | [1]: nalu {} (avc_nalu) 0x4-0x1c.7 (25)

BIN
format/mpeg/testdata/hevc_annexb vendored Normal file

Binary file not shown.

48
format/mpeg/testdata/hevc_annexb.fqtest vendored Normal file
View File

@ -0,0 +1,48 @@
# ffmpeg -y -f lavfi -i testsrc -t 10ms -f hevc hevc_annexb
/hevc_annexb:
$ fq -d hevc_annexb verbose /hevc_annexb
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f| |.: {} /hevc_annexb (hevc_annexb) 0x0-0x1193.7 (4500)
| | | nalus: [10] 0x0-0x1193.7 (4500)
0x0000|00 00 00 01 |.... | [0]: start_code 00000001 0x0-0x3.7 (4)
| | | [1]: nalu {} (hevc_nalu) 0x4-0x1a.7 (23)
0x0000| 40 | @ | forbidden_zero_bit: false 0x4-0x4 (0.1)
0x0000| 40 | @ | nal_unit_type: VPS_NUT (32) 0x4.1-0x4.6 (0.6)
0x0000| 40 01 | @. | nuh_layer_id: 0 0x4.7-0x5.4 (0.6)
0x0000| 01 | . | nuh_temporal_id_plus1: 1 0x5.5-0x5.7 (0.3)
0x0000| 0c 01 ff ff 04 08 00 00 03 00| ..........| data: 0c01ffff0408000003009e0800000300... 0x6-0x1a.7 (21)
0x0010|9e 08 00 00 03 00 00 3c 95 98 09 |.......<... |
0x0010| 00 00 00 01 | .... | [2]: start_code 00000001 0x1b-0x1e.7 (4)
| | | [3]: nalu {} (hevc_nalu) 0x1f-0x49.7 (43)
0x0010| 42| B| forbidden_zero_bit: false 0x1f-0x1f (0.1)
0x0010| 42| B| nal_unit_type: SPS_NUT (33) 0x1f.1-0x1f.6 (0.6)
0x0010| 42| B| nuh_layer_id: 0 0x1f.7-0x20.4 (0.6)
0x0020|01 |. |
0x0020|01 |. | nuh_temporal_id_plus1: 1 0x20.5-0x20.7 (0.3)
0x0020| 01 04 08 00 00 03 00 9e 08 00 00 03 00 00 3c| ..............<| data: 010408000003009e0800000300003c90... 0x21-0x49.7 (41)
0x0030|90 01 41 01 e2 cb 2b 34 92 65 78 0b 70 20 20 00|..A...+4.ex.p .|
0x0040|40 00 00 03 00 40 00 00 06 42 |@....@...B |
0x0040| 00 00 00 01 | .... | [4]: start_code 00000001 0x4a-0x4d.7 (4)
| | | [5]: nalu {} (hevc_nalu) 0x4e-0x55.7 (8)
0x0040| 44 | D | forbidden_zero_bit: false 0x4e-0x4e (0.1)
0x0040| 44 | D | nal_unit_type: PPS_NUT (34) 0x4e.1-0x4e.6 (0.6)
0x0040| 44 01| D.| nuh_layer_id: 0 0x4e.7-0x4f.4 (0.6)
0x0040| 01| .| nuh_temporal_id_plus1: 1 0x4f.5-0x4f.7 (0.3)
0x0050|c1 72 86 0c 46 24 |.r..F$ | data: c172860c4624 0x50-0x55.7 (6)
0x0050| 00 00 01 | ... | [6]: start_code 000001 0x56-0x58.7 (3)
| | | [7]: nalu {} (hevc_nalu) 0x59-0x93f.7 (2279)
0x0050| 4e | N | forbidden_zero_bit: false 0x59-0x59 (0.1)
0x0050| 4e | N | nal_unit_type: PREFIX_SEI_NUT (39) 0x59.1-0x59.6 (0.6)
0x0050| 4e 01 | N. | nuh_layer_id: 0 0x59.7-0x5a.4 (0.6)
0x0050| 01 | . | nuh_temporal_id_plus1: 1 0x5a.5-0x5a.7 (0.3)
0x0050| 05 ff ff ff ff| .....| data: 05ffffffffffffffffe22ca2de09b517... 0x5b-0x93f.7 (2277)
0x0060|ff ff ff ff e2 2c a2 de 09 b5 17 47 db bb 55 a4|.....,.....G..U.|
* |until 0x93f.7 (2277) | |
0x0940|00 00 01 |... | [8]: start_code 000001 0x940-0x942.7 (3)
| | | [9]: nalu {} (hevc_nalu) 0x943-0x1193.7 (2129)
0x0940| 28 | ( | forbidden_zero_bit: false 0x943-0x943 (0.1)
0x0940| 28 | ( | nal_unit_type: IDR_N_LP (20) 0x943.1-0x943.6 (0.6)
0x0940| 28 01 | (. | nuh_layer_id: 0 0x943.7-0x944.4 (0.6)
0x0940| 01 | . | nuh_temporal_id_plus1: 1 0x944.5-0x944.7 (0.3)
0x0940| af 1d 20 aa 55 b7 88 a0 62 7f ff| .. .U...b..| data: af1d20aa55b788a0627ffffa2c46fda9... 0x945-0x1193.7 (2127)
0x0950|fa 2c 46 fd a9 78 83 ff fb 75 6c 0b 3f ff 94 ce|.,F..x...ul.?...|
* |until 0x1193.7 (end) (2127) | |

View File

@ -76,6 +76,7 @@ apev2 APEv2 metadata tag
av1_ccr AV1 Codec Configuration Record
av1_frame AV1 frame
av1_obu AV1 Open Bitstream Unit
avc_annexb H.264/AVC Annex B
avc_au H.264/AVC Access Unit
avc_dcr H.264/AVC Decoder Configuration Record
avc_nalu H.264/AVC Network Access Layer Unit
@ -92,6 +93,7 @@ flac_metadatablock FLAC metadatablock
flac_picture FLAC metadatablock picture
gif Graphics Interchange Format
gzip gzip compression
hevc_annexb H.265/HEVC Annex B
hevc_au H.265/HEVC Access Unit
hevc_dcr H.265/HEVC Decoder Configuration Record
hevc_nalu H.265/HEVC Network Access Layer Unit
@ -105,7 +107,6 @@ matroska Matroska file
mp3 MP3 file
mp3_frame MPEG audio layer 3 frame
mp4 MPEG-4 file and similar
mpeg_annexb H.264/AVC Annex B
mpeg_asc MPEG-4 Audio Specific Config
mpeg_es MPEG Elementary Stream
mpeg_pes MPEG Packetized elementary stream

View File

@ -2,6 +2,7 @@
$ fq -i
null> he\t
help
hevc_annexb
hevc_au
hevc_dcr
hevc_nalu