Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
ffmpeg
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Stefan Westerfeld
ffmpeg
Commits
4ff73add
Commit
4ff73add
authored
Jul 23, 2021
by
James Almer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avcodec/h264_sei: parse and export Film Grain Characteristics SEI messages
Signed-off-by:
James Almer
<
jamrial@gmail.com
>
parent
e3b5ff17
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
123 additions
and
0 deletions
+123
-0
h264_sei.c
libavcodec/h264_sei.c
+47
-0
h264_sei.h
libavcodec/h264_sei.h
+22
-0
h264_slice.c
libavcodec/h264_slice.c
+54
-0
No files found.
libavcodec/h264_sei.c
View file @
4ff73add
...
...
@@ -55,6 +55,7 @@ void ff_h264_sei_uninit(H264SEIContext *h)
h
->
picture_timing
.
present
=
0
;
h
->
buffering_period
.
present
=
0
;
h
->
frame_packing
.
present
=
0
;
h
->
film_grain_characteristics
.
present
=
0
;
h
->
display_orientation
.
present
=
0
;
h
->
afd
.
present
=
0
;
...
...
@@ -416,6 +417,49 @@ static int decode_alternative_transfer(H264SEIAlternativeTransfer *h,
return
0
;
}
static
int
decode_film_grain_characteristics
(
H264SEIFilmGrainCharacteristics
*
h
,
GetBitContext
*
gb
)
{
int
film_grain_characteristics_cancel_flag
=
get_bits1
(
gb
);
if
(
!
film_grain_characteristics_cancel_flag
)
{
memset
(
h
,
0
,
sizeof
(
*
h
));
h
->
model_id
=
get_bits
(
gb
,
8
);
h
->
separate_colour_description_present_flag
=
get_bits1
(
gb
);
if
(
h
->
separate_colour_description_present_flag
)
{
h
->
bit_depth_luma
=
get_bits
(
gb
,
3
)
+
8
;
h
->
bit_depth_chroma
=
get_bits
(
gb
,
3
)
+
8
;
h
->
full_range
=
get_bits1
(
gb
);
h
->
color_primaries
=
get_bits
(
gb
,
8
);
h
->
transfer_characteristics
=
get_bits
(
gb
,
8
);
h
->
matrix_coeffs
=
get_bits
(
gb
,
8
);
}
h
->
blending_mode_id
=
get_bits
(
gb
,
2
);
h
->
log2_scale_factor
=
get_bits
(
gb
,
4
);
for
(
int
c
=
0
;
c
<
3
;
c
++
)
h
->
comp_model_present_flag
[
c
]
=
get_bits1
(
gb
);
for
(
int
c
=
0
;
c
<
3
;
c
++
)
{
if
(
h
->
comp_model_present_flag
[
c
])
{
h
->
num_intensity_intervals
[
c
]
=
get_bits
(
gb
,
8
)
+
1
;
h
->
num_model_values
[
c
]
=
get_bits
(
gb
,
3
)
+
1
;
if
(
h
->
num_model_values
[
c
]
>
6
)
return
AVERROR_INVALIDDATA
;
for
(
int
i
=
0
;
i
<
h
->
num_intensity_intervals
[
c
];
i
++
)
{
h
->
intensity_interval_lower_bound
[
c
][
i
]
=
get_bits
(
gb
,
8
);
h
->
intensity_interval_upper_bound
[
c
][
i
]
=
get_bits
(
gb
,
8
);
for
(
int
j
=
0
;
j
<
h
->
num_model_values
[
c
];
j
++
)
h
->
comp_model_value
[
c
][
i
][
j
]
=
get_se_golomb_long
(
gb
);
}
}
}
h
->
repetition_period
=
get_ue_golomb_long
(
gb
);
h
->
present
=
1
;
}
return
0
;
}
int
ff_h264_sei_decode
(
H264SEIContext
*
h
,
GetBitContext
*
gb
,
const
H264ParamSets
*
ps
,
void
*
logctx
)
{
...
...
@@ -477,6 +521,9 @@ int ff_h264_sei_decode(H264SEIContext *h, GetBitContext *gb,
case
SEI_TYPE_ALTERNATIVE_TRANSFER_CHARACTERISTICS
:
ret
=
decode_alternative_transfer
(
&
h
->
alternative_transfer
,
&
gb_payload
);
break
;
case
SEI_TYPE_FILM_GRAIN_CHARACTERISTICS
:
ret
=
decode_film_grain_characteristics
(
&
h
->
film_grain_characteristics
,
&
gb_payload
);
break
;
default:
av_log
(
logctx
,
AV_LOG_DEBUG
,
"unknown SEI type %d
\n
"
,
type
);
}
...
...
libavcodec/h264_sei.h
View file @
4ff73add
...
...
@@ -165,6 +165,27 @@ typedef struct H264SEIAlternativeTransfer {
int
preferred_transfer_characteristics
;
}
H264SEIAlternativeTransfer
;
typedef
struct
H264SEIFilmGrainCharacteristics
{
int
present
;
int
model_id
;
int
separate_colour_description_present_flag
;
int
bit_depth_luma
;
int
bit_depth_chroma
;
int
full_range
;
int
color_primaries
;
int
transfer_characteristics
;
int
matrix_coeffs
;
int
blending_mode_id
;
int
log2_scale_factor
;
int
comp_model_present_flag
[
3
];
uint16_t
num_intensity_intervals
[
3
];
uint8_t
num_model_values
[
3
];
uint8_t
intensity_interval_lower_bound
[
3
][
256
];
uint8_t
intensity_interval_upper_bound
[
3
][
256
];
int16_t
comp_model_value
[
3
][
256
][
6
];
int
repetition_period
;
}
H264SEIFilmGrainCharacteristics
;
typedef
struct
H264SEIContext
{
H264SEIPictureTiming
picture_timing
;
H264SEIAFD
afd
;
...
...
@@ -176,6 +197,7 @@ typedef struct H264SEIContext {
H264SEIDisplayOrientation
display_orientation
;
H264SEIGreenMetaData
green_metadata
;
H264SEIAlternativeTransfer
alternative_transfer
;
H264SEIFilmGrainCharacteristics
film_grain_characteristics
;
}
H264SEIContext
;
struct
H264ParamSets
;
...
...
libavcodec/h264_slice.c
View file @
4ff73add
...
...
@@ -28,6 +28,7 @@
#include "libavutil/avassert.h"
#include "libavutil/display.h"
#include "libavutil/imgutils.h"
#include "libavutil/film_grain_params.h"
#include "libavutil/stereo3d.h"
#include "libavutil/timecode.h"
#include "internal.h"
...
...
@@ -1330,6 +1331,59 @@ static int h264_export_frame_props(H264Context *h)
}
h
->
sei
.
unregistered
.
nb_buf_ref
=
0
;
if
(
h
->
sei
.
film_grain_characteristics
.
present
&&
(
h
->
avctx
->
export_side_data
&
AV_CODEC_EXPORT_DATA_FILM_GRAIN
))
{
H264SEIFilmGrainCharacteristics
*
fgc
=
&
h
->
sei
.
film_grain_characteristics
;
AVFilmGrainParams
*
fgp
=
av_film_grain_params_create_side_data
(
out
);
if
(
!
fgp
)
return
AVERROR
(
ENOMEM
);
fgp
->
type
=
AV_FILM_GRAIN_PARAMS_H274
;
fgp
->
codec
.
h274
.
model_id
=
fgc
->
model_id
;
if
(
fgc
->
separate_colour_description_present_flag
)
{
fgp
->
codec
.
h274
.
bit_depth_luma
=
fgc
->
bit_depth_luma
;
fgp
->
codec
.
h274
.
bit_depth_chroma
=
fgc
->
bit_depth_chroma
;
fgp
->
codec
.
h274
.
color_range
=
fgc
->
full_range
+
1
;
fgp
->
codec
.
h274
.
color_primaries
=
fgc
->
color_primaries
;
fgp
->
codec
.
h274
.
color_trc
=
fgc
->
transfer_characteristics
;
fgp
->
codec
.
h274
.
color_space
=
fgc
->
matrix_coeffs
;
}
else
{
fgp
->
codec
.
h274
.
bit_depth_luma
=
sps
->
bit_depth_luma
;
fgp
->
codec
.
h274
.
bit_depth_chroma
=
sps
->
bit_depth_chroma
;
if
(
sps
->
video_signal_type_present_flag
)
fgp
->
codec
.
h274
.
color_range
=
sps
->
full_range
+
1
;
else
fgp
->
codec
.
h274
.
color_range
=
AVCOL_RANGE_UNSPECIFIED
;
if
(
sps
->
colour_description_present_flag
)
{
fgp
->
codec
.
h274
.
color_primaries
=
sps
->
color_primaries
;
fgp
->
codec
.
h274
.
color_trc
=
sps
->
color_trc
;
fgp
->
codec
.
h274
.
color_space
=
sps
->
colorspace
;
}
else
{
fgp
->
codec
.
h274
.
color_primaries
=
AVCOL_PRI_UNSPECIFIED
;
fgp
->
codec
.
h274
.
color_trc
=
AVCOL_TRC_UNSPECIFIED
;
fgp
->
codec
.
h274
.
color_space
=
AVCOL_SPC_UNSPECIFIED
;
}
}
fgp
->
codec
.
h274
.
blending_mode_id
=
fgc
->
blending_mode_id
;
fgp
->
codec
.
h274
.
log2_scale_factor
=
fgc
->
log2_scale_factor
;
memcpy
(
&
fgp
->
codec
.
h274
.
component_model_present
,
&
fgc
->
comp_model_present_flag
,
sizeof
(
fgp
->
codec
.
h274
.
component_model_present
));
memcpy
(
&
fgp
->
codec
.
h274
.
num_intensity_intervals
,
&
fgc
->
num_intensity_intervals
,
sizeof
(
fgp
->
codec
.
h274
.
num_intensity_intervals
));
memcpy
(
&
fgp
->
codec
.
h274
.
num_model_values
,
&
fgc
->
num_model_values
,
sizeof
(
fgp
->
codec
.
h274
.
num_model_values
));
memcpy
(
&
fgp
->
codec
.
h274
.
intensity_interval_lower_bound
,
&
fgc
->
intensity_interval_lower_bound
,
sizeof
(
fgp
->
codec
.
h274
.
intensity_interval_lower_bound
));
memcpy
(
&
fgp
->
codec
.
h274
.
intensity_interval_upper_bound
,
&
fgc
->
intensity_interval_upper_bound
,
sizeof
(
fgp
->
codec
.
h274
.
intensity_interval_upper_bound
));
memcpy
(
&
fgp
->
codec
.
h274
.
comp_model_value
,
&
fgc
->
comp_model_value
,
sizeof
(
fgp
->
codec
.
h274
.
comp_model_value
));
fgc
->
present
=
!!
fgc
->
repetition_period
;
}
if
(
h
->
sei
.
picture_timing
.
timecode_cnt
>
0
)
{
uint32_t
*
tc_sd
;
char
tcbuf
[
AV_TIMECODE_STR_SIZE
];
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment