88 int primary_pic_type_mask = 0xff;
91 static const int primary_pic_type_table[] = {
107 if (!(primary_pic_type_table[j] &
109 primary_pic_type_mask &= ~(1 << j);
114 if (primary_pic_type_mask & (1 << j))
118 "invalid slice types?\n");
124 .primary_pic_type = j,
142 int crop_unit_x, crop_unit_y;
144 if (
ctx->sample_aspect_ratio.num &&
ctx->sample_aspect_ratio.den) {
148 { 1, 1 }, { 12, 11 }, { 10, 11 }, { 16, 11 },
149 { 40, 33 }, { 24, 11 }, { 20, 11 }, { 32, 11 },
150 { 80, 33 }, { 18, 11 }, { 15, 11 }, { 64, 33 },
151 { 160, 99 }, { 4, 3 }, { 3, 2 }, { 2, 1 },
156 ctx->sample_aspect_ratio.den, 65535);
159 if (num == sar_idc[
i].num &&
160 den == sar_idc[
i].den)
164 sps->vui.aspect_ratio_idc = 255;
165 sps->vui.sar_width = num;
166 sps->vui.sar_height = den;
168 sps->vui.aspect_ratio_idc =
i;
170 sps->vui.aspect_ratio_info_present_flag = 1;
174 #define SET_VUI_FIELD(field) do { \
175 if (ctx->field >= 0) { \
176 sps->vui.field = ctx->field; \
181 if (
ctx->overscan_appropriate_flag >= 0) {
183 sps->vui.overscan_info_present_flag = 1;
186 if (
ctx->video_format >= 0 ||
187 ctx->video_full_range_flag >= 0 ||
188 ctx->colour_primaries >= 0 ||
189 ctx->transfer_characteristics >= 0 ||
190 ctx->matrix_coefficients >= 0) {
196 if (
ctx->colour_primaries >= 0 ||
197 ctx->transfer_characteristics >= 0 ||
198 ctx->matrix_coefficients >= 0) {
204 sps->vui.colour_description_present_flag = 1;
206 sps->vui.video_signal_type_present_flag = 1;
209 if (
ctx->chroma_sample_loc_type >= 0) {
210 sps->vui.chroma_sample_loc_type_top_field =
211 ctx->chroma_sample_loc_type;
212 sps->vui.chroma_sample_loc_type_bottom_field =
213 ctx->chroma_sample_loc_type;
214 sps->vui.chroma_loc_info_present_flag = 1;
218 if (
ctx->tick_rate.num &&
ctx->tick_rate.den) {
222 UINT32_MAX > INT_MAX ? UINT32_MAX : INT_MAX);
224 sps->vui.time_scale = num;
225 sps->vui.num_units_in_tick = den;
227 sps->vui.timing_info_present_flag = 1;
232 if (
sps->separate_colour_plane_flag ||
sps->chroma_format_idc == 0) {
234 crop_unit_y = 2 -
sps->frame_mbs_only_flag;
236 crop_unit_x = 1 + (
sps->chroma_format_idc < 3);
237 crop_unit_y = (1 + (
sps->chroma_format_idc < 2)) *
238 (2 -
sps->frame_mbs_only_flag);
240 #define CROP(border, unit) do { \
241 if (ctx->crop_ ## border >= 0) { \
242 if (ctx->crop_ ## border % unit != 0) { \
243 av_log(bsf, AV_LOG_ERROR, "Invalid value for crop_%s: " \
244 "must be a multiple of %d.\n", #border, unit); \
245 return AVERROR(EINVAL); \
247 sps->frame_crop_ ## border ## _offset = \
248 ctx->crop_ ## border / unit; \
249 sps->frame_cropping_flag = 1; \
252 CROP(left, crop_unit_x);
253 CROP(right, crop_unit_x);
254 CROP(top, crop_unit_y);
255 CROP(bottom, crop_unit_y);
267 if (
sps->vui.nal_hrd_parameters_present_flag) {
268 bit_rate = (
sps->vui.nal_hrd_parameters.bit_rate_value_minus1[0] + 1) *
269 (INT64_C(1) << (
sps->vui.nal_hrd_parameters.bit_rate_scale + 6));
270 }
else if (
sps->vui.vcl_hrd_parameters_present_flag) {
271 bit_rate = (
sps->vui.vcl_hrd_parameters.bit_rate_value_minus1[0] + 1) *
272 (INT64_C(1) << (
sps->vui.vcl_hrd_parameters.bit_rate_scale + 6));
274 bit_rate = bit_rate * 6 / 5;
283 width = 16 * (
sps->pic_width_in_mbs_minus1 + 1);
284 height = 16 * (
sps->pic_height_in_map_units_minus1 + 1) *
285 (2 -
sps->frame_mbs_only_flag);
287 if (
sps->vui.timing_info_present_flag)
298 "conform to any level: using level 6.2.\n");
306 if (
sps->profile_idc == 66 ||
307 sps->profile_idc == 77 ||
308 sps->profile_idc == 88) {
310 sps->constraint_set3_flag = 1;
320 sps->vui_parameters_present_flag = 1;
358 "displaymatrix side data to packet.\n");
372 &
ctx->display_orientation_payload;
382 double scale_x, scale_y, angle;
384 memcpy(matrix,
data,
sizeof(matrix));
386 for (
i = 0;
i < 9;
i++)
387 dmatrix[
i] = matrix[
i] / 65536.0;
390 scale_x =
hypot(dmatrix[0], dmatrix[3]);
391 scale_y =
hypot(dmatrix[1], dmatrix[4]);
394 hflip = dmatrix[0] < 0.0;
395 vflip = dmatrix[4] < 0.0;
402 for (
i = 0;
i < 9;
i += 3) {
403 dmatrix[
i] /= scale_x;
404 dmatrix[
i + 1] /= scale_y;
408 angle = atan2(dmatrix[3], dmatrix[0]);
410 if (!(angle >= -
M_PI && angle <=
M_PI) ||
411 matrix[2] != 0.0 || matrix[5] != 0.0 ||
412 matrix[6] != 0.0 || matrix[7] != 0.0) {
414 "representable in H.264 parameters.\n");
419 (uint16_t)
rint((angle >= 0.0 ? angle
420 : angle + 2 *
M_PI) *
429 (uint16_t)
rint((
ctx->rotate >= 0.0 ?
ctx->rotate
430 :
ctx->rotate + 360.0) *
449 "SEI message to access unit.\n");
462 int err,
i, has_sps, seek_point;
492 seek_point = !
ctx->done_first_au || has_sps ||
498 if (
ctx->sei_user_data && seek_point) {
501 &
ctx->sei_user_data_payload,
NULL);
504 "message to access unit.\n");
509 if (
ctx->delete_filler) {
529 ctx->done_first_au = 1;
536 .fragment_name =
"access unit",
537 .unit_name =
"NAL unit",
545 if (
ctx->sei_user_data) {
551 for (
i = j = 0; j < 32 &&
i < 64 &&
ctx->sei_user_data[
i];
i++) {
553 c =
ctx->sei_user_data[
i];
558 v = (
c <=
'9' ?
c -
'0' :
c -
'a' + 10);
568 if (j == 32 &&
ctx->sei_user_data[
i] ==
'+') {
573 "must be \"UUID+string\".\n");
581 #define OFFSET(x) offsetof(H264MetadataContext, x)
582 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_BSF_PARAM)
587 {
"sample_aspect_ratio",
"Set sample aspect ratio (table E-1)",
589 { .dbl = 0.0 }, 0, 65535,
FLAGS },
591 {
"overscan_appropriate_flag",
"Set VUI overscan appropriate flag",
593 { .i64 = -1 }, -1, 1,
FLAGS },
595 {
"video_format",
"Set video format (table E-2)",
597 { .i64 = -1 }, -1, 7,
FLAGS},
598 {
"video_full_range_flag",
"Set video full range flag",
600 { .i64 = -1 }, -1, 1,
FLAGS },
601 {
"colour_primaries",
"Set colour primaries (table E-3)",
603 { .i64 = -1 }, -1, 255,
FLAGS },
604 {
"transfer_characteristics",
"Set transfer characteristics (table E-4)",
606 { .i64 = -1 }, -1, 255,
FLAGS },
607 {
"matrix_coefficients",
"Set matrix coefficients (table E-5)",
609 { .i64 = -1 }, -1, 255,
FLAGS },
611 {
"chroma_sample_loc_type",
"Set chroma sample location type (figure E-1)",
613 { .i64 = -1 }, -1, 6,
FLAGS },
615 {
"tick_rate",
"Set VUI tick rate (num_units_in_tick / time_scale)",
617 { .dbl = 0.0 }, 0, UINT_MAX,
FLAGS },
618 {
"fixed_frame_rate_flag",
"Set VUI fixed frame rate flag",
620 { .i64 = -1 }, -1, 1,
FLAGS },
622 {
"crop_left",
"Set left border crop offset",
625 {
"crop_right",
"Set right border crop offset",
628 {
"crop_top",
"Set top border crop offset",
631 {
"crop_bottom",
"Set bottom border crop offset",
635 {
"sei_user_data",
"Insert SEI user data (UUID+string)",
638 {
"delete_filler",
"Delete all filler (both NAL and SEI)",
642 "Display orientation SEI",
643 display_orientation,
FLAGS),
645 {
"rotate",
"Set rotation in display orientation SEI (anticlockwise angle in degrees)",
647 { .dbl =
NAN }, -360.0, +360.0,
FLAGS },
648 {
"flip",
"Set flip in display orientation SEI",
651 {
"horizontal",
"Set hor_flip",
654 {
"vertical",
"Set ver_flip",
658 {
"level",
"Set level (table A-1)",
661 {
"auto",
"Attempt to guess level from stream properties",
664 #define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
665 { .i64 = value }, .flags = FLAGS, .unit = "level"
668 {
LEVEL(
"1.1", 11) },
669 {
LEVEL(
"1.2", 12) },
670 {
LEVEL(
"1.3", 13) },
672 {
LEVEL(
"2.1", 21) },
673 {
LEVEL(
"2.2", 22) },
675 {
LEVEL(
"3.1", 31) },
676 {
LEVEL(
"3.2", 32) },
678 {
LEVEL(
"4.1", 41) },
679 {
LEVEL(
"4.2", 42) },
681 {
LEVEL(
"5.1", 51) },
682 {
LEVEL(
"5.2", 52) },
684 {
LEVEL(
"6.1", 61) },
685 {
LEVEL(
"6.2", 62) },
703 .
name =
"h264_metadata",
static enum AVCodecID codec_ids[]
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, buffer_size_t *size)
static av_cold int init(AVCodecContext *avctx)
void ff_cbs_delete_unit(CodedBitstreamFragment *frag, int position)
Delete a unit from a fragment and free all memory it uses.
int ff_cbs_insert_unit_content(CodedBitstreamFragment *frag, int position, CodedBitstreamUnitType type, void *content, AVBufferRef *content_buf)
Insert a new unit into a fragment with the given content.
int ff_cbs_bsf_generic_filter(AVBSFContext *bsf, AVPacket *pkt)
Filter operation for CBS BSF.
int ff_cbs_bsf_generic_init(AVBSFContext *bsf, const CBSBSFType *type)
Initialise generic CBS BSF setup.
void ff_cbs_bsf_generic_close(AVBSFContext *bsf)
Close a generic CBS BSF instance.
#define BSF_ELEMENT_OPTIONS_PIR(name, help, field, opt_flags)
#define BSF_ELEMENT_OPTIONS_PIRE(name, help, field, opt_flags)
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
static int FUNC() aud(CodedBitstreamContext *ctx, RWContext *rw, H264RawAUD *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, AVBufferRef *payload_buf)
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.
static int FUNC() message(CodedBitstreamContext *ctx, RWContext *rw, SEIRawMessage *current)
static av_always_inline void filter(int16_t *output, ptrdiff_t out_stride, const int16_t *low, ptrdiff_t low_stride, const int16_t *high, ptrdiff_t high_stride, int len, int clip)
common internal and external API header
AVCodecID
Identify the syntax and semantics of the bitstream.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
FF_ENABLE_DEPRECATION_WARNINGS 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.
@ AV_PKT_DATA_DISPLAYMATRIX
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
#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 counterclockwise rotation by the specified angle...
void av_display_matrix_flip(int32_t matrix[9], int hflip, int vflip)
Flip the input matrix horizontally and/or vertically.
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[AVCOL_TRC_NB]
static av_const double hypot(double x, double y)
@ 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.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
This structure stores compressed data.
int flags
A combination of AV_PKT_FLAG values.
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
uint16_t anticlockwise_rotation
uint16_t display_orientation_repetition_period
H264RawSliceHeader header
uint8_t uuid_iso_iec_11578[16]
static void rotate(const float rot_quaternion[2][4], float *vec)
Rotate vector with given rotation quaternion.