22 #include <va/va_enc_hevc.h>
72 char *
data,
size_t *data_len,
87 "%zu < %zu.\n", *data_len,
119 char *
data,
size_t *data_len)
154 char *
data,
size_t *data_len)
193 memset(vps, 0,
sizeof(*vps));
194 memset(sps, 0,
sizeof(*sps));
195 memset(pps, 0,
sizeof(*pps));
203 .nuh_temporal_id_plus1 = 1,
216 .general_profile_idc = avctx->
profile,
217 .general_tier_flag = 0,
219 .general_progressive_source_flag = 1,
220 .general_interlaced_source_flag = 0,
221 .general_non_packed_constraint_flag = 1,
222 .general_frame_only_constraint_flag = 1,
224 .general_level_idc = avctx->
level,
256 .nuh_temporal_id_plus1 = 1,
336 { 1, 1 }, { 12, 11 }, { 10, 11 }, { 16, 11 },
337 { 40, 33 }, { 24, 11 }, { 20, 11 }, { 32, 11 },
338 { 80, 33 }, { 18, 11 }, { 15, 11 }, { 64, 33 },
339 { 160, 99 }, { 4, 3 }, { 3, 2 }, { 2, 1 },
410 .nuh_temporal_id_plus1 = 1,
429 *vseq = (VAEncSequenceParameterBufferHEVC) {
435 .intra_idr_period = avctx->
gop_size,
448 .strong_intra_smoothing_enabled_flag =
451 .sample_adaptive_offset_enabled_flag =
458 .log2_min_luma_coding_block_size_minus3 =
460 .log2_diff_max_min_luma_coding_block_size =
462 .log2_min_transform_block_size_minus2 =
464 .log2_diff_max_min_transform_block_size =
466 .max_transform_hierarchy_depth_inter =
468 .max_transform_hierarchy_depth_intra =
471 .pcm_sample_bit_depth_luma_minus1 =
473 .pcm_sample_bit_depth_chroma_minus1 =
475 .log2_min_pcm_luma_coding_block_size_minus3 =
477 .log2_max_pcm_luma_coding_block_size_minus3 =
481 .vui_parameters_present_flag = 0,
484 *vpic = (VAEncPictureParameterBufferHEVC) {
485 .decoded_curr_pic = {
486 .picture_id = VA_INVALID_ID,
487 .flags = VA_PICTURE_HEVC_INVALID,
490 .coded_buf = VA_INVALID_ID,
492 .collocated_ref_pic_index = 0xff,
505 .ctu_max_bitsize_allowed = 0,
507 .num_ref_idx_l0_default_active_minus1 =
509 .num_ref_idx_l1_default_active_minus1 =
524 .loop_filter_across_tiles_enabled_flag =
528 .screen_content_flag = 0,
529 .enable_gpu_weighted_prediction = 0,
530 .no_output_of_prior_pics_flag = 0,
583 .nuh_temporal_id_plus1 = 1,
590 vpic->decoded_curr_pic = (VAPictureHEVC) {
596 for (i = 0; i < pic->
nb_refs; i++) {
600 vpic->reference_frames[i] = (VAPictureHEVC) {
604 VA_PICTURE_HEVC_RPS_ST_CURR_BEFORE : 0) |
606 VA_PICTURE_HEVC_RPS_ST_CURR_AFTER : 0),
610 vpic->reference_frames[i] = (VAPictureHEVC) {
611 .picture_id = VA_INVALID_ID,
612 .flags = VA_PICTURE_HEVC_INVALID,
622 vpic->pic_fields.bits.idr_pic_flag = 1;
623 vpic->pic_fields.bits.coding_type = 1;
624 vpic->pic_fields.bits.reference_pic_flag = 1;
627 vpic->pic_fields.bits.idr_pic_flag = 0;
628 vpic->pic_fields.bits.coding_type = 1;
629 vpic->pic_fields.bits.reference_pic_flag = 1;
632 vpic->pic_fields.bits.idr_pic_flag = 0;
633 vpic->pic_fields.bits.coding_type = 2;
634 vpic->pic_fields.bits.reference_pic_flag = 1;
637 vpic->pic_fields.bits.idr_pic_flag = 0;
638 vpic->pic_fields.bits.coding_type = 3;
639 vpic->pic_fields.bits.reference_pic_flag = 0;
666 .nuh_temporal_id_plus1 = 1,
688 memset(rps, 0,
sizeof(*rps));
696 for (i = 0; i < pic->
nb_refs; i++) {
697 if (pic->
refs[i] == st)
713 if (rp->
refs[0] == st && rp->
refs[1] == pic)
761 *vslice = (VAEncSliceParameterBufferHEVC) {
783 .slice_fields.bits = {
784 .last_slice_of_pic_flag = 1,
787 .slice_temporal_mvp_enabled_flag =
791 .num_ref_idx_active_override_flag =
795 .slice_deblocking_filter_disabled_flag =
797 .slice_loop_filter_across_slices_enabled_flag =
804 vslice->ref_pic_list0[i].picture_id = VA_INVALID_ID;
805 vslice->ref_pic_list0[i].flags = VA_PICTURE_HEVC_INVALID;
806 vslice->ref_pic_list1[i].picture_id = VA_INVALID_ID;
807 vslice->ref_pic_list1[i].flags = VA_PICTURE_HEVC_INVALID;
815 vslice->ref_pic_list0[0] = vpic->reference_frames[0];
820 vslice->ref_pic_list1[0] = vpic->reference_frames[1];
858 "%d / %d / %d for IDR- / P- / B-frames.\n",
869 ctx->
va_rc_mode == VA_RC_CBR ?
"constant" :
"variable",
884 .sequence_params_size =
sizeof(VAEncSequenceParameterBufferHEVC),
887 .picture_params_size =
sizeof(VAEncPictureParameterBufferHEVC),
890 .slice_params_size =
sizeof(VAEncSliceParameterBufferHEVC),
893 .sequence_header_type = VAEncPackedHeaderSequence,
896 .slice_header_type = VAEncPackedHeaderHEVC_Slice,
906 ctx->
codec = &vaapi_encode_type_h265;
920 #ifdef VA_RT_FORMAT_YUV420_10BPP
926 "supported with this VAAPI version.\n");
945 VA_ENC_PACKED_HEADER_SEQUENCE |
946 VA_ENC_PACKED_HEADER_SLICE;
965 #define OFFSET(x) (offsetof(VAAPIEncodeContext, codec_options_data) + \
966 offsetof(VAAPIEncodeH265Options, x))
967 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
969 {
"qp",
"Constant QP (for P-frames; scaled by qfactor/qoffset for I/B)",
972 {
"aud",
"Include AUD",
975 {
"profile",
"Set profile (general_profile_idc)",
979 #define PROFILE(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
980 { .i64 = value }, 0, 0, FLAGS, "profile"
985 {
"level",
"Set level (general_level_idc)",
987 { .i64 = 153 }, 0x00, 0xff,
FLAGS,
"level" },
989 #define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
990 { .i64 = value }, 0, 0, FLAGS, "level"
993 {
LEVEL(
"2.1", 63) },
995 {
LEVEL(
"3.1", 93) },
997 {
LEVEL(
"4.1", 123) },
999 {
LEVEL(
"5.1", 153) },
1000 {
LEVEL(
"5.2", 156) },
1001 {
LEVEL(
"6", 180) },
1002 {
LEVEL(
"6.1", 183) },
1003 {
LEVEL(
"6.2", 186) },
1013 {
"i_qfactor",
"1" },
1014 {
"i_qoffset",
"0" },
1015 {
"b_qfactor",
"6/5" },
1016 {
"b_qoffset",
"0" },
1028 .
name =
"hevc_vaapi",
1037 .priv_class = &vaapi_encode_h265_class,
1039 .
defaults = vaapi_encode_h265_defaults,
1044 .wrapper_name =
"vaapi",
uint8_t sps_video_parameter_set_id
uint8_t loop_filter_across_tiles_enabled_flag
uint8_t transfer_characteristics
uint8_t pps_pic_parameter_set_id
uint8_t vps_poc_proportional_to_timing_flag
uint8_t num_ref_idx_l0_default_active_minus1
VAEntrypoint va_entrypoint
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
char codec_options_data[0]
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.
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.
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
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 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...
unsigned int va_packed_headers
uint32_t vps_num_units_in_tick
uint8_t sign_data_hiding_enabled_flag
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.
uint16_t pic_height_in_luma_samples
uint8_t vps_sub_layer_ordering_info_present_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]
uint8_t matrix_coefficients
uint8_t aspect_ratio_info_present_flag
uint8_t vps_max_sub_layers_minus1
#define AV_LOG_VERBOSE
Detailed information.
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
uint8_t vps_video_parameter_set_id
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void ff_cbs_fragment_uninit(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Free all allocated memory in a fragment.
uint8_t conformance_window_flag
uint8_t max_bits_per_min_cu_denom
static av_cold int vaapi_encode_h265_init(AVCodecContext *avctx)
#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[]
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 scaling_list_enabled_flag
H265RawProfileTierLevel profile_tier_level
uint8_t transquant_bypass_enabled_flag
int width
picture width / height.
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
av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
AVCodec ff_hevc_vaapi_encoder
uint8_t sps_seq_parameter_set_id
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
unsigned int va_rt_format
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
struct VAAPIEncodePicture * refs[MAX_PICTURE_REFERENCES]
uint8_t used_by_curr_pic_s1_flag[HEVC_MAX_REFS]
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
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
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)
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.
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_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
static int vaapi_encode_h265_write_sequence_header(AVCodecContext *avctx, char *data, size_t *data_len)
uint8_t num_positive_pics
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
uint8_t vui_poc_proportional_to_timing_flag
uint8_t max_transform_hierarchy_depth_inter
static av_cold int vaapi_encode_h265_configure(AVCodecContext *avctx)
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)
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
uint8_t vps_max_num_reorder_pics[HEVC_MAX_SUB_LAYERS]
H265RawSliceHeader header
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
#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
uint8_t separate_colour_plane_flag
uint8_t strong_intra_smoothing_enabled_flag
uint8_t colour_description_present_flag
AVPixelFormat
Pixel format.
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)
int64_t rc_max_rate
maximum bitrate
uint8_t num_ref_idx_l1_default_active_minus1
uint8_t cu_qp_delta_enabled_flag