2 * This file is part of FFmpeg.
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #include "libavutil/avstring.h"
20 #include "libavutil/display.h"
21 #include "libavutil/common.h"
22 #include "libavutil/opt.h"
25 #include "bsf_internal.h"
29 #include "h264_levels.h"
49 typedef struct H264MetadataContext {
52 CodedBitstreamContext *input;
53 CodedBitstreamContext *output;
54 CodedBitstreamFragment access_unit;
61 AVRational sample_aspect_ratio;
63 int overscan_appropriate_flag;
66 int video_full_range_flag;
68 int transfer_characteristics;
69 int matrix_coefficients;
71 int chroma_sample_loc_type;
74 int fixed_frame_rate_flag;
81 const char *sei_user_data;
82 SEIRawUserDataUnregistered sei_user_data_payload;
86 int display_orientation;
89 H264RawSEIDisplayOrientation display_orientation_payload;
92 } H264MetadataContext;
95 static int h264_metadata_insert_aud(AVBSFContext *bsf,
96 CodedBitstreamFragment *au)
98 H264MetadataContext *ctx = bsf->priv_data;
99 int primary_pic_type_mask = 0xff;
102 static const int primary_pic_type_table[] = {
105 0x0e7, // 0, 1, 2, 5, 6, 7
109 0x3bd, // 0, 2, 3, 4, 5, 7, 8, 9
110 0x3ff, // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
113 for (i = 0; i < au->nb_units; i++) {
114 if (au->units[i].type == H264_NAL_SLICE ||
115 au->units[i].type == H264_NAL_IDR_SLICE) {
116 H264RawSlice *slice = au->units[i].content;
117 for (j = 0; j < FF_ARRAY_ELEMS(primary_pic_type_table); j++) {
118 if (!(primary_pic_type_table[j] &
119 (1 << slice->header.slice_type)))
120 primary_pic_type_mask &= ~(1 << j);
124 for (j = 0; j < FF_ARRAY_ELEMS(primary_pic_type_table); j++)
125 if (primary_pic_type_mask & (1 << j))
127 if (j >= FF_ARRAY_ELEMS(primary_pic_type_table)) {
128 av_log(bsf, AV_LOG_ERROR, "No usable primary_pic_type: "
129 "invalid slice types?\n");
130 return AVERROR_INVALIDDATA;
133 ctx->aud_nal = (H264RawAUD) {
134 .nal_unit_header.nal_unit_type = H264_NAL_AUD,
135 .primary_pic_type = j,
138 err = ff_cbs_insert_unit_content(au, 0, H264_NAL_AUD,
139 &ctx->aud_nal, NULL);
141 av_log(bsf, AV_LOG_ERROR, "Failed to insert AUD.\n");
148 static int h264_metadata_update_sps(AVBSFContext *bsf,
151 H264MetadataContext *ctx = bsf->priv_data;
153 int crop_unit_x, crop_unit_y;
155 if (ctx->sample_aspect_ratio.num && ctx->sample_aspect_ratio.den) {
157 static const AVRational sar_idc[] = {
158 { 0, 0 }, // Unspecified (never written here).
159 { 1, 1 }, { 12, 11 }, { 10, 11 }, { 16, 11 },
160 { 40, 33 }, { 24, 11 }, { 20, 11 }, { 32, 11 },
161 { 80, 33 }, { 18, 11 }, { 15, 11 }, { 64, 33 },
162 { 160, 99 }, { 4, 3 }, { 3, 2 }, { 2, 1 },
166 av_reduce(&num, &den, ctx->sample_aspect_ratio.num,
167 ctx->sample_aspect_ratio.den, 65535);
169 for (i = 1; i < FF_ARRAY_ELEMS(sar_idc); i++) {
170 if (num == sar_idc[i].num &&
171 den == sar_idc[i].den)
174 if (i == FF_ARRAY_ELEMS(sar_idc)) {
175 sps->vui.aspect_ratio_idc = 255;
176 sps->vui.sar_width = num;
177 sps->vui.sar_height = den;
179 sps->vui.aspect_ratio_idc = i;
181 sps->vui.aspect_ratio_info_present_flag = 1;
185 #define SET_VUI_FIELD(field) do { \
186 if (ctx->field >= 0) { \
187 sps->vui.field = ctx->field; \
192 if (ctx->overscan_appropriate_flag >= 0) {
193 SET_VUI_FIELD(overscan_appropriate_flag);
194 sps->vui.overscan_info_present_flag = 1;
197 if (ctx->video_format >= 0 ||
198 ctx->video_full_range_flag >= 0 ||
199 ctx->colour_primaries >= 0 ||
200 ctx->transfer_characteristics >= 0 ||
201 ctx->matrix_coefficients >= 0) {
203 SET_VUI_FIELD(video_format);
205 SET_VUI_FIELD(video_full_range_flag);
207 if (ctx->colour_primaries >= 0 ||
208 ctx->transfer_characteristics >= 0 ||
209 ctx->matrix_coefficients >= 0) {
211 SET_VUI_FIELD(colour_primaries);
212 SET_VUI_FIELD(transfer_characteristics);
213 SET_VUI_FIELD(matrix_coefficients);
215 sps->vui.colour_description_present_flag = 1;
217 sps->vui.video_signal_type_present_flag = 1;
220 if (ctx->chroma_sample_loc_type >= 0) {
221 sps->vui.chroma_sample_loc_type_top_field =
222 ctx->chroma_sample_loc_type;
223 sps->vui.chroma_sample_loc_type_bottom_field =
224 ctx->chroma_sample_loc_type;
225 sps->vui.chroma_loc_info_present_flag = 1;
229 if (ctx->tick_rate.num && ctx->tick_rate.den) {
232 av_reduce(&num, &den, ctx->tick_rate.num, ctx->tick_rate.den,
233 UINT32_MAX > INT_MAX ? UINT32_MAX : INT_MAX);
235 sps->vui.time_scale = num;
236 sps->vui.num_units_in_tick = den;
238 sps->vui.timing_info_present_flag = 1;
241 SET_VUI_FIELD(fixed_frame_rate_flag);
243 if (sps->separate_colour_plane_flag || sps->chroma_format_idc == 0) {
245 crop_unit_y = 2 - sps->frame_mbs_only_flag;
247 crop_unit_x = 1 + (sps->chroma_format_idc < 3);
248 crop_unit_y = (1 + (sps->chroma_format_idc < 2)) *
249 (2 - sps->frame_mbs_only_flag);
251 #define CROP(border, unit) do { \
252 if (ctx->crop_ ## border >= 0) { \
253 if (ctx->crop_ ## border % unit != 0) { \
254 av_log(bsf, AV_LOG_ERROR, "Invalid value for crop_%s: " \
255 "must be a multiple of %d.\n", #border, unit); \
256 return AVERROR(EINVAL); \
258 sps->frame_crop_ ## border ## _offset = \
259 ctx->crop_ ## border / unit; \
260 sps->frame_cropping_flag = 1; \
263 CROP(left, crop_unit_x);
264 CROP(right, crop_unit_x);
265 CROP(top, crop_unit_y);
266 CROP(bottom, crop_unit_y);
269 if (ctx->level != LEVEL_UNSET) {
272 if (ctx->level == LEVEL_AUTO) {
273 const H264LevelDescriptor *desc;
275 int width, height, dpb_frames;
278 if (sps->vui.nal_hrd_parameters_present_flag) {
279 bit_rate = (sps->vui.nal_hrd_parameters.bit_rate_value_minus1[0] + 1) *
280 (INT64_C(1) << (sps->vui.nal_hrd_parameters.bit_rate_scale + 6));
281 } else if (sps->vui.vcl_hrd_parameters_present_flag) {
282 bit_rate = (sps->vui.vcl_hrd_parameters.bit_rate_value_minus1[0] + 1) *
283 (INT64_C(1) << (sps->vui.vcl_hrd_parameters.bit_rate_scale + 6));
284 // Adjust for VCL vs. NAL limits.
285 bit_rate = bit_rate * 6 / 5;
290 // Don't use max_dec_frame_buffering if it is only inferred.
291 dpb_frames = sps->vui.bitstream_restriction_flag ?
292 sps->vui.max_dec_frame_buffering : H264_MAX_DPB_FRAMES;
294 width = 16 * (sps->pic_width_in_mbs_minus1 + 1);
295 height = 16 * (sps->pic_height_in_map_units_minus1 + 1) *
296 (2 - sps->frame_mbs_only_flag);
298 if (sps->vui.timing_info_present_flag)
299 framerate = sps->vui.time_scale / sps->vui.num_units_in_tick / 2;
303 desc = ff_h264_guess_level(sps->profile_idc, bit_rate, framerate,
304 width, height, dpb_frames);
306 level_idc = desc->level_idc;
308 av_log(bsf, AV_LOG_WARNING, "Stream does not appear to "
309 "conform to any level: using level 6.2.\n");
313 level_idc = ctx->level;
316 if (level_idc == 9) {
317 if (sps->profile_idc == 66 ||
318 sps->profile_idc == 77 ||
319 sps->profile_idc == 88) {
321 sps->constraint_set3_flag = 1;
326 sps->level_idc = level_idc;
331 sps->vui_parameters_present_flag = 1;
336 static int h264_metadata_update_side_data(AVBSFContext *bsf, AVPacket *pkt)
338 H264MetadataContext *ctx = bsf->priv_data;
339 CodedBitstreamFragment *au = &ctx->access_unit;
344 side_data = av_packet_get_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA,
349 err = ff_cbs_read(ctx->input, au, side_data, side_data_size);
351 av_log(bsf, AV_LOG_ERROR, "Failed to read extradata from packet side data.\n");
355 for (i = 0; i < au->nb_units; i++) {
356 if (au->units[i].type == H264_NAL_SPS) {
357 err = h264_metadata_update_sps(bsf, au->units[i].content);
363 err = ff_cbs_write_fragment_data(ctx->output, au);
365 av_log(bsf, AV_LOG_ERROR, "Failed to write extradata into packet side data.\n");
369 side_data = av_packet_new_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA, au->data_size);
371 return AVERROR(ENOMEM);
372 memcpy(side_data, au->data, au->data_size);
374 ff_cbs_fragment_reset(au);
379 static int h264_metadata_handle_display_orientation(AVBSFContext *bsf,
381 CodedBitstreamFragment *au,
384 H264MetadataContext *ctx = bsf->priv_data;
385 SEIRawMessage *message;
389 while (ff_cbs_sei_find_message(ctx->output, au,
390 SEI_TYPE_DISPLAY_ORIENTATION,
392 H264RawSEIDisplayOrientation *disp = message->payload;
395 matrix = av_malloc(9 * sizeof(int32_t));
397 return AVERROR(ENOMEM);
399 av_display_rotation_set(matrix,
400 disp->anticlockwise_rotation *
402 av_display_matrix_flip(matrix, disp->hor_flip, disp->ver_flip);
404 // If there are multiple display orientation messages in an
405 // access unit, then the last one added to the packet (i.e.
406 // the first one in the access unit) will prevail.
407 err = av_packet_add_side_data(pkt, AV_PKT_DATA_DISPLAYMATRIX,
409 9 * sizeof(int32_t));
411 av_log(bsf, AV_LOG_ERROR, "Failed to attach extracted "
412 "displaymatrix side data to packet.\n");
414 return AVERROR(ENOMEM);
418 if (ctx->display_orientation == REMOVE ||
419 ctx->display_orientation == INSERT) {
420 ff_cbs_sei_delete_message_type(ctx->output, au,
421 SEI_TYPE_DISPLAY_ORIENTATION);
424 if (ctx->display_orientation == INSERT) {
425 H264RawSEIDisplayOrientation *disp =
426 &ctx->display_orientation_payload;
431 data = av_packet_get_side_data(pkt, AV_PKT_DATA_DISPLAYMATRIX, &size);
432 if (data && size >= 9 * sizeof(int32_t)) {
437 memcpy(matrix, data, sizeof(matrix));
440 if (matrix[0] < 0 && matrix[4] > 0)
442 else if (matrix[0] > 0 && matrix[4] < 0)
444 av_display_matrix_flip(matrix, hflip, vflip);
446 angle = av_display_rotation_get(matrix);
448 if (!(angle >= -180.0 && angle <= 180.0 /* also excludes NaN */) ||
449 matrix[2] != 0 || matrix[5] != 0 ||
450 matrix[6] != 0 || matrix[7] != 0) {
451 av_log(bsf, AV_LOG_WARNING, "Input display matrix is not "
452 "representable in H.264 parameters.\n");
454 disp->hor_flip = hflip;
455 disp->ver_flip = vflip;
456 disp->anticlockwise_rotation =
457 (uint16_t)rint((angle >= 0.0 ? angle
465 if (!isnan(ctx->rotate)) {
466 disp->anticlockwise_rotation =
467 (uint16_t)rint((ctx->rotate >= 0.0 ? ctx->rotate
468 : ctx->rotate + 360.0) *
473 disp->hor_flip = !!(ctx->flip & FLIP_HORIZONTAL);
474 disp->ver_flip = !!(ctx->flip & FLIP_VERTICAL);
480 disp->display_orientation_repetition_period = 1;
482 err = ff_cbs_sei_add_message(ctx->output, au, 1,
483 SEI_TYPE_DISPLAY_ORIENTATION,
486 av_log(bsf, AV_LOG_ERROR, "Failed to add display orientation "
487 "SEI message to access unit.\n");
496 static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *pkt)
498 H264MetadataContext *ctx = bsf->priv_data;
499 CodedBitstreamFragment *au = &ctx->access_unit;
500 int err, i, has_sps, seek_point;
502 err = ff_bsf_get_packet_ref(bsf, pkt);
506 err = h264_metadata_update_side_data(bsf, pkt);
510 err = ff_cbs_read_packet(ctx->input, au, pkt);
512 av_log(bsf, AV_LOG_ERROR, "Failed to read packet.\n");
516 if (au->nb_units == 0) {
517 av_log(bsf, AV_LOG_ERROR, "No NAL units in packet.\n");
518 err = AVERROR_INVALIDDATA;
522 // If an AUD is present, it must be the first NAL unit.
523 if (au->units[0].type == H264_NAL_AUD) {
524 if (ctx->aud == REMOVE)
525 ff_cbs_delete_unit(au, 0);
527 if (ctx->aud == INSERT) {
528 err = h264_metadata_insert_aud(bsf, au);
535 for (i = 0; i < au->nb_units; i++) {
536 if (au->units[i].type == H264_NAL_SPS) {
537 err = h264_metadata_update_sps(bsf, au->units[i].content);
544 // The current packet should be treated as a seek point for metadata
545 // insertion if any of:
546 // - It is the first packet in the stream.
547 // - It contains an SPS, indicating that a sequence might start here.
548 // - It is marked as containing a key frame.
549 seek_point = !ctx->done_first_au || has_sps ||
550 (pkt->flags & AV_PKT_FLAG_KEY);
552 if (ctx->sei_user_data && seek_point) {
553 err = ff_cbs_sei_add_message(ctx->output, au, 1,
554 SEI_TYPE_USER_DATA_UNREGISTERED,
555 &ctx->sei_user_data_payload, NULL);
557 av_log(bsf, AV_LOG_ERROR, "Failed to add user data SEI "
558 "message to access unit.\n");
563 if (ctx->delete_filler) {
564 for (i = au->nb_units - 1; i >= 0; i--) {
565 if (au->units[i].type == H264_NAL_FILLER_DATA) {
566 ff_cbs_delete_unit(au, i);
571 ff_cbs_sei_delete_message_type(ctx->output, au,
572 SEI_TYPE_FILLER_PAYLOAD);
575 if (ctx->display_orientation != PASS) {
576 err = h264_metadata_handle_display_orientation(bsf, pkt, au,
582 err = ff_cbs_write_packet(ctx->output, pkt, au);
584 av_log(bsf, AV_LOG_ERROR, "Failed to write packet.\n");
588 ctx->done_first_au = 1;
592 ff_cbs_fragment_reset(au);
595 av_packet_unref(pkt);
600 static int h264_metadata_init(AVBSFContext *bsf)
602 H264MetadataContext *ctx = bsf->priv_data;
603 CodedBitstreamFragment *au = &ctx->access_unit;
606 if (ctx->sei_user_data) {
607 SEIRawUserDataUnregistered *udu = &ctx->sei_user_data_payload;
610 // Parse UUID. It must be a hex string of length 32, possibly
611 // containing '-'s between hex digits (which we ignore).
612 for (i = j = 0; j < 32 && i < 64 && ctx->sei_user_data[i]; i++) {
614 c = ctx->sei_user_data[i];
617 } else if (av_isxdigit(c)) {
619 v = (c <= '9' ? c - '0' : c - 'a' + 10);
624 udu->uuid_iso_iec_11578[j / 2] |= v;
626 udu->uuid_iso_iec_11578[j / 2] = v << 4;
629 if (j == 32 && ctx->sei_user_data[i] == '+') {
630 udu->data = (uint8_t*)ctx->sei_user_data + i + 1;
631 udu->data_length = strlen(udu->data) + 1;
633 av_log(bsf, AV_LOG_ERROR, "Invalid user data: "
634 "must be \"UUID+string\".\n");
635 err = AVERROR(EINVAL);
640 err = ff_cbs_init(&ctx->input, AV_CODEC_ID_H264, bsf);
643 err = ff_cbs_init(&ctx->output, AV_CODEC_ID_H264, bsf);
647 if (bsf->par_in->extradata) {
648 err = ff_cbs_read_extradata(ctx->input, au, bsf->par_in);
650 av_log(bsf, AV_LOG_ERROR, "Failed to read extradata.\n");
654 for (i = 0; i < au->nb_units; i++) {
655 if (au->units[i].type == H264_NAL_SPS) {
656 err = h264_metadata_update_sps(bsf, au->units[i].content);
662 err = ff_cbs_write_extradata(ctx->output, bsf->par_out, au);
664 av_log(bsf, AV_LOG_ERROR, "Failed to write extradata.\n");
671 ff_cbs_fragment_reset(au);
675 static void h264_metadata_close(AVBSFContext *bsf)
677 H264MetadataContext *ctx = bsf->priv_data;
679 ff_cbs_fragment_free(&ctx->access_unit);
680 ff_cbs_close(&ctx->input);
681 ff_cbs_close(&ctx->output);
684 #define OFFSET(x) offsetof(H264MetadataContext, x)
685 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_BSF_PARAM)
686 static const AVOption h264_metadata_options[] = {
687 { "aud", "Access Unit Delimiter NAL units",
688 OFFSET(aud), AV_OPT_TYPE_INT,
689 { .i64 = PASS }, PASS, REMOVE, FLAGS, "aud" },
690 { "pass", NULL, 0, AV_OPT_TYPE_CONST,
691 { .i64 = PASS }, .flags = FLAGS, .unit = "aud" },
692 { "insert", NULL, 0, AV_OPT_TYPE_CONST,
693 { .i64 = INSERT }, .flags = FLAGS, .unit = "aud" },
694 { "remove", NULL, 0, AV_OPT_TYPE_CONST,
695 { .i64 = REMOVE }, .flags = FLAGS, .unit = "aud" },
697 { "sample_aspect_ratio", "Set sample aspect ratio (table E-1)",
698 OFFSET(sample_aspect_ratio), AV_OPT_TYPE_RATIONAL,
699 { .dbl = 0.0 }, 0, 65535, FLAGS },
701 { "overscan_appropriate_flag", "Set VUI overscan appropriate flag",
702 OFFSET(overscan_appropriate_flag), AV_OPT_TYPE_INT,
703 { .i64 = -1 }, -1, 1, FLAGS },
705 { "video_format", "Set video format (table E-2)",
706 OFFSET(video_format), AV_OPT_TYPE_INT,
707 { .i64 = -1 }, -1, 7, FLAGS},
708 { "video_full_range_flag", "Set video full range flag",
709 OFFSET(video_full_range_flag), AV_OPT_TYPE_INT,
710 { .i64 = -1 }, -1, 1, FLAGS },
711 { "colour_primaries", "Set colour primaries (table E-3)",
712 OFFSET(colour_primaries), AV_OPT_TYPE_INT,
713 { .i64 = -1 }, -1, 255, FLAGS },
714 { "transfer_characteristics", "Set transfer characteristics (table E-4)",
715 OFFSET(transfer_characteristics), AV_OPT_TYPE_INT,
716 { .i64 = -1 }, -1, 255, FLAGS },
717 { "matrix_coefficients", "Set matrix coefficients (table E-5)",
718 OFFSET(matrix_coefficients), AV_OPT_TYPE_INT,
719 { .i64 = -1 }, -1, 255, FLAGS },
721 { "chroma_sample_loc_type", "Set chroma sample location type (figure E-1)",
722 OFFSET(chroma_sample_loc_type), AV_OPT_TYPE_INT,
723 { .i64 = -1 }, -1, 6, FLAGS },
725 { "tick_rate", "Set VUI tick rate (num_units_in_tick / time_scale)",
726 OFFSET(tick_rate), AV_OPT_TYPE_RATIONAL,
727 { .dbl = 0.0 }, 0, UINT_MAX, FLAGS },
728 { "fixed_frame_rate_flag", "Set VUI fixed frame rate flag",
729 OFFSET(fixed_frame_rate_flag), AV_OPT_TYPE_INT,
730 { .i64 = -1 }, -1, 1, FLAGS },
732 { "crop_left", "Set left border crop offset",
733 OFFSET(crop_left), AV_OPT_TYPE_INT,
734 { .i64 = -1 }, -1, H264_MAX_WIDTH, FLAGS },
735 { "crop_right", "Set right border crop offset",
736 OFFSET(crop_right), AV_OPT_TYPE_INT,
737 { .i64 = -1 }, -1, H264_MAX_WIDTH, FLAGS },
738 { "crop_top", "Set top border crop offset",
739 OFFSET(crop_top), AV_OPT_TYPE_INT,
740 { .i64 = -1 }, -1, H264_MAX_HEIGHT, FLAGS },
741 { "crop_bottom", "Set bottom border crop offset",
742 OFFSET(crop_bottom), AV_OPT_TYPE_INT,
743 { .i64 = -1 }, -1, H264_MAX_HEIGHT, FLAGS },
745 { "sei_user_data", "Insert SEI user data (UUID+string)",
746 OFFSET(sei_user_data), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = FLAGS },
748 { "delete_filler", "Delete all filler (both NAL and SEI)",
749 OFFSET(delete_filler), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, FLAGS},
751 { "display_orientation", "Display orientation SEI",
752 OFFSET(display_orientation), AV_OPT_TYPE_INT,
753 { .i64 = PASS }, PASS, EXTRACT, FLAGS, "disp_or" },
754 { "pass", NULL, 0, AV_OPT_TYPE_CONST,
755 { .i64 = PASS }, .flags = FLAGS, .unit = "disp_or" },
756 { "insert", NULL, 0, AV_OPT_TYPE_CONST,
757 { .i64 = INSERT }, .flags = FLAGS, .unit = "disp_or" },
758 { "remove", NULL, 0, AV_OPT_TYPE_CONST,
759 { .i64 = REMOVE }, .flags = FLAGS, .unit = "disp_or" },
760 { "extract", NULL, 0, AV_OPT_TYPE_CONST,
761 { .i64 = EXTRACT }, .flags = FLAGS, .unit = "disp_or" },
763 { "rotate", "Set rotation in display orientation SEI (anticlockwise angle in degrees)",
764 OFFSET(rotate), AV_OPT_TYPE_DOUBLE,
765 { .dbl = NAN }, -360.0, +360.0, FLAGS },
766 { "flip", "Set flip in display orientation SEI",
767 OFFSET(flip), AV_OPT_TYPE_FLAGS,
768 { .i64 = 0 }, 0, FLIP_HORIZONTAL | FLIP_VERTICAL, FLAGS, "flip" },
769 { "horizontal", "Set hor_flip",
770 0, AV_OPT_TYPE_CONST,
771 { .i64 = FLIP_HORIZONTAL }, .flags = FLAGS, .unit = "flip" },
772 { "vertical", "Set ver_flip",
773 0, AV_OPT_TYPE_CONST,
774 { .i64 = FLIP_VERTICAL }, .flags = FLAGS, .unit = "flip" },
776 { "level", "Set level (table A-1)",
777 OFFSET(level), AV_OPT_TYPE_INT,
778 { .i64 = LEVEL_UNSET }, LEVEL_UNSET, 0xff, FLAGS, "level" },
779 { "auto", "Attempt to guess level from stream properties",
780 0, AV_OPT_TYPE_CONST,
781 { .i64 = LEVEL_AUTO }, .flags = FLAGS, .unit = "level" },
782 #define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
783 { .i64 = value }, .flags = FLAGS, .unit = "level"
786 { LEVEL("1.1", 11) },
787 { LEVEL("1.2", 12) },
788 { LEVEL("1.3", 13) },
790 { LEVEL("2.1", 21) },
791 { LEVEL("2.2", 22) },
793 { LEVEL("3.1", 31) },
794 { LEVEL("3.2", 32) },
796 { LEVEL("4.1", 41) },
797 { LEVEL("4.2", 42) },
799 { LEVEL("5.1", 51) },
800 { LEVEL("5.2", 52) },
802 { LEVEL("6.1", 61) },
803 { LEVEL("6.2", 62) },
809 static const AVClass h264_metadata_class = {
810 .class_name = "h264_metadata_bsf",
811 .item_name = av_default_item_name,
812 .option = h264_metadata_options,
813 .version = LIBAVUTIL_VERSION_INT,
816 static const enum AVCodecID h264_metadata_codec_ids[] = {
817 AV_CODEC_ID_H264, AV_CODEC_ID_NONE,
820 const AVBitStreamFilter ff_h264_metadata_bsf = {
821 .name = "h264_metadata",
822 .priv_data_size = sizeof(H264MetadataContext),
823 .priv_class = &h264_metadata_class,
824 .init = &h264_metadata_init,
825 .close = &h264_metadata_close,
826 .filter = &h264_metadata_filter,
827 .codec_ids = h264_metadata_codec_ids,