Go to the documentation of this file.
22 #include <va/va_enc_av1.h>
33 #define AV1_MAX_QUANT 255
46 VAConfigAttribValEncAV1
attr;
91 const char *str,
const int *subscripts,
100 if (!strcmp(str,
"base_q_idx"))
102 else if (!strcmp(str,
"loop_filter_level[0]"))
104 else if (!strcmp(str,
"cdef_damping_minus_3"))
106 else if (!strcmp(str,
"cdef_uv_sec_strength[i]"))
136 if (
ctx->rc_mode->quality) {
174 "type = %d.\n",
type);
182 char *
data,
size_t *data_len,
194 if ((
size_t)8 * MAX_PARAM_BUFFER_SIZE < 8 * bs->data_size - bs->
data_bit_padding) {
209 for (k = 0; (blkSize << k) < target; k++);
216 int mi_cols, mi_rows, sb_shift, sb_size;
217 int max_tile_area_sb, max_tile_area_sb_varied;
218 int tile_width_sb, tile_height_sb, widest_tile_sb;
230 mi_cols = 2 * ((avctx->
width + 7) >> 3);
231 mi_rows = 2 * ((avctx->
height + 7) >> 3);
233 ((mi_cols + 31) >> 5) : ((mi_cols + 15) >> 4);
235 ((mi_rows + 31) >> 5) : ((mi_rows + 15) >> 4);
237 sb_size = sb_shift + 2;
274 if ((priv->
sb_cols + tile_width_sb - 1) / tile_width_sb == priv->
tile_cols) {
283 tile_height_sb <= max_tile_area_sb / tile_width_sb) {
303 max_tile_area_sb_varied = (priv->
sb_rows * priv->
sb_cols) >> (min_log2_tiles + 1);
327 if (priv->
attr_ext2.bits.max_tile_num_minus1) {
332 priv->
attr_ext2.bits.max_tile_num_minus1 + 1);
348 char *
data,
size_t *data_len)
364 VAEncSequenceParameterBufferAV1 *vseq =
ctx->codec_sequence_params;
369 memset(sh_obu, 0,
sizeof(*sh_obu));
390 .transfer_characteristics = avctx->
color_trc,
396 .subsampling_x =
desc->log2_chroma_w,
397 .subsampling_y =
desc->log2_chroma_h,
424 ctx->surface_width,
ctx->surface_height,
432 "any normal level, using maximum parameters level by default.\n");
441 vseq->intra_period =
ctx->gop_size;
442 vseq->ip_period =
ctx->b_per_p + 1;
446 if (!(
ctx->va_rc_mode & VA_RC_CQP)) {
447 vseq->bits_per_second =
ctx->va_bit_rate;
448 vseq->seq_fields.bits.enable_cdef = sh->
enable_cdef = 1;
479 { 1, 0, 0, 0, -1, 0, -1, -1 };
481 memset(fh_obu, 0,
sizeof(*fh_obu));
501 href =
ref->priv_data;
517 href =
ref->priv_data;
531 vpic->picture_flags.bits.disable_frame_recon = 1;
538 href =
ref->priv_data;
547 href =
ref->priv_data;
572 if (priv->
attr_ext2.bits.tx_mode_support & 0x04)
574 else if (priv->
attr_ext2.bits.tx_mode_support & 0x02)
606 #if VA_CHECK_VERSION(1, 15, 0)
610 vpic->picture_flags.bits.enable_frame_obu = 0;
611 vpic->picture_flags.bits.frame_type = fh->
frame_type;
616 vpic->mode_control_flags.bits.reference_mode = fh->
reference_select ? 2 : 0;
617 vpic->mode_control_flags.bits.tx_mode = fh->
tx_mode;
619 vpic->tile_group_obu_hdr_info.bits.obu_has_size_field = 1;
626 vpic->reference_frames[
i] = VA_INVALID_SURFACE;
629 for (
int j = 0; j < pic->
nb_refs[
i]; j++) {
633 av_assert0(vpic->reference_frames[slot] == VA_INVALID_SURFACE);
647 if (!(
ctx->va_rc_mode & VA_RC_CQP)) {
655 vpic->size_in_bits_frame_hdr_obu = priv->
fh_data_len;
678 vslice->tg_start = slice->
index * div;
683 vslice->tg_end = (slice->
index + 1) * div - 1;
691 char *
data,
size_t *data_len)
704 memset(fh_obu, 0,
sizeof(*fh_obu));
747 .default_quality = 25,
752 .sequence_header_type = VAEncPackedHeaderSequence,
753 .sequence_params_size =
sizeof(VAEncSequenceParameterBufferAV1),
758 .picture_header_type = VAEncPackedHeaderPicture,
759 .picture_params_size =
sizeof(VAEncPictureParameterBufferAV1),
763 .slice_params_size =
sizeof(VAEncTileGroupBufferAV1),
777 ctx->desired_packed_headers =
778 VA_ENC_PACKED_HEADER_SEQUENCE |
779 VA_ENC_PACKED_HEADER_PICTURE;
795 attr.type = VAConfigAttribEncAV1;
796 vas = vaGetConfigAttributes(
ctx->hwctx->display,
800 if (vas != VA_STATUS_SUCCESS) {
802 "config attribute: %d (%s).\n", vas, vaErrorStr(vas));
804 }
else if (attr.value == VA_ATTRIB_NOT_SUPPORTED) {
805 priv->
attr.value = 0;
807 "supported.\n", attr.type);
809 priv->
attr.value = attr.value;
812 attr.type = VAConfigAttribEncAV1Ext1;
813 vas = vaGetConfigAttributes(
ctx->hwctx->display,
817 if (vas != VA_STATUS_SUCCESS) {
819 "config attribute: %d (%s).\n", vas, vaErrorStr(vas));
821 }
else if (attr.value == VA_ATTRIB_NOT_SUPPORTED) {
824 "supported.\n", attr.type);
830 attr.type = VAConfigAttribEncAV1Ext2;
831 vas = vaGetConfigAttributes(
ctx->hwctx->display,
835 if (vas != VA_STATUS_SUCCESS || attr.value == VA_ATTRIB_NOT_SUPPORTED) {
837 "config attribute: %d (%s).\n", vas, vaErrorStr(vas));
844 priv->
attr_ext2.bits.obu_size_bytes_minus1 + 1, 0);
863 #define OFFSET(x) offsetof(VAAPIEncodeAV1Context, x)
864 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
869 {
"profile",
"Set profile (seq_profile)",
873 #define PROFILE(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
874 { .i64 = value }, 0, 0, FLAGS, .unit = "profile"
880 {
"tier",
"Set tier (seq_tier)",
883 { .i64 = 0 }, 0, 0,
FLAGS, .unit =
"tier" },
885 { .i64 = 1 }, 0, 0,
FLAGS, .unit =
"tier" },
886 {
"level",
"Set level (seq_level_idx)",
890 #define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
891 { .i64 = value }, 0, 0, FLAGS, .unit = "level"
898 {
LEVEL(
"5.0", 12) },
899 {
LEVEL(
"5.1", 13) },
900 {
LEVEL(
"5.2", 14) },
901 {
LEVEL(
"5.3", 15) },
902 {
LEVEL(
"6.0", 16) },
903 {
LEVEL(
"6.1", 17) },
904 {
LEVEL(
"6.2", 18) },
905 {
LEVEL(
"6.3", 19) },
908 {
"tiles",
"Tile columns x rows (Use minimal tile column/row number automatically by default)",
910 {
"tile_groups",
"Number of tile groups for encoding",
933 .
p.
name =
"av1_vaapi",
952 .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)
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 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]
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
static int vaapi_encode_av1_init_slice_params(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodeSlice *slice)
av_cold void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
struct VAAPIEncodePicture * refs[MAX_REFERENCE_LIST_NUM][MAX_PICTURE_REFERENCES]
int nb_refs[MAX_REFERENCE_LIST_NUM]
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.
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.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
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.
#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
offset must point to two consecutive integers
const char * av_default_item_name(void *ptr)
Return the context name.
uint8_t chroma_sample_position
VAConfigAttribValEncAV1Ext2 attr_ext2
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
AV1RawSequenceHeader sequence_header
uint8_t * data
Pointer to the bitstream form of this fragment.
CBSTraceWriteCallback trace_write_callback
Callback for write tracing.
@ AV1_TOTAL_REFS_PER_FRAME
@ AV1_OBU_SEQUENCE_HEADER
static const AVOption vaapi_encode_av1_options[]
#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...
@ FLAG_TIMESTAMP_NO_DELAY
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)
AVHWFramesContext * input_frames
size_t sh_data_len
bit length of sh_data.
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
const char * name
Name of the codec implementation.
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
static int vaapi_encode_av1_write_picture_header(AVCodecContext *avctx, VAAPIEncodePicture *pic, char *data, size_t *data_len)
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...
static int vaapi_encode_av1_init_picture_params(AVCodecContext *avctx, VAAPIEncodePicture *pic)
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
float i_quant_offset
qscale offset between P and I-frames
static int ref[MAX_W *MAX_W]
#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.
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
int width
picture width / height.
#define AV_PROFILE_AV1_MAIN
static av_cold int vaapi_encode_av1_configure(AVCodecContext *avctx)
#define LEVEL(name, value)
#define PROFILE(name, value)