Go to the documentation of this file.
20 #include <va/va_enc_mpeg2.h>
69 char *
data,
size_t *data_len,
83 "%zu < %zu.\n", *data_len,
103 "type = %d.\n",
type);
111 char *
data,
size_t *data_len)
145 char *
data,
size_t *data_len)
177 VAEncSequenceParameterBufferMPEG2 *vseq =
ctx->codec_sequence_params;
178 VAEncPictureParameterBufferMPEG2 *vpic =
ctx->codec_picture_params;
179 int code, ext_n, ext_d;
181 memset(sh, 0,
sizeof(*sh));
182 memset(
se, 0,
sizeof(*
se));
183 memset(sde, 0,
sizeof(*sde));
184 memset(goph, 0,
sizeof(*goph));
185 memset(
ph, 0,
sizeof(*
ph));
186 memset(pce, 0,
sizeof(*pce));
189 if (
ctx->va_bit_rate > 0) {
203 switch (avctx->
level) {
231 (
AVRational) { avctx->width, avctx->height });
243 "representable, signalling square pixels instead.\n",
258 &
code, &ext_n, &ext_d, 0);
275 se->profile_and_level_indication = avctx->
profile << 4 | avctx->
level;
276 se->progressive_sequence = 1;
277 se->chroma_format = 1;
279 se->horizontal_size_extension = avctx->
width >> 12;
280 se->vertical_size_extension = avctx->
height >> 12;
282 se->bit_rate_extension = priv->
bit_rate >> 18;
284 se->low_delay =
ctx->b_per_p == 0;
286 se->frame_rate_extension_n = ext_n;
287 se->frame_rate_extension_d = ext_d;
326 ph->vbv_delay = 0xffff;
328 ph->full_pel_forward_vector = 0;
329 ph->forward_f_code = 7;
330 ph->full_pel_backward_vector = 0;
331 ph->forward_f_code = 7;
355 *vseq = (VAEncSequenceParameterBufferMPEG2) {
356 .intra_period =
ctx->gop_size,
357 .ip_period =
ctx->b_per_p + 1,
359 .picture_width = avctx->
width,
360 .picture_height = avctx->
height,
362 .bits_per_second =
ctx->va_bit_rate,
367 .sequence_extension.bits = {
368 .profile_and_level_indication =
se->profile_and_level_indication,
369 .progressive_sequence =
se->progressive_sequence,
370 .chroma_format =
se->chroma_format,
371 .low_delay =
se->low_delay,
372 .frame_rate_extension_n =
se->frame_rate_extension_n,
373 .frame_rate_extension_d =
se->frame_rate_extension_d,
384 *vpic = (VAEncPictureParameterBufferMPEG2) {
385 .forward_reference_picture = VA_INVALID_ID,
386 .backward_reference_picture = VA_INVALID_ID,
387 .reconstructed_picture = VA_INVALID_ID,
388 .coded_buf = VA_INVALID_ID,
391 .f_code = { { 15, 15 }, { 15, 15 } },
393 .picture_coding_extension.bits = {
407 .composite_display.bits = {
428 ph->temporal_reference = 0;
429 ph->picture_coding_type = 1;
457 vpic->picture_type = VAEncPictureTypeIntra;
460 vpic->picture_type = VAEncPictureTypePredictive;
464 vpic->picture_type = VAEncPictureTypeBidirectional;
472 vpic->temporal_reference =
ph->temporal_reference;
473 vpic->f_code[0][0] = pce->
f_code[0][0];
474 vpic->f_code[0][1] = pce->
f_code[0][1];
475 vpic->f_code[1][0] = pce->
f_code[1][0];
476 vpic->f_code[1][1] = pce->
f_code[1][1];
507 vslice->quantiser_scale_code = qp;
524 if (
ctx->va_rc_mode == VA_RC_CQP) {
540 "%d / %d / %d for I- / P- / B-frames.\n",
552 ctx->nb_slices =
ctx->slice_block_rows;
555 ctx->roi_quant_range = 31;
573 .default_quality = 10,
575 .sequence_params_size =
sizeof(VAEncSequenceParameterBufferMPEG2),
578 .picture_params_size =
sizeof(VAEncPictureParameterBufferMPEG2),
581 .slice_params_size =
sizeof(VAEncSliceParameterBufferMPEG2),
584 .sequence_header_type = VAEncPackedHeaderSequence,
587 .picture_header_type = VAEncPackedHeaderPicture,
605 switch (avctx->
level) {
617 if (avctx->
height % 4096 == 0 || avctx->
width % 4096 == 0) {
619 "height or width divisible by 4096.\n");
623 ctx->desired_packed_headers = VA_ENC_PACKED_HEADER_SEQUENCE |
624 VA_ENC_PACKED_HEADER_PICTURE;
639 #define OFFSET(x) offsetof(VAAPIEncodeMPEG2Context, x)
640 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
645 {
"profile",
"Set profile (in profile_and_level_indication)",
649 #define PROFILE(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
650 { .i64 = value }, 0, 0, FLAGS, "profile"
655 {
"level",
"Set level (in profile_and_level_indication)",
657 { .i64 = 4 }, 0, 15,
FLAGS,
"level" },
659 #define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
660 { .i64 = value }, 0, 0, FLAGS, "level"
661 {
LEVEL(
"low", 10) },
662 {
LEVEL(
"main", 8) },
663 {
LEVEL(
"high_1440", 6) },
664 {
LEVEL(
"high", 4) },
674 {
"i_qfactor",
"1" },
675 {
"i_qoffset",
"0" },
676 {
"b_qfactor",
"6/5" },
677 {
"b_qoffset",
"0" },
691 .
p.
name =
"mpeg2_vaapi",
710 .p.wrapper_name =
"vaapi",
CodedBitstreamContext * cbc
MPEG2RawPictureHeader picture_header
static int vaapi_encode_mpeg2_write_fragment(AVCodecContext *avctx, char *data, size_t *data_len, CodedBitstreamFragment *frag)
#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
enum AVColorSpace colorspace
YUV colorspace type.
@ MPEG2_START_SEQUENCE_HEADER
MPEG2RawGroupOfPicturesHeader gop_header
unsigned int vbv_buffer_size
#define AV_PROFILE_MPEG2_SIMPLE
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.
#define AV_CODEC_CAP_HARDWARE
Codec is backed by a hardware implementation.
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
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.
#define se(name, range_min, range_max)
unsigned int f_code_horizontal
static int FUNC() ph(CodedBitstreamContext *ctx, RWContext *rw, H266RawPH *current)
MPEG2RawSequenceDisplayExtension sequence_display
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
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.
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.
av_cold int ff_vaapi_encode_close(AVCodecContext *avctx)
@ MPEG2_EXTENSION_SEQUENCE_DISPLAY
uint16_t display_horizontal_size
static av_cold int vaapi_encode_mpeg2_close(AVCodecContext *avctx)
void ff_mpeg12_find_best_frame_rate(AVRational frame_rate, int *code, int *ext_n, int *ext_d, int nonstandard)
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]
static av_cold int vaapi_encode_mpeg2_configure(AVCodecContext *avctx)
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.
uint8_t frame_pred_frame_dct
uint8_t extension_start_code
static const AVOption vaapi_encode_mpeg2_options[]
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
uint8_t concealment_motion_vectors
VAAPIEncodeContext common
uint8_t colour_description
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define AV_PROFILE_UNKNOWN
@ MPEG2_EXTENSION_PICTURE_CODING
void * codec_picture_params
uint8_t composite_display_flag
Coded bitstream fragment structure, combining one or more units.
static int vaapi_encode_mpeg2_init_picture_params(AVCodecContext *avctx, VAAPIEncodePicture *pic)
size_t data_size
The number of bytes in the bitstream.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
int(* init)(AVBSFContext *ctx)
#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.
#define LEVEL(name, value)
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.
const FFCodec ff_mpeg2_vaapi_encoder
#define CODEC_LONG_NAME(str)
int rc_buffer_size
decoder bitstream buffer size
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
const VAAPIEncodeProfile * profiles
Rational number (pair of numerator and denominator).
#define FF_CODEC_RECEIVE_PACKET_CB(func)
const char * av_default_item_name(void *ptr)
Return the context name.
uint8_t repeat_first_field
#define PROFILE(name, value)
MPEG2RawExtensionData picture_coding_extension
static const VAAPIEncodeProfile vaapi_encode_mpeg2_profiles[]
int level
Encoding level descriptor.
uint8_t matrix_coefficients
static av_cold int vaapi_encode_mpeg2_init(AVCodecContext *avctx)
MPEG2RawSequenceExtension sequence
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define VAAPI_ENCODE_RC_OPTIONS
uint8_t extension_start_code_identifier
static const AVClass vaapi_encode_mpeg2_class
CodedBitstreamFragment current_fragment
uint8_t * data
Pointer to the bitstream form of this fragment.
static const uint8_t header[24]
#define VAAPI_ENCODE_COMMON_OPTIONS
VASurfaceID recon_surface
static const FFCodecDefault vaapi_encode_mpeg2_defaults[]
@ AV_PIX_FMT_VAAPI
Hardware acceleration through VA-API, data[3] contains a VASurfaceID.
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...
static const VAAPIEncodeType vaapi_encode_type_mpeg2
static int vaapi_encode_mpeg2_init_slice_params(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodeSlice *slice)
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some it can consider them to be part of the FIFO and delay acknowledging a status change accordingly Example code
static int vaapi_encode_mpeg2_write_sequence_header(AVCodecContext *avctx, char *data, size_t *data_len)
const char * name
Name of the codec implementation.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
static int vaapi_encode_mpeg2_init_sequence_params(AVCodecContext *avctx)
uint8_t transfer_characteristics
int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Write the content of the fragment to its own internal buffer.
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
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...
union MPEG2RawExtensionData::@45 data
MPEG2RawPictureCodingExtension picture_coding
main external API structure.
@ MPEG2_EXTENSION_SEQUENCE
float i_quant_offset
qscale offset between P and I-frames
#define AV_PROFILE_MPEG2_MAIN
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
uint8_t picture_structure
MPEG2RawExtensionData sequence_extension
unsigned int f_code_vertical
uint16_t display_vertical_size
MPEG2RawSequenceHeader sequence_header
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.
static int vaapi_encode_mpeg2_add_header(AVCodecContext *avctx, CodedBitstreamFragment *frag, int type, void *header)
uint8_t intra_dc_precision
int width
picture width / height.
MPEG2RawExtensionData sequence_display_extension
static int vaapi_encode_mpeg2_write_picture_header(AVCodecContext *avctx, VAAPIEncodePicture *pic, char *data, size_t *data_len)
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
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 sub_carrier_phase
uint8_t progressive_frame