Skip to content

Commit

Permalink
avcodec/h264_metadata_bsf: Allow zeroing constraint_set4_flag and con…
Browse files Browse the repository at this point in the history
…straint_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>
  • Loading branch information
dwbuiten committed Jun 29, 2021
1 parent b74beba commit d70dde2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions doc/bitstream_filters.texi
Original file line number Diff line number Diff line change
Expand Up @@ -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
meaning is dependent on interlacing and the picture structure (see
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_right
Expand Down
8 changes: 8 additions & 0 deletions libavcodec/h264_metadata_bsf.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ typedef struct H264MetadataContext {

AVRational tick_rate;
int fixed_frame_rate_flag;
int zero_new_constraint_set_flags;

int crop_left;
int crop_right;
Expand Down Expand Up @@ -228,6 +229,10 @@ static int h264_metadata_update_sps(AVBSFContext *bsf,
need_vui = 1;
}
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) {
crop_unit_x = 1;
Expand Down Expand Up @@ -618,6 +623,9 @@ static const AVOption h264_metadata_options[] = {
{ "fixed_frame_rate_flag", "Set VUI fixed frame rate flag",
OFFSET(fixed_frame_rate_flag), AV_OPT_TYPE_INT,
{ .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",
OFFSET(crop_left), AV_OPT_TYPE_INT,
Expand Down
2 changes: 1 addition & 1 deletion libavcodec/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "libavutil/version.h"

#define LIBAVCODEC_VERSION_MAJOR 59
#define LIBAVCODEC_VERSION_MINOR 2
#define LIBAVCODEC_VERSION_MINOR 3
#define LIBAVCODEC_VERSION_MICRO 100

#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
Expand Down

0 comments on commit d70dde2

Please sign in to comment.