22 #include <va/va_enc_hevc.h>
88 char *
data,
size_t *data_len,
102 "%zu < %zu.\n", *data_len,
133 char *
data,
size_t *data_len)
167 char *
data,
size_t *data_len)
193 char *
data,
size_t *data_len)
213 .nuh_temporal_id_plus1 = 1,
245 *type = VAEncPackedHeaderRawData;
274 memset(vps, 0,
sizeof(*vps));
275 memset(sps, 0,
sizeof(*sps));
276 memset(pps, 0,
sizeof(*pps));
292 "%s is not supported.\n", desc->
name);
304 .nuh_temporal_id_plus1 = 1,
319 if (chroma_format == 1) {
356 "any normal level; using level 8.5.\n");
391 .nuh_temporal_id_plus1 = 1,
470 { 1, 1 }, { 12, 11 }, { 10, 11 }, { 16, 11 },
471 { 40, 33 }, { 24, 11 }, { 20, 11 }, { 32, 11 },
472 { 80, 33 }, { 18, 11 }, { 15, 11 }, { 64, 33 },
473 { 160, 99 }, { 4, 3 }, { 3, 2 }, { 2, 1 },
544 .nuh_temporal_id_plus1 = 1,
563 *vseq = (VAEncSequenceParameterBufferHEVC) {
582 .strong_intra_smoothing_enabled_flag =
585 .sample_adaptive_offset_enabled_flag =
592 .log2_min_luma_coding_block_size_minus3 =
594 .log2_diff_max_min_luma_coding_block_size =
596 .log2_min_transform_block_size_minus2 =
598 .log2_diff_max_min_transform_block_size =
600 .max_transform_hierarchy_depth_inter =
602 .max_transform_hierarchy_depth_intra =
605 .pcm_sample_bit_depth_luma_minus1 =
607 .pcm_sample_bit_depth_chroma_minus1 =
609 .log2_min_pcm_luma_coding_block_size_minus3 =
611 .log2_max_pcm_luma_coding_block_size_minus3 =
615 .vui_parameters_present_flag = 0,
618 *vpic = (VAEncPictureParameterBufferHEVC) {
619 .decoded_curr_pic = {
620 .picture_id = VA_INVALID_ID,
621 .flags = VA_PICTURE_HEVC_INVALID,
624 .coded_buf = VA_INVALID_ID,
626 .collocated_ref_pic_index = 0xff,
639 .ctu_max_bitsize_allowed = 0,
641 .num_ref_idx_l0_default_active_minus1 =
643 .num_ref_idx_l1_default_active_minus1 =
658 .loop_filter_across_tiles_enabled_flag =
662 .screen_content_flag = 0,
663 .enable_gpu_weighted_prediction = 0,
664 .no_output_of_prior_pics_flag = 0,
716 .nuh_temporal_id_plus1 = 1,
743 const int mapping[3] = {1, 2, 0};
744 const int chroma_den = 50000;
745 const int luma_den = 10000;
747 for (i = 0; i < 3; i++) {
748 const int j = mapping[i];
790 clli->max_pic_average_light_level =
FFMIN(clm->
MaxFALL, 65535);
796 vpic->decoded_curr_pic = (VAPictureHEVC) {
802 for (i = 0; i < pic->
nb_refs; i++) {
806 vpic->reference_frames[i] = (VAPictureHEVC) {
810 VA_PICTURE_HEVC_RPS_ST_CURR_BEFORE : 0) |
812 VA_PICTURE_HEVC_RPS_ST_CURR_AFTER : 0),
816 vpic->reference_frames[i] = (VAPictureHEVC) {
817 .picture_id = VA_INVALID_ID,
818 .flags = VA_PICTURE_HEVC_INVALID,
828 vpic->pic_fields.bits.idr_pic_flag = 1;
829 vpic->pic_fields.bits.coding_type = 1;
830 vpic->pic_fields.bits.reference_pic_flag = 1;
833 vpic->pic_fields.bits.idr_pic_flag = 0;
834 vpic->pic_fields.bits.coding_type = 1;
835 vpic->pic_fields.bits.reference_pic_flag = 1;
838 vpic->pic_fields.bits.idr_pic_flag = 0;
839 vpic->pic_fields.bits.coding_type = 2;
840 vpic->pic_fields.bits.reference_pic_flag = 1;
843 vpic->pic_fields.bits.idr_pic_flag = 0;
844 vpic->pic_fields.bits.coding_type = 3;
845 vpic->pic_fields.bits.reference_pic_flag = 0;
870 .nuh_temporal_id_plus1 = 1,
891 memset(rps, 0,
sizeof(*rps));
899 for (i = 0; i < pic->
nb_refs; i++) {
900 if (pic->
refs[i] == st)
916 if (rp->
refs[0] == st && rp->
refs[1] == pic)
964 *vslice = (VAEncSliceParameterBufferHEVC) {
986 .slice_fields.bits = {
990 .slice_temporal_mvp_enabled_flag =
994 .num_ref_idx_active_override_flag =
998 .slice_deblocking_filter_disabled_flag =
1000 .slice_loop_filter_across_slices_enabled_flag =
1007 vslice->ref_pic_list0[i].picture_id = VA_INVALID_ID;
1008 vslice->ref_pic_list0[i].flags = VA_PICTURE_HEVC_INVALID;
1009 vslice->ref_pic_list1[i].picture_id = VA_INVALID_ID;
1010 vslice->ref_pic_list1[i].flags = VA_PICTURE_HEVC_INVALID;
1018 vslice->ref_pic_list0[0] = vpic->reference_frames[0];
1023 vslice->ref_pic_list1[0] = vpic->reference_frames[1];
1053 "%d / %d / %d for IDR- / P- / B-frames.\n",
1073 #if VA_CHECK_VERSION(0, 37, 0)
1087 .sequence_params_size =
sizeof(VAEncSequenceParameterBufferHEVC),
1090 .picture_params_size =
sizeof(VAEncPictureParameterBufferHEVC),
1093 .slice_params_size =
sizeof(VAEncSliceParameterBufferHEVC),
1096 .sequence_header_type = VAEncPackedHeaderSequence,
1099 .slice_header_type = VAEncPackedHeaderHEVC_Slice,
1119 "in 8-bit unsigned integer.\n", avctx->
level);
1124 VA_ENC_PACKED_HEADER_SEQUENCE |
1125 VA_ENC_PACKED_HEADER_SLICE |
1126 VA_ENC_PACKED_HEADER_MISC;
1146 #define OFFSET(x) offsetof(VAAPIEncodeH265Context, x)
1147 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
1151 {
"qp",
"Constant QP (for P-frames; scaled by qfactor/qoffset for I/B)",
1154 {
"aud",
"Include AUD",
1157 {
"profile",
"Set profile (general_profile_idc)",
1161 #define PROFILE(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
1162 { .i64 = value }, 0, 0, FLAGS, "profile"
1168 {
"tier",
"Set tier (general_tier_flag)",
1170 { .i64 = 0 }, 0, 1,
FLAGS,
"tier" },
1172 { .i64 = 0 }, 0, 0,
FLAGS,
"tier" },
1174 { .i64 = 1 }, 0, 0,
FLAGS,
"tier" },
1176 {
"level",
"Set level (general_level_idc)",
1180 #define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
1181 { .i64 = value }, 0, 0, FLAGS, "level"
1184 {
LEVEL(
"2.1", 63) },
1186 {
LEVEL(
"3.1", 93) },
1187 {
LEVEL(
"4", 120) },
1188 {
LEVEL(
"4.1", 123) },
1189 {
LEVEL(
"5", 150) },
1190 {
LEVEL(
"5.1", 153) },
1191 {
LEVEL(
"5.2", 156) },
1192 {
LEVEL(
"6", 180) },
1193 {
LEVEL(
"6.1", 183) },
1194 {
LEVEL(
"6.2", 186) },
1197 {
"sei",
"Set SEI to include",
1200 0, INT_MAX,
FLAGS,
"sei" },
1202 "Include HDR metadata for mastering display colour volume "
1203 "and content light level information",
1206 INT_MIN, INT_MAX,
FLAGS,
"sei" },
1215 {
"i_qfactor",
"1" },
1216 {
"i_qoffset",
"0" },
1217 {
"b_qfactor",
"6/5" },
1218 {
"b_qoffset",
"0" },
1232 .
name =
"hevc_vaapi",
1240 .priv_class = &vaapi_encode_h265_class,
1242 .
defaults = vaapi_encode_h265_defaults,
1247 .wrapper_name =
"vaapi",
uint16_t display_primaries_x[3]
uint8_t sps_video_parameter_set_id
uint8_t loop_filter_across_tiles_enabled_flag
uint32_t min_display_mastering_luminance
uint8_t transfer_characteristics
uint8_t pps_pic_parameter_set_id
uint8_t vps_poc_proportional_to_timing_flag
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
unsigned MaxCLL
Max content light level (cd/m^2).
uint8_t num_ref_idx_l0_default_active_minus1
uint8_t log2_max_mv_length_horizontal
ptrdiff_t const GLvoid * data
uint8_t motion_vectors_over_pic_boundaries_flag
uint8_t sps_sub_layer_ordering_info_present_flag
uint8_t general_max_8bit_constraint_flag
static int vaapi_encode_h265_add_nal(AVCodecContext *avctx, CodedBitstreamFragment *au, void *nal_unit)
int64_t bit_rate
the average bitrate
#define LIBAVUTIL_VERSION_INT
uint8_t bitstream_restriction_flag
uint8_t bit_depth_luma_minus8
static av_cold int init(AVCodecContext *avctx)
#define AV_CODEC_CAP_HARDWARE
Codec is backed by a hardware implementation.
H265RawSEIContentLightLevelInfo content_light_level
uint8_t vui_timing_info_present_flag
int ff_cbs_init(CodedBitstreamContext **ctx_ptr, enum AVCodecID codec_id, void *log_ctx)
Create and initialise a new context for the given codec.
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Content light level (based on CTA-861.3).
uint8_t sps_max_sub_layers_minus1
uint8_t sps_max_num_reorder_pics[HEVC_MAX_SUB_LAYERS]
const char * av_default_item_name(void *ptr)
Return the context name.
static const AVClass vaapi_encode_h265_class
uint8_t tiles_enabled_flag
int ff_cbs_insert_unit_content(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int position, CodedBitstreamUnitType type, void *content, AVBufferRef *content_buf)
Insert a new unit into a fragment with the given content.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
uint8_t restricted_ref_pic_lists_flag
Mastering display metadata associated with a video frame.
H265RawProfileTierLevel profile_tier_level
static av_cold int vaapi_encode_h265_close(AVCodecContext *avctx)
CodedBitstreamContext * cbc
void * codec_sequence_params
uint8_t sample_adaptive_offset_enabled_flag
uint8_t vui_parameters_present_flag
uint8_t pcm_sample_bit_depth_luma_minus1
static const AVCodecDefault vaapi_encode_h265_defaults[]
uint8_t bit_depth_chroma_minus8
float i_quant_offset
qscale offset between P and I-frames
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
uint8_t general_profile_idc
uint8_t used_by_curr_pic_s0_flag[HEVC_MAX_REFS]
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
uint32_t vps_num_units_in_tick
uint8_t sign_data_hiding_enabled_flag
uint16_t display_primaries_y[3]
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
uint16_t conf_win_right_offset
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
H265RawSEIContentLightLevelInfo sei_content_light_level
uint16_t pic_height_in_luma_samples
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
uint8_t vps_sub_layer_ordering_info_present_flag
uint8_t general_max_12bit_constraint_flag
float b_quant_factor
qscale factor between IP and B-frames If > 0 then the last P-frame quantizer will be used (q= lastp_q...
#define FF_PROFILE_HEVC_MAIN
uint8_t vps_timing_info_present_flag
uint8_t log2_max_pic_order_cnt_lsb_minus4
uint8_t constrained_intra_pred_flag
uint32_t sps_max_latency_increase_plus1[HEVC_MAX_SUB_LAYERS]
Structure to hold side data for an AVFrame.
uint8_t matrix_coefficients
static double av_q2d(AVRational a)
Convert an AVRational to a double.
uint8_t aspect_ratio_info_present_flag
uint8_t vps_max_sub_layers_minus1
#define AVERROR_EOF
End of file.
#define AV_LOG_VERBOSE
Detailed information.
H265RawSEIPayload payload[H265_MAX_SEI_PAYLOADS]
uint8_t general_max_monochrome_constraint_flag
VASurfaceID recon_surface
uint8_t log2_min_luma_transform_block_size_minus2
static const uint8_t header[24]
uint8_t sps_scaling_list_data_present_flag
uint8_t log2_min_pcm_luma_coding_block_size_minus3
static int vaapi_encode_h265_write_access_unit(AVCodecContext *avctx, char *data, size_t *data_len, CodedBitstreamFragment *au)
#define FF_PROFILE_HEVC_MAIN_10
uint8_t video_full_range_flag
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
uint8_t chroma_sample_loc_type_bottom_field
uint16_t vps_num_layer_sets_minus1
uint8_t video_signal_type_present_flag
size_t data_size
The number of bytes in the bitstream.
uint32_t vui_num_ticks_poc_diff_one_minus1
uint8_t vps_max_dec_pic_buffering_minus1[HEVC_MAX_SUB_LAYERS]
uint8_t log2_max_mv_length_vertical
AVHWFramesContext * input_frames
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
uint8_t vps_video_parameter_set_id
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
void ff_cbs_fragment_uninit(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Free all allocated memory in a fragment.
uint8_t conformance_window_flag
uint16_t max_content_light_level
uint8_t max_bits_per_min_cu_denom
static av_cold int vaapi_encode_h265_init(AVCodecContext *avctx)
union H265RawSEIPayload::@55 payload
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
uint8_t chroma_loc_info_present_flag
#define PROFILE(name, value)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx)
uint8_t num_negative_pics
simple assert() macros that are a bit more flexible than ISO C assert().
const char * name
Name of the codec implementation.
float i_quant_factor
qscale factor between P- and I-frames If > 0 then the last P-frame quantizer will be used (q = lastp_...
static const AVOption vaapi_encode_h265_options[]
uint8_t general_interlaced_source_flag
static const AVCodecDefault defaults[]
uint8_t general_tier_flag
uint8_t transform_skip_enabled_flag
H265RawNALUnitHeader nal_unit_header
uint8_t pcm_sample_bit_depth_chroma_minus1
void * codec_picture_params
size_t data_bit_padding
The number of bits which should be ignored in the final byte.
uint8_t chroma_sample_loc_type_top_field
uint8_t vps_max_layers_minus1
static int vaapi_encode_h265_init_slice_params(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodeSlice *slice)
uint16_t conf_win_bottom_offset
H265RawNALUnitHeader nal_unit_header
static const VAAPIEncodeType vaapi_encode_type_h265
uint8_t nb_components
The number of components each pixel has, (1-4)
uint8_t scaling_list_enabled_flag
H265RawProfileTierLevel profile_tier_level
uint8_t general_max_422chroma_constraint_flag
uint8_t transquant_bypass_enabled_flag
int width
picture width / height.
uint8_t general_intra_constraint_flag
uint32_t vps_max_latency_increase_plus1[HEVC_MAX_SUB_LAYERS]
uint8_t vui_hrd_parameters_present_flag
uint16_t delta_poc_s1_minus1[HEVC_MAX_REFS]
uint8_t diff_cu_qp_delta_depth
#define FF_PROFILE_UNKNOWN
const VAAPIEncodeProfile * profiles
av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
AVCodec ff_hevc_vaapi_encoder
static void bit_depth(AudioStatsContext *s, uint64_t mask, uint64_t imask, AVRational *depth)
uint8_t general_non_packed_constraint_flag
uint8_t sps_seq_parameter_set_id
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
struct VAAPIEncodePicture * next
uint16_t pic_width_in_luma_samples
void * codec_picture_params
static int vaapi_encode_h265_init_picture_params(AVCodecContext *avctx, VAAPIEncodePicture *pic)
uint8_t vps_base_layer_available_flag
uint8_t log2_min_luma_coding_block_size_minus3
uint8_t * data
Pointer to the bitstream form of this fragment.
uint8_t pps_seq_parameter_set_id
#define FF_ARRAY_ELEMS(a)
the normal 2^n-1 "JPEG" YUV ranges
int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Write the content of the fragment to its own internal buffer.
uint16_t vps_num_hrd_parameters
uint8_t general_max_420chroma_constraint_flag
struct VAAPIEncodePicture * refs[MAX_PICTURE_REFERENCES]
uint8_t used_by_curr_pic_s1_flag[HEVC_MAX_REFS]
const H265LevelDescriptor * ff_h265_guess_level(const H265RawProfileTierLevel *ptl, int64_t bitrate, int width, int height, int slice_segments, int tile_rows, int tile_cols, int max_dec_pic_buffering)
Guess the level of a stream from some parameters.
uint8_t max_bytes_per_pic_denom
H265RawNALUnitHeader nal_unit_header
static int vaapi_encode_h265_write_slice_header(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodeSlice *slice, char *data, size_t *data_len)
const struct VAAPIEncodeType * codec
uint8_t log2_diff_max_min_pcm_luma_coding_block_size
Libavcodec external API header.
uint8_t entropy_coding_sync_enabled_flag
uint8_t weighted_bipred_flag
uint16_t conf_win_top_offset
uint8_t sps_temporal_mvp_enabled_flag
VAAPIEncodePicture * pic_start
Coded bitstream fragment structure, combining one or more units.
uint8_t general_level_idc
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
main external API structure.
uint32_t vui_num_units_in_tick
uint8_t max_transform_hierarchy_depth_intra
uint8_t pps_loop_filter_across_slices_enabled_flag
uint8_t weighted_pred_flag
uint8_t sps_temporal_id_nesting_flag
H265RawSEIMasteringDisplayColourVolume mastering_display
static int FUNC() aud(CodedBitstreamContext *ctx, RWContext *rw, H264RawAUD *current)
uint16_t conf_win_left_offset
Describe the class of an AVClass context structure.
static int FUNC() pps(CodedBitstreamContext *ctx, RWContext *rw, H264RawPPS *current)
uint32_t max_display_mastering_luminance
Context structure for coded bitstream operations.
enum AVColorSpace colorspace
YUV colorspace type.
Rational number (pair of numerator and denominator).
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
uint8_t general_max_10bit_constraint_flag
static int vaapi_encode_h265_write_extra_header(AVCodecContext *avctx, VAAPIEncodePicture *pic, int index, int *type, char *data, size_t *data_len)
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
uint8_t chroma_format_idc
void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
float b_quant_offset
qscale offset between IP and B-frames
uint8_t general_lower_bit_rate_constraint_flag
uint8_t general_profile_compatibility_flag[32]
uint8_t vps_base_layer_internal_flag
static enum AVPixelFormat pix_fmts[]
static int FUNC() vps(CodedBitstreamContext *ctx, RWContext *rw, H265RawVPS *current)
uint8_t pcm_loop_filter_disabled_flag
H265RawNALUnitHeader nal_unit_header
#define VAAPI_ENCODE_COMMON_OPTIONS
static int vaapi_encode_h265_write_sequence_header(AVCodecContext *avctx, char *data, size_t *data_len)
uint8_t num_positive_pics
uint8_t general_frame_only_constraint_flag
static const VAAPIEncodeProfile vaapi_encode_h265_profiles[]
uint8_t vui_poc_proportional_to_timing_flag
uint8_t general_progressive_source_flag
uint8_t max_transform_hierarchy_depth_inter
static av_cold int vaapi_encode_h265_configure(AVCodecContext *avctx)
VAAPIEncodeContext common
common internal api header.
common internal and external API header
static int ref[MAX_W *MAX_W]
uint8_t pps_scaling_list_data_present_flag
uint8_t num_tile_rows_minus1
int ff_vaapi_encode2(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *input_image, int *got_packet)
static int FUNC() sei(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEI *current)
uint8_t num_tile_columns_minus1
uint16_t delta_poc_s0_minus1[HEVC_MAX_REFS]
uint8_t log2_diff_max_min_luma_coding_block_size
CodedBitstreamFragment current_access_unit
#define FF_PROFILE_HEVC_REXT
uint8_t vps_max_num_reorder_pics[HEVC_MAX_SUB_LAYERS]
H265RawSliceHeader header
H265RawSEIMasteringDisplayColourVolume sei_mastering_display
uint8_t num_short_term_ref_pic_sets
void * codec_slice_params
uint8_t log2_parallel_merge_level_minus2
uint8_t vps_temporal_id_nesting_flag
unsigned int desired_packed_headers
#define LEVEL(name, value)
uint8_t general_profile_space
uint8_t sps_max_dec_pic_buffering_minus1[HEVC_MAX_SUB_LAYERS]
uint32_t vps_num_ticks_poc_diff_one_minus1
int depth
Number of bits in the component.
uint8_t separate_colour_plane_flag
uint8_t strong_intra_smoothing_enabled_flag
uint8_t colour_description_present_flag
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
AVPixelFormat
Pixel format.
unsigned MaxFALL
Max average light level per frame (cd/m^2).
uint8_t log2_diff_max_min_luma_transform_block_size
uint8_t long_term_ref_pics_present_flag
uint8_t layer_id_included_flag[HEVC_MAX_LAYER_SETS][HEVC_MAX_LAYERS]
av_cold int ff_vaapi_encode_close(AVCodecContext *avctx)
uint8_t num_ref_idx_l1_default_active_minus1
H265RawNALUnitHeader nal_unit_header
uint8_t cu_qp_delta_enabled_flag