Go to the documentation of this file.
22 #include <va/va_enc_av1.h>
34 #define AV1_MAX_QUANT 255
49 VAConfigAttribValEncAV1
attr;
94 const char *str,
const int *subscripts,
103 if (!strcmp(str,
"base_q_idx"))
105 else if (!strcmp(str,
"loop_filter_level[0]"))
107 else if (!strcmp(str,
"cdef_damping_minus_3"))
109 else if (!strcmp(str,
"cdef_uv_sec_strength[i]"))
139 if (
ctx->rc_mode->quality) {
177 "type = %d.\n",
type);
185 char *
data,
size_t *data_len,
197 if ((
size_t)8 * MAX_PARAM_BUFFER_SIZE < 8 * bs->data_size - bs->
data_bit_padding) {
212 for (k = 0; (blkSize << k) < target; k++);
219 int mi_cols, mi_rows, sb_shift, sb_size;
220 int max_tile_area_sb, max_tile_area_sb_varied;
221 int tile_width_sb, tile_height_sb, widest_tile_sb;
233 mi_cols = 2 * ((avctx->
width + 7) >> 3);
234 mi_rows = 2 * ((avctx->
height + 7) >> 3);
236 ((mi_cols + 31) >> 5) : ((mi_cols + 15) >> 4);
238 ((mi_rows + 31) >> 5) : ((mi_rows + 15) >> 4);
240 sb_size = sb_shift + 2;
277 if ((priv->
sb_cols + tile_width_sb - 1) / tile_width_sb == priv->
tile_cols) {
286 tile_height_sb <= max_tile_area_sb / tile_width_sb) {
306 max_tile_area_sb_varied = (priv->
sb_rows * priv->
sb_cols) >> (min_log2_tiles + 1);
330 if (priv->
attr_ext2.bits.max_tile_num_minus1) {
335 priv->
attr_ext2.bits.max_tile_num_minus1 + 1);
351 char *
data,
size_t *data_len)
368 VAEncSequenceParameterBufferAV1 *vseq =
ctx->codec_sequence_params;
373 memset(sh_obu, 0,
sizeof(*sh_obu));
394 .transfer_characteristics = avctx->
color_trc,
400 .subsampling_x =
desc->log2_chroma_w,
401 .subsampling_y =
desc->log2_chroma_h,
436 "any normal level, using maximum parameters level by default.\n");
445 vseq->intra_period = base_ctx->
gop_size;
446 vseq->ip_period = base_ctx->
b_per_p + 1;
450 if (!(
ctx->va_rc_mode & VA_RC_CQP)) {
451 vseq->bits_per_second =
ctx->va_bit_rate;
452 vseq->seq_fields.bits.enable_cdef = sh->
enable_cdef = 1;
484 { 1, 0, 0, 0, -1, 0, -1, -1 };
486 memset(fh_obu, 0,
sizeof(*fh_obu));
506 href =
ref->codec_priv;
522 href =
ref->codec_priv;
536 vpic->picture_flags.bits.disable_frame_recon = 1;
543 href =
ref->codec_priv;
552 href =
ref->codec_priv;
577 if (priv->
attr_ext2.bits.tx_mode_support & 0x04)
579 else if (priv->
attr_ext2.bits.tx_mode_support & 0x02)
611 #if VA_CHECK_VERSION(1, 15, 0)
615 vpic->picture_flags.bits.enable_frame_obu = 0;
616 vpic->picture_flags.bits.frame_type = fh->
frame_type;
621 vpic->mode_control_flags.bits.reference_mode = fh->
reference_select ? 2 : 0;
622 vpic->mode_control_flags.bits.tx_mode = fh->
tx_mode;
624 vpic->tile_group_obu_hdr_info.bits.obu_has_size_field = 1;
631 vpic->reference_frames[
i] = VA_INVALID_SURFACE;
634 for (
int j = 0; j < pic->
nb_refs[
i]; j++) {
638 av_assert0(vpic->reference_frames[slot] == VA_INVALID_SURFACE);
652 if (!(
ctx->va_rc_mode & VA_RC_CQP)) {
660 vpic->size_in_bits_frame_hdr_obu = priv->
fh_data_len;
680 const int chroma_den = 1 << 16;
681 const int max_luma_den = 1 << 8;
682 const int min_luma_den = 1 << 14;
684 memset(obu, 0,
sizeof(*obu));
688 for (
i = 0;
i < 3;
i++) {
721 memset(obu, 0,
sizeof(*obu));
724 cll->max_cll = cllm->
MaxCLL;
745 vslice->tg_start = slice->
index * div;
750 vslice->tg_end = (slice->
index + 1) * div - 1;
758 char *
data,
size_t *data_len)
772 memset(fh_obu, 0,
sizeof(*fh_obu));
809 char *
data,
size_t *data_len)
831 *data_len = mh_data_len;
832 *
type = VAEncPackedHeaderRawData;
848 .default_quality = 25,
853 .sequence_header_type = VAEncPackedHeaderSequence,
854 .sequence_params_size =
sizeof(VAEncSequenceParameterBufferAV1),
859 .picture_header_type = VAEncPackedHeaderPicture,
860 .picture_params_size =
sizeof(VAEncPictureParameterBufferAV1),
864 .slice_params_size =
sizeof(VAEncTileGroupBufferAV1),
880 ctx->desired_packed_headers =
881 VA_ENC_PACKED_HEADER_SEQUENCE |
882 VA_ENC_PACKED_HEADER_PICTURE |
883 VA_ENC_PACKED_HEADER_MISC;
899 attr.type = VAConfigAttribEncAV1;
900 vas = vaGetConfigAttributes(
ctx->hwctx->display,
904 if (vas != VA_STATUS_SUCCESS) {
906 "config attribute: %d (%s).\n", vas, vaErrorStr(vas));
908 }
else if (attr.value == VA_ATTRIB_NOT_SUPPORTED) {
909 priv->
attr.value = 0;
911 "supported.\n", attr.type);
913 priv->
attr.value = attr.value;
916 attr.type = VAConfigAttribEncAV1Ext1;
917 vas = vaGetConfigAttributes(
ctx->hwctx->display,
921 if (vas != VA_STATUS_SUCCESS) {
923 "config attribute: %d (%s).\n", vas, vaErrorStr(vas));
925 }
else if (attr.value == VA_ATTRIB_NOT_SUPPORTED) {
928 "supported.\n", attr.type);
934 attr.type = VAConfigAttribEncAV1Ext2;
935 vas = vaGetConfigAttributes(
ctx->hwctx->display,
939 if (vas != VA_STATUS_SUCCESS || attr.value == VA_ATTRIB_NOT_SUPPORTED) {
941 "config attribute: %d (%s).\n", vas, vaErrorStr(vas));
948 priv->
attr_ext2.bits.obu_size_bytes_minus1 + 1, 0);
967 #define OFFSET(x) offsetof(VAAPIEncodeAV1Context, x)
968 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
974 {
"profile",
"Set profile (seq_profile)",
978 #define PROFILE(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
979 { .i64 = value }, 0, 0, FLAGS, .unit = "profile"
985 {
"tier",
"Set tier (seq_tier)",
988 { .i64 = 0 }, 0, 0,
FLAGS, .unit =
"tier" },
990 { .i64 = 1 }, 0, 0,
FLAGS, .unit =
"tier" },
991 {
"level",
"Set level (seq_level_idx)",
995 #define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
996 { .i64 = value }, 0, 0, FLAGS, .unit = "level"
1000 {
LEVEL(
"3.1", 5) },
1001 {
LEVEL(
"4.0", 8) },
1002 {
LEVEL(
"4.1", 9) },
1003 {
LEVEL(
"5.0", 12) },
1004 {
LEVEL(
"5.1", 13) },
1005 {
LEVEL(
"5.2", 14) },
1006 {
LEVEL(
"5.3", 15) },
1007 {
LEVEL(
"6.0", 16) },
1008 {
LEVEL(
"6.1", 17) },
1009 {
LEVEL(
"6.2", 18) },
1010 {
LEVEL(
"6.3", 19) },
1013 {
"tiles",
"Tile columns x rows (Use minimal tile column/row number automatically by default)",
1015 {
"tile_groups",
"Number of tile groups for encoding",
1038 .
p.
name =
"av1_vaapi",
1058 .p.wrapper_name =
"vaapi",
static av_cold int vaapi_encode_av1_init(AVCodecContext *avctx)
#define AV_LOG_WARNING
Something somehow does not look correct.
void * codec_slice_params
AVPixelFormat
Pixel format.
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
void * priv_data
Internal codec-specific data.
enum AVColorSpace colorspace
YUV colorspace type.
const FFCodec ff_av1_vaapi_encoder
static int tile_log2(int blkSize, int target)
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
av_cold void ff_cbs_fragment_free(CodedBitstreamFragment *frag)
Free the units array of a fragment in addition to what ff_cbs_fragment_reset does.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AVERROR_EOF
End of file.
#define AV_CODEC_CAP_HARDWARE
Codec is backed by a hardware implementation.
size_t tail_size
Byte length of tail_data.
int ff_cbs_insert_unit_content(CodedBitstreamFragment *frag, int position, CodedBitstreamUnitType type, void *content, void *content_ref)
Insert a new unit into a fragment with the given content.
const AV1LevelDescriptor * ff_av1_guess_level(int64_t bitrate, int tier, int width, int height, int tiles, int tile_cols, float fps)
Guess the level of a stream from some parameters.
uint8_t height_in_sbs_minus_1[AV1_MAX_TILE_ROWS]
unsigned MaxCLL
Max content light level (cd/m^2).
char fh_data[MAX_PARAM_BUFFER_SIZE]
coded frame header data.
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
@ AVCOL_RANGE_JPEG
Full range content.
void ff_cbs_fragment_reset(CodedBitstreamFragment *frag)
Free the units contained in a fragment as well as the fragment's own data buffer, but not the units a...
Context structure for coded bitstream operations.
static int vaapi_encode_av1_set_tile(AVCodecContext *avctx)
CodedBitstreamFragment current_obu
float b_quant_offset
qscale offset between IP and B-frames
#define FF_CODEC_CAP_NOT_INIT_THREADSAFE
The codec is not known to be init-threadsafe (i.e.
#define AV_LOG_VERBOSE
Detailed information.
AV1RawOBU fh
frame header.
av_cold int ff_vaapi_encode_close(AVCodecContext *avctx)
#define AV_PROFILE_AV1_PROFESSIONAL
int qmax
maximum quantizer
VAAPIEncodeContext common
int qindex_offset
bit positions in current frame header
av_cold void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
float i_quant_factor
qscale factor between P- and I-frames If > 0 then the last P-frame quantizer will be used (q = lastp_...
AVCodec p
The public AVCodec.
static const VAAPIEncodeProfile vaapi_encode_av1_profiles[]
int non_independent_frame
indicate if current frame is an independent frame that the coded data can be pushed to downstream dir...
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
int trace_level
Log level to use for default trace output.
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
#define AV_PROFILE_UNKNOWN
static int vaapi_encode_av1_init_sequence_params(AVCodecContext *avctx)
void * codec_picture_params
Coded bitstream fragment structure, combining one or more units.
#define FLAG_TIMESTAMP_NO_DELAY
uint8_t width_in_sbs_minus_1[AV1_MAX_TILE_COLS]
size_t data_size
The number of bytes in the bitstream.
static int vaapi_encode_av1_write_sequence_header(AVCodecContext *avctx, char *data, size_t *data_len)
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
@ AV1_METADATA_TYPE_HDR_CLL
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static int vaapi_encode_av1_init_picture_params(AVCodecContext *avctx, FFHWBaseEncodePicture *pic)
int ff_vaapi_encode_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
size_t data_bit_padding
The number of bits which should be ignored in the final byte.
static int vaapi_encode_av1_init_slice_params(AVCodecContext *avctx, FFHWBaseEncodePicture *base, VAAPIEncodeSlice *slice)
#define CODEC_LONG_NAME(str)
static void vaapi_encode_av1_trace_write_log(void *ctx, PutBitContext *pbc, int length, const char *str, const int *subscripts, int64_t value)
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
static __device__ float fabs(float a)
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
enum AVColorRange color_range
MPEG vs JPEG YUV range.
void * trace_context
User context pointer to pass to trace callbacks.
@ AVCHROMA_LOC_LEFT
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
const VAAPIEncodeProfile * profiles
@ AVCHROMA_LOC_TOPLEFT
ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2.
static int vaapi_encode_av1_add_obu(AVCodecContext *avctx, CodedBitstreamFragment *au, uint8_t type, void *obu_unit)
#define FF_CODEC_RECEIVE_PACKET_CB(func)
int64_t bit_rate
the average bitrate
@ AV_OPT_TYPE_IMAGE_SIZE
Underlying C type is two consecutive integers.
const char * av_default_item_name(void *ptr)
Return the context name.
uint8_t chroma_sample_position
VAConfigAttribValEncAV1Ext2 attr_ext2
@ AV_FRAME_DATA_MASTERING_DISPLAY_METADATA
Mastering display metadata associated with a video frame.
CodedBitstreamContext * cbc
int level
Encoding level descriptor.
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
static av_cold int vaapi_encode_av1_close(AVCodecContext *avctx)
AV1RawOBU sh
sequence header.
int(* init)(AVBSFContext *ctx)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
VAConfigAttribValEncAV1Ext1 attr_ext1
#define VAAPI_ENCODE_RC_OPTIONS
int nb_refs[MAX_REFERENCE_LIST_NUM]
AV1RawSequenceHeader sequence_header
uint8_t * data
Pointer to the bitstream form of this fragment.
CBSTraceWriteCallback trace_write_callback
Callback for write tracing.
@ AV1_OBU_SEQUENCE_HEADER
static const AVOption vaapi_encode_av1_options[]
@ AV1_METADATA_TYPE_HDR_MDCV
#define VAAPI_ENCODE_COMMON_OPTIONS
VASurfaceID recon_surface
uint8_t use_128x128_superblock
#define AVERROR_EXTERNAL
Generic error in an external library.
#define AV_PROFILE_AV1_HIGH
@ AV_PIX_FMT_VAAPI
Hardware acceleration through VA-API, data[3] contains a VASurfaceID.
AV1RawFrameHeader frame_header
static const AVClass vaapi_encode_av1_class
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...
AV1RawOBU mh[4]
metadata header.
@ AV_FRAME_DATA_CONTENT_LIGHT_LEVEL
Content light level (based on CTA-861.3).
char sh_data[MAX_PARAM_BUFFER_SIZE]
coded sequence header data.
#define i(width, name, range_min, range_max)
static int put_bits_count(PutBitContext *s)
size_t sh_data_len
bit length of sh_data.
#define MAX_REFERENCE_LIST_NUM
static const VAAPIEncodeType vaapi_encode_type_av1
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
struct FFHWBaseEncodePicture * refs[MAX_REFERENCE_LIST_NUM][MAX_PICTURE_REFERENCES]
static int vaapi_encode_av1_write_extra_header(AVCodecContext *avctx, FFHWBaseEncodePicture *base_pic, int index, int *type, char *data, size_t *data_len)
const char * name
Name of the codec implementation.
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Write the content of the fragment to its own internal buffer.
char tail_data[MAX_PARAM_BUFFER_SIZE]
Tail data of current pic, used only for repeat header of AV1.
const AVCodecHWConfigInternal *const ff_vaapi_encode_hw_configs[]
av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
@ AV1_TOTAL_REFS_PER_FRAME
static int vaapi_encode_av1_write_obu(AVCodecContext *avctx, char *data, size_t *data_len, CodedBitstreamFragment *bs)
static av_cold int vaapi_encode_av1_get_encoder_caps(AVCodecContext *avctx)
size_t fh_data_len
bit length of fh_data.
static const FFCodecDefault vaapi_encode_av1_defaults[]
main external API structure.
int qmin
minimum quantizer
@ AV_OPT_TYPE_INT
Underlying C type is int.
float i_quant_offset
qscale offset between P and I-frames
static int ref[MAX_W *MAX_W]
AVHWFramesContext * input_frames
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
int trace_enable
Enable trace output during read/write operations.
Structure to hold side data for an AVFrame.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
av_cold int ff_cbs_init(CodedBitstreamContext **ctx_ptr, enum AVCodecID codec_id, void *log_ctx)
Create and initialise a new context for the given codec.
VAConfigAttribValEncAV1 attr
unsigned MaxFALL
Max average light level per frame (cd/m^2).
static int vaapi_encode_av1_write_picture_header(AVCodecContext *avctx, FFHWBaseEncodePicture *pic, char *data, size_t *data_len)
int width
picture width / height.
#define HW_BASE_ENCODE_COMMON_OPTIONS
#define AV_PROFILE_AV1_MAIN
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
static av_cold int vaapi_encode_av1_configure(AVCodecContext *avctx)
#define LEVEL(name, value)
#define PROFILE(name, value)