93 int primary_pic_type_mask = 0xff;
96 static const int primary_pic_type_table[] = {
112 if (!(primary_pic_type_table[j] &
114 primary_pic_type_mask &= ~(1 << j);
119 if (primary_pic_type_mask & (1 << j))
123 "invalid slice types?\n");
129 .primary_pic_type = j,
147 int crop_unit_x, crop_unit_y;
149 if (
ctx->sample_aspect_ratio.num &&
ctx->sample_aspect_ratio.den) {
153 ctx->sample_aspect_ratio.den, 65535);
161 sps->vui.aspect_ratio_idc = 255;
162 sps->vui.sar_width = num;
163 sps->vui.sar_height = den;
165 sps->vui.aspect_ratio_idc =
i;
167 sps->vui.aspect_ratio_info_present_flag = 1;
171#define SET_VUI_FIELD(field) do { \
172 if (ctx->field >= 0) { \
173 sps->vui.field = ctx->field; \
178 if (
ctx->overscan_appropriate_flag >= 0) {
180 sps->vui.overscan_info_present_flag = 1;
183 if (
ctx->video_format >= 0 ||
184 ctx->video_full_range_flag >= 0 ||
185 ctx->colour_primaries >= 0 ||
186 ctx->transfer_characteristics >= 0 ||
187 ctx->matrix_coefficients >= 0) {
193 if (
ctx->colour_primaries >= 0 ||
194 ctx->transfer_characteristics >= 0 ||
195 ctx->matrix_coefficients >= 0) {
201 sps->vui.colour_description_present_flag = 1;
203 sps->vui.video_signal_type_present_flag = 1;
206 if (
ctx->chroma_sample_loc_type >= 0) {
207 sps->vui.chroma_sample_loc_type_top_field =
208 ctx->chroma_sample_loc_type;
209 sps->vui.chroma_sample_loc_type_bottom_field =
210 ctx->chroma_sample_loc_type;
211 sps->vui.chroma_loc_info_present_flag = 1;
215 if (
ctx->tick_rate.num &&
ctx->tick_rate.den) {
219 UINT32_MAX > INT_MAX ? UINT32_MAX : INT_MAX);
221 sps->vui.time_scale = num;
222 sps->vui.num_units_in_tick = den;
224 sps->vui.timing_info_present_flag = 1;
228 if (
ctx->zero_new_constraint_set_flags) {
229 sps->constraint_set4_flag = 0;
230 sps->constraint_set5_flag = 0;
233 if (
sps->separate_colour_plane_flag ||
sps->chroma_format_idc == 0) {
235 crop_unit_y = 2 -
sps->frame_mbs_only_flag;
237 crop_unit_x = 1 + (
sps->chroma_format_idc < 3);
238 crop_unit_y = (1 + (
sps->chroma_format_idc < 2)) *
239 (2 -
sps->frame_mbs_only_flag);
241#define CROP(border, unit) do { \
242 if (ctx->crop_ ## border >= 0) { \
243 if (ctx->crop_ ## border % unit != 0) { \
244 av_log(bsf, AV_LOG_ERROR, "Invalid value for crop_%s: " \
245 "must be a multiple of %d.\n", #border, unit); \
246 return AVERROR(EINVAL); \
248 sps->frame_crop_ ## border ## _offset = \
249 ctx->crop_ ## border / unit; \
250 sps->frame_cropping_flag = 1; \
254 CROP(right, crop_unit_x);
255 CROP(top, crop_unit_y);
256 CROP(bottom, crop_unit_y);
268 if (
sps->vui.nal_hrd_parameters_present_flag) {
269 bit_rate = (
sps->vui.nal_hrd_parameters.bit_rate_value_minus1[0] + 1) *
270 (INT64_C(1) << (
sps->vui.nal_hrd_parameters.bit_rate_scale + 6));
271 }
else if (
sps->vui.vcl_hrd_parameters_present_flag) {
272 bit_rate = (
sps->vui.vcl_hrd_parameters.bit_rate_value_minus1[0] + 1) *
273 (INT64_C(1) << (
sps->vui.vcl_hrd_parameters.bit_rate_scale + 6));
275 bit_rate = bit_rate * 6 / 5;
284 width = 16 * (
sps->pic_width_in_mbs_minus1 + 1);
285 height = 16 * (
sps->pic_height_in_map_units_minus1 + 1) *
286 (2 -
sps->frame_mbs_only_flag);
288 if (
sps->vui.timing_info_present_flag)
299 "conform to any level: using level 6.2.\n");
307 if (
sps->profile_idc == 66 ||
308 sps->profile_idc == 77 ||
309 sps->profile_idc == 88) {
311 sps->constraint_set3_flag = 1;
321 sps->vui_parameters_present_flag = 1;
368 "displaymatrix side data to packet.\n");
382 &
ctx->display_orientation_payload;
392 double scale_x, scale_y, angle;
396 for (
i = 0;
i < 9;
i++)
400 scale_x =
hypot(dmatrix[0], dmatrix[3]);
401 scale_y =
hypot(dmatrix[1], dmatrix[4]);
404 hflip = dmatrix[0] < 0.0;
405 vflip = dmatrix[4] < 0.0;
412 for (
i = 0;
i < 9;
i += 3) {
413 dmatrix[
i] /= scale_x;
414 dmatrix[
i + 1] /= scale_y;
418 angle = atan2(dmatrix[3], dmatrix[0]);
420 if (!(angle >= -
M_PI && angle <=
M_PI) ||
424 "representable in H.264 parameters.\n");
429 (uint16_t)
rint((angle >= 0.0 ? angle
430 : angle + 2 *
M_PI) *
439 (uint16_t)
rint((
ctx->rotate >= 0.0 ?
ctx->rotate
440 :
ctx->rotate + 360.0) *
459 "SEI message to access unit.\n");
472 int err,
i, has_sps, seek_point;
477 ff_cbs_delete_unit(au,
i);
503 seek_point = !
ctx->done_first_au || has_sps ||
509 if (
ctx->sei_user_data && seek_point) {
512 &
ctx->sei_user_data_payload,
NULL);
515 "message to access unit.\n");
520 if (
ctx->delete_filler) {
523 ff_cbs_delete_unit(au,
i);
540 ctx->done_first_au = 1;
547 .fragment_name =
"access unit",
548 .unit_name =
"NAL unit",
556 if (
ctx->sei_user_data) {
562 for (
i = j = 0; j < 32 &&
i < 64 &&
ctx->sei_user_data[
i];
i++) {
564 c =
ctx->sei_user_data[
i];
569 v = (
c <=
'9' ?
c -
'0' :
c -
'a' + 10);
579 if (j == 32 &&
ctx->sei_user_data[
i] ==
'+') {
580 udu->
data = (uint8_t*)
ctx->sei_user_data +
i + 1;
584 "must be \"UUID+string\".\n");
592#define OFFSET(x) offsetof(H264MetadataContext, x)
593#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_BSF_PARAM)
598 {
"sample_aspect_ratio",
"Set sample aspect ratio (table E-1)",
600 { .dbl = 0.0 }, 0, 65535,
FLAGS },
602 {
"overscan_appropriate_flag",
"Set VUI overscan appropriate flag",
604 { .i64 = -1 }, -1, 1,
FLAGS },
606 {
"video_format",
"Set video format (table E-2)",
608 { .i64 = -1 }, -1, 7,
FLAGS},
609 {
"video_full_range_flag",
"Set video full range flag",
611 { .i64 = -1 }, -1, 1,
FLAGS },
612 {
"colour_primaries",
"Set colour primaries (table E-3)",
614 { .i64 = -1 }, -1, 255,
FLAGS },
615 {
"transfer_characteristics",
"Set transfer characteristics (table E-4)",
617 { .i64 = -1 }, -1, 255,
FLAGS },
618 {
"matrix_coefficients",
"Set matrix coefficients (table E-5)",
620 { .i64 = -1 }, -1, 255,
FLAGS },
622 {
"chroma_sample_loc_type",
"Set chroma sample location type (figure E-1)",
624 { .i64 = -1 }, -1, 5,
FLAGS },
626 {
"tick_rate",
"Set VUI tick rate (time_scale / num_units_in_tick)",
628 { .dbl = 0.0 }, 0, UINT_MAX,
FLAGS },
629 {
"fixed_frame_rate_flag",
"Set VUI fixed frame rate flag",
631 { .i64 = -1 }, -1, 1,
FLAGS },
632 {
"zero_new_constraint_set_flags",
"Set constraint_set4_flag / constraint_set5_flag to zero",
634 { .i64 = 0 }, 0, 1,
FLAGS },
636 {
"crop_left",
"Set left border crop offset",
639 {
"crop_right",
"Set right border crop offset",
642 {
"crop_top",
"Set top border crop offset",
645 {
"crop_bottom",
"Set bottom border crop offset",
649 {
"sei_user_data",
"Insert SEI user data (UUID+string)",
652 {
"delete_filler",
"Delete all filler (both NAL and SEI)",
656 "Display orientation SEI",
657 display_orientation,
FLAGS),
659 {
"rotate",
"Set rotation in display orientation SEI (anticlockwise angle in degrees)",
661 { .dbl =
NAN }, -360.0, +360.0,
FLAGS },
662 {
"flip",
"Set flip in display orientation SEI",
665 {
"horizontal",
"Set hor_flip",
668 {
"vertical",
"Set ver_flip",
672 {
"level",
"Set level (table A-1)",
675 {
"auto",
"Attempt to guess level from stream properties",
678#define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
679 { .i64 = value }, .flags = FLAGS, .unit = "level"
682 {
LEVEL(
"1.1", 11) },
683 {
LEVEL(
"1.2", 12) },
684 {
LEVEL(
"1.3", 13) },
686 {
LEVEL(
"2.1", 21) },
687 {
LEVEL(
"2.2", 22) },
689 {
LEVEL(
"3.1", 31) },
690 {
LEVEL(
"3.2", 32) },
692 {
LEVEL(
"4.1", 41) },
693 {
LEVEL(
"4.2", 42) },
695 {
LEVEL(
"5.1", 51) },
696 {
LEVEL(
"5.2", 52) },
698 {
LEVEL(
"6.1", 61) },
699 {
LEVEL(
"6.2", 62) },
706 .class_name =
"h264_metadata_bsf",
717 .p.name =
"h264_metadata",
static av_cold void close(AVCodecParserContext *s)
const FFBitStreamFilter ff_h264_metadata_bsf
static int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
int ff_cbs_bsf_generic_filter(AVBSFContext *bsf, AVPacket *pkt)
Filter operation for CBS BSF.
av_cold void ff_cbs_bsf_generic_close(AVBSFContext *bsf)
Close a generic CBS BSF instance.
av_cold int ff_cbs_bsf_generic_init(AVBSFContext *bsf, const CBSBSFType *type)
Initialise generic CBS BSF setup.
#define BSF_ELEMENT_OPTIONS_PIR(name, help, field, opt_flags)
#define BSF_ELEMENT_OPTIONS_PIRE(name, help, field, opt_flags)
#define i(width, name, range_min, range_max)
static int FUNC aud(CodedBitstreamContext *ctx, RWContext *rw, H264RawAUD *current)
static int FUNC sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
void ff_cbs_sei_delete_message_type(CodedBitstreamContext *ctx, CodedBitstreamFragment *au, uint32_t payload_type)
Delete all messages with the given payload type from an access unit.
int ff_cbs_sei_add_message(CodedBitstreamContext *ctx, CodedBitstreamFragment *au, int prefix, uint32_t payload_type, void *payload_data, void *payload_ref)
Add an SEI message to an access unit.
int ff_cbs_sei_find_message(CodedBitstreamContext *ctx, CodedBitstreamFragment *au, uint32_t payload_type, SEIRawMessage **iter)
Iterate over messages with the given payload type in an access unit.
common internal and external API header
int(* init)(AVBSFContext *ctx)
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_RATIONAL
Underlying C type is AVRational.
@ AV_OPT_TYPE_FLAGS
Underlying C type is unsigned int.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_DOUBLE
Underlying C type is double.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
AVCodecID
Identify the syntax and semantics of the bitstream.
@ AV_PKT_DATA_DISPLAYMATRIX
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
int av_packet_add_side_data(AVPacket *pkt, enum AVPacketSideDataType type, uint8_t *data, size_t size)
Wrap an existing array as a packet side data.
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
Get side information from packet.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
static av_const int av_tolower(int c)
Locale-independent conversion of ASCII characters to lowercase.
static av_const int av_isxdigit(int c)
Locale-independent conversion of ASCII isxdigit.
#define LIBAVUTIL_VERSION_INT
void av_display_rotation_set(int32_t matrix[9], double angle)
Initialize a transformation matrix describing a pure clockwise rotation by the specified angle (in de...
void av_display_matrix_flip(int32_t matrix[9], int hflip, int vflip)
Flip the input matrix horizontally and/or vertically.
const AVRational ff_h2645_pixel_aspect[]
H.264 common definitions.
const H264LevelDescriptor * ff_h264_guess_level(int profile_idc, int64_t bitrate, int framerate, int width, int height, int max_dec_frame_buffering)
Guess the level of a stream from some parameters.
static void flip(AVCodecContext *avctx, AVFrame *frame)
static const struct TransferCharacteristics transfer_characteristics[]
static av_const double hypot(double x, double y)
Memory handling functions.
@ SEI_TYPE_FILLER_PAYLOAD
@ SEI_TYPE_DISPLAY_ORIENTATION
@ SEI_TYPE_USER_DATA_UNREGISTERED
#define FF_ARRAY_ELEMS(a)
The bitstream filter state.
void * priv_data
Opaque filter-specific private data.
Describe the class of an AVClass context structure.
This structure stores compressed data.
Rational number (pair of numerator and denominator).
Coded bitstream fragment structure, combining one or more units.
CodedBitstreamUnit * units
Pointer to an array of units of length nb_units_allocated.
int nb_units
Number of units in this fragment.
void * content
Pointer to the decomposed form of this unit.
CodedBitstreamUnitType type
Codec-specific type of this unit.
SEIRawUserDataUnregistered sei_user_data_payload
int video_full_range_flag
H264RawSEIDisplayOrientation display_orientation_payload
int chroma_sample_loc_type
const char * sei_user_data
int transfer_characteristics
int overscan_appropriate_flag
int fixed_frame_rate_flag
AVRational sample_aspect_ratio
int zero_new_constraint_set_flags
uint16_t anticlockwise_rotation
uint16_t display_orientation_repetition_period
H264RawSliceHeader header
uint8_t uuid_iso_iec_11578[16]
void(* filter)(uint8_t *src, ptrdiff_t stride, int qscale)
static AVFormatContext * ctx
static void rotate(const float rot_quaternion[2][4], float *vec)
Rotate vector with given rotation quaternion.