Skip to content

Commit

Permalink
Merge pull request #1021 from wader/av1_obu_derive_more
Browse files Browse the repository at this point in the history
av1_obu: Add more derived values
  • Loading branch information
wader authored Oct 23, 2024
2 parents de43e35 + 5395330 commit 3917383
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 15 deletions.
59 changes: 44 additions & 15 deletions format/av1/av1_obu.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,7 @@ func obuDecode(d *decode.D) any {
operatingPointsCntMinus1 := d.FieldU5("operating_points_cnt_minus_1")

d.FieldArray("operating_points", func(d *decode.D) {

for i := uint64(0); i <= operatingPointsCntMinus1; i++ {

d.FieldStruct("operating_point", func(d *decode.D) {
d.FieldU12("operating_point_idc")
seqLevelIdx := d.FieldU5("seq_level_idx")
Expand All @@ -233,25 +231,24 @@ func obuDecode(d *decode.D) any {
} else {
// nop
}

})

if initialDisplayDelayPresentFlag == 1 {
initialDisplayDelayPresentForThisOp := d.FieldU1("seq_tier")
if initialDisplayDelayPresentForThisOp == 1 {
d.FieldU4("initial_display_delay_minus_1")
}
}
}

})

}

frameWidthBitsMinus1 := d.FieldU4("frame_width_bits_minus_1")
frameHeightBitsMinus1 := d.FieldU4("frame_height_bits_minus_1")
d.FieldU("max_frame_width_minus_1", int(frameWidthBitsMinus1)+1)
d.FieldU("max_frame_height_minus_1", int(frameHeightBitsMinus1)+1)
frameWidthMinus1 := d.FieldU("max_frame_width_minus_1", int(frameWidthBitsMinus1)+1)
frameHeightMinus1 := d.FieldU("max_frame_height_minus_1", int(frameHeightBitsMinus1)+1)
d.FieldValueUint("frame_width", frameWidthMinus1+1)
d.FieldValueUint("frame_height", frameHeightMinus1+1)

var frameIdNumbersPresentFlag uint64 = 0
if reducedStillPictureHeader == 1 {
Expand Down Expand Up @@ -301,33 +298,58 @@ func obuDecode(d *decode.D) any {
d.FieldU1("enable_cdef")
d.FieldU1("enable_restoration")
d.FieldStruct("color_config", func(d *decode.D) {
// https://aomediacodec.github.io/av1-spec/#color-config-syntax
highBitdepth := d.FieldU1("high_bitdepth")
var twelveBit uint64
var bitDepth uint64 = 0 // TODO: what if seqProfile > 2?
if seqProfile == 2 && highBitdepth == 1 {
twelveBit = d.FieldU1("twelve_bit")
if twelveBit == 1 {
bitDepth = 12
} else {
bitDepth = 10
}
} else if seqProfile <= 2 {
if highBitdepth == 1 {
bitDepth = 10
} else {
bitDepth = 8
}
}
var monoChrome uint64 = 0
d.FieldValueUint("bit_depth", bitDepth)

var monoChrome uint64
if seqProfile == 1 {
// nop
d.FieldValueUint("mono_chrome", 0)
monoChrome = 0
} else {
d.FieldU1("mono_chrome")
monoChrome = d.FieldU1("mono_chrome")
}
colorDescriptionPresentFlag := d.FieldU1("color_description_present_flag")

var colorPrimaries uint64 = 0
var transferCharacteristics uint64 = 0
var matrixCoefficients uint64 = 0
var colorPrimaries uint64 = CP_UNSPECIFIED
var transferCharacteristics uint64 = TC_UNSPECIFIED
var matrixCoefficients uint64 = MC_UNSPECIFIED

if colorDescriptionPresentFlag == 1 {
colorPrimaries = d.FieldU8("color_primaries", cpTypeNames)
transferCharacteristics = d.FieldU8("transfer_characteristics", tcTypeNames)
matrixCoefficients = d.FieldU8("matrix_coefficients", mcTypeNames)
} else {
d.FieldValueUint("color_primaries", transferCharacteristics, cpTypeNames)
d.FieldValueUint("transfer_characteristics", transferCharacteristics, tcTypeNames)
d.FieldValueUint("matrix_coefficients", matrixCoefficients, mcTypeNames)
}
if monoChrome == 1 {
d.FieldU1("color_range")
d.FieldValueUint("subsampling_x", 1)
d.FieldValueUint("subsampling_y", 1)
} else if colorPrimaries == CP_BT_709 &&
transferCharacteristics == TC_SRGB &&
matrixCoefficients == MC_IDENTITY {
d.FieldValueUint("color_range", 1)
d.FieldValueUint("subsampling_x", 0)
d.FieldValueUint("subsampling_y", 0)
// nop
} else {
d.FieldU1("color_range")
Expand All @@ -336,16 +358,23 @@ func obuDecode(d *decode.D) any {
if seqProfile == 0 {
subsamplingX = 1
subsamplingY = 1
d.FieldValueUint("subsampling_x", subsamplingX)
d.FieldValueUint("subsampling_y", subsamplingY)
} else if seqProfile == 1 {
// nop
d.FieldValueUint("subsampling_x", subsamplingX)
d.FieldValueUint("subsampling_y", subsamplingY)
} else {
if twelveBit == 1 {
if bitDepth == 12 {
subsamplingX = d.FieldU1("subsampling_x")
if subsamplingX == 1 {
subsamplingY = d.FieldU1("subsampling_y")
} else {
d.FieldValueUint("subsampling_y", subsamplingY)
}
} else {
subsamplingX = 1
d.FieldValueUint("subsampling_x", subsamplingX)
d.FieldValueUint("subsampling_y", subsamplingY)
}
}
if subsamplingX == 1 && subsamplingY == 1 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ $ fq -d av1_obu dv av1_obu_seq_header_film_grain_chrome_sample_pos
0x00| ab | . | frame_height_bits_minus_1: 10 0x6.2-0x6.6 (0.4)
0x00| ab bf c3 | ... | max_frame_width_minus_1: 1919 0x6.6-0x8.1 (1.3)
0x00| c3 71 | .q | max_frame_height_minus_1: 1079 0x8.1-0x9.4 (1.3)
| | | frame_width: 1920
| | | frame_height: 1080
0x00| 71 | q | frame_id_numbers_present_flag: 0 0x9.4-0x9.5 (0.1)
0x00| 71 | q | use_128x128_superblock: 0 0x9.5-0x9.6 (0.1)
0x00| 71 | q | enable_filter_intra: 0 0x9.6-0x9.7 (0.1)
Expand All @@ -41,12 +43,15 @@ $ fq -d av1_obu dv av1_obu_seq_header_film_grain_chrome_sample_pos
0x00| e6 | . | enable_restoration: 1 0xb.6-0xb.7 (0.1)
| | | color_config{}: 0xb.7-0xf.6 (3.7)
0x00| e6 | . | high_bitdepth: 0 0xb.7-0xc (0.1)
| | | bit_depth: 8
0x00| 40 | @ | mono_chrome: 0 0xc-0xc.1 (0.1)
0x00| 40 | @ | color_description_present_flag: 1 0xc.1-0xc.2 (0.1)
0x00| 40 40 | @@ | color_primaries: "bt_709" (1) 0xc.2-0xd.2 (1)
0x00| 40 40 | @@ | transfer_characteristics: "bt_709" (1) 0xd.2-0xe.2 (1)
0x00| 40 43| @C| matrix_coefficients: "bt_709" (1) 0xe.2-0xf.2 (1)
0x00| 43| C| color_range: 0 0xf.2-0xf.3 (0.1)
| | | subsampling_x: 1
| | | subsampling_y: 1
0x00| 43| C| chroma_sample_position: 0 0xf.3-0xf.5 (0.2)
0x00| 43| C| separate_uv_delta_q: 0 0xf.5-0xf.6 (0.1)
0x00| 43| C| film_grain_params_present: 1 0xf.6-0xf.7 (0.1)
Expand Down
6 changes: 6 additions & 0 deletions format/matroska/testdata/av1.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ $ fq -d matroska dv av1.mkv
0x0230| 1e | . | frame_height_bits_minus_1: 7 0x23d.2-0x23d.6 (0.4)
0x0230| 1e 7f | .. | max_frame_width_minus_1: 319 0x23d.6-0x23e.7 (1.1)
0x0230| 7f de| ..| max_frame_height_minus_1: 239 0x23e.7-0x23f.7 (1)
| | | frame_width: 320
| | | frame_height: 240
0x0230| de| .| frame_id_numbers_present_flag: 0 0x23f.7-0x240 (0.1)
0x0240|21 |! | use_128x128_superblock: 0 0x240-0x240.1 (0.1)
0x0240|21 |! | enable_filter_intra: 0 0x240.1-0x240.2 (0.1)
Expand All @@ -412,11 +414,15 @@ $ fq -d matroska dv av1.mkv
0x0240| d0 | . | enable_restoration: 1 0x242.1-0x242.2 (0.1)
| | | color_config{}: 0x242.2-0x245.6 (3.4)
0x0240| d0 | . | high_bitdepth: 0 0x242.2-0x242.3 (0.1)
| | | bit_depth: 8
| | | mono_chrome: 0
0x0240| d0 | . | color_description_present_flag: 1 0x242.3-0x242.4 (0.1)
0x0240| d0 20 | . | color_primaries: "unspecified" (2) 0x242.4-0x243.4 (1)
0x0240| 20 20 | | transfer_characteristics: "unspecified" (2) 0x243.4-0x244.4 (1)
0x0240| 20 25 | % | matrix_coefficients: "unspecified" (2) 0x244.4-0x245.4 (1)
0x0240| 25 | % | color_range: 0 0x245.4-0x245.5 (0.1)
| | | subsampling_x: 0
| | | subsampling_y: 0
0x0240| 25 | % | separate_uv_delta_q: 1 0x245.5-0x245.6 (0.1)
0x0240| 25 | % | film_grain_params_present: 0 0x245.6-0x245.7 (0.1)
0x0240| 25 | % | data: raw bits 0x245.7-0x246 (0.1)
Expand Down
12 changes: 12 additions & 0 deletions format/mp4/testdata/av1.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ $ fq -d mp4 dv av1.mp4
0x13d0| 1e | . | frame_height_bits_minus_1: 7 0x13d1.2-0x13d1.6 (0.4)
0x13d0| 1e 7f | .. | max_frame_width_minus_1: 319 0x13d1.6-0x13d2.7 (1.1)
0x13d0| 7f de | .. | max_frame_height_minus_1: 239 0x13d2.7-0x13d3.7 (1)
| | | frame_width: 320
| | | frame_height: 240
0x13d0| de | . | frame_id_numbers_present_flag: 0 0x13d3.7-0x13d4 (0.1)
0x13d0| 21 | ! | use_128x128_superblock: 0 0x13d4-0x13d4.1 (0.1)
0x13d0| 21 | ! | enable_filter_intra: 0 0x13d4.1-0x13d4.2 (0.1)
Expand All @@ -268,11 +270,15 @@ $ fq -d mp4 dv av1.mp4
0x13d0| d0 | . | enable_restoration: 1 0x13d6.1-0x13d6.2 (0.1)
| | | color_config{}: 0x13d6.2-0x13d9.6 (3.4)
0x13d0| d0 | . | high_bitdepth: 0 0x13d6.2-0x13d6.3 (0.1)
| | | bit_depth: 8
| | | mono_chrome: 0
0x13d0| d0 | . | color_description_present_flag: 1 0x13d6.3-0x13d6.4 (0.1)
0x13d0| d0 20 | . | color_primaries: "unspecified" (2) 0x13d6.4-0x13d7.4 (1)
0x13d0| 20 20 | | transfer_characteristics: "unspecified" (2) 0x13d7.4-0x13d8.4 (1)
0x13d0| 20 25 | % | matrix_coefficients: "unspecified" (2) 0x13d8.4-0x13d9.4 (1)
0x13d0| 25 | % | color_range: 0 0x13d9.4-0x13d9.5 (0.1)
| | | subsampling_x: 0
| | | subsampling_y: 0
0x13d0| 25 | % | separate_uv_delta_q: 1 0x13d9.5-0x13d9.6 (0.1)
0x13d0| 25 | % | film_grain_params_present: 0 0x13d9.6-0x13d9.7 (0.1)
0x13d0| 25 | % | data: raw bits 0x13d9.7-0x13da (0.1)
Expand Down Expand Up @@ -388,6 +394,8 @@ $ fq -d mp4 dv av1.mp4
0x0030| 1e | . | frame_height_bits_minus_1: 7 0x32.2-0x32.6 (0.4)
0x0030| 1e 7f | .. | max_frame_width_minus_1: 319 0x32.6-0x33.7 (1.1)
0x0030| 7f de | .. | max_frame_height_minus_1: 239 0x33.7-0x34.7 (1)
| | | frame_width: 320
| | | frame_height: 240
0x0030| de | . | frame_id_numbers_present_flag: 0 0x34.7-0x35 (0.1)
0x0030| 21 | ! | use_128x128_superblock: 0 0x35-0x35.1 (0.1)
0x0030| 21 | ! | enable_filter_intra: 0 0x35.1-0x35.2 (0.1)
Expand All @@ -407,11 +415,15 @@ $ fq -d mp4 dv av1.mp4
0x0030| d0 | . | enable_restoration: 1 0x37.1-0x37.2 (0.1)
| | | color_config{}: 0x37.2-0x3a.6 (3.4)
0x0030| d0 | . | high_bitdepth: 0 0x37.2-0x37.3 (0.1)
| | | bit_depth: 8
| | | mono_chrome: 0
0x0030| d0 | . | color_description_present_flag: 1 0x37.3-0x37.4 (0.1)
0x0030| d0 20 | . | color_primaries: "unspecified" (2) 0x37.4-0x38.4 (1)
0x0030| 20 20 | | transfer_characteristics: "unspecified" (2) 0x38.4-0x39.4 (1)
0x0030| 20 25 | % | matrix_coefficients: "unspecified" (2) 0x39.4-0x3a.4 (1)
0x0030| 25 | % | color_range: 0 0x3a.4-0x3a.5 (0.1)
| | | subsampling_x: 0
| | | subsampling_y: 0
0x0030| 25 | % | separate_uv_delta_q: 1 0x3a.5-0x3a.6 (0.1)
0x0030| 25 | % | film_grain_params_present: 0 0x3a.6-0x3a.7 (0.1)
0x0030| 25 | % | data: raw bits 0x3a.7-0x3b (0.1)
Expand Down

0 comments on commit 3917383

Please sign in to comment.