avcodec/h264_metadata_bsf: Allow zeroing constraint_set4_flag and constraint_set5_flag

These bits are reserved in earlier versions of the H.264 spec, and
some poor hardware decoders require they are zero. Thus, it is useful
to be able to zero these on streams that may have them set. The result
is still a valid H.264 bitstream.

Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
This commit is contained in:
Derek Buitenhuis 2021-06-23 17:12:43 +01:00
parent b74beba9a9
commit d70dde2712
3 changed files with 14 additions and 1 deletions

View File

@ -253,6 +253,11 @@ Set whether the stream has fixed framerate - typically this indicates
that the framerate is exactly half the tick rate, but the exact that the framerate is exactly half the tick rate, but the exact
meaning is dependent on interlacing and the picture structure (see meaning is dependent on interlacing and the picture structure (see
H.264 section E.2.1 and table E-6). H.264 section E.2.1 and table E-6).
@item zero_new_constraint_set_flags
Zero constraint_set4_flag and constraint_set5_flag in the SPS. These
bits were reserved in a previous version of the H.264 spec, and thus
some hardware decoders require these to be zero. The result of zeroing
this is still a valid bitstream.
@item crop_left @item crop_left
@item crop_right @item crop_right

View File

@ -61,6 +61,7 @@ typedef struct H264MetadataContext {
AVRational tick_rate; AVRational tick_rate;
int fixed_frame_rate_flag; int fixed_frame_rate_flag;
int zero_new_constraint_set_flags;
int crop_left; int crop_left;
int crop_right; int crop_right;
@ -228,6 +229,10 @@ static int h264_metadata_update_sps(AVBSFContext *bsf,
need_vui = 1; need_vui = 1;
} }
SET_VUI_FIELD(fixed_frame_rate_flag); SET_VUI_FIELD(fixed_frame_rate_flag);
if (ctx->zero_new_constraint_set_flags) {
sps->constraint_set4_flag = 0;
sps->constraint_set5_flag = 0;
}
if (sps->separate_colour_plane_flag || sps->chroma_format_idc == 0) { if (sps->separate_colour_plane_flag || sps->chroma_format_idc == 0) {
crop_unit_x = 1; crop_unit_x = 1;
@ -618,6 +623,9 @@ static const AVOption h264_metadata_options[] = {
{ "fixed_frame_rate_flag", "Set VUI fixed frame rate flag", { "fixed_frame_rate_flag", "Set VUI fixed frame rate flag",
OFFSET(fixed_frame_rate_flag), AV_OPT_TYPE_INT, OFFSET(fixed_frame_rate_flag), AV_OPT_TYPE_INT,
{ .i64 = -1 }, -1, 1, FLAGS }, { .i64 = -1 }, -1, 1, FLAGS },
{ "zero_new_constraint_set_flags", "Set constraint_set4_flag / constraint_set5_flag to zero",
OFFSET(zero_new_constraint_set_flags), AV_OPT_TYPE_BOOL,
{ .i64 = 0 }, 0, 1, FLAGS },
{ "crop_left", "Set left border crop offset", { "crop_left", "Set left border crop offset",
OFFSET(crop_left), AV_OPT_TYPE_INT, OFFSET(crop_left), AV_OPT_TYPE_INT,

View File

@ -28,7 +28,7 @@
#include "libavutil/version.h" #include "libavutil/version.h"
#define LIBAVCODEC_VERSION_MAJOR 59 #define LIBAVCODEC_VERSION_MAJOR 59
#define LIBAVCODEC_VERSION_MINOR 2 #define LIBAVCODEC_VERSION_MINOR 3
#define LIBAVCODEC_VERSION_MICRO 100 #define LIBAVCODEC_VERSION_MICRO 100
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \