20 #include <va/va_enc_mpeg2.h> 67 char *
data,
size_t *data_len,
81 "%zu < %zu.\n", *data_len,
102 "type = %d.\n", type);
110 char *
data,
size_t *data_len)
144 char *
data,
size_t *data_len)
178 int code, ext_n, ext_d;
180 memset(sh, 0,
sizeof(*sh));
181 memset(se, 0,
sizeof(*se));
182 memset(sde, 0,
sizeof(*sde));
183 memset(goph, 0,
sizeof(*goph));
184 memset(ph, 0,
sizeof(*ph));
185 memset(pce, 0,
sizeof(*pce));
202 switch (avctx->
level) {
230 (
AVRational) { avctx->width, avctx->height });
242 "representable, signalling square pixels instead.\n",
257 &code, &ext_n, &ext_d, 0);
354 *vseq = (VAEncSequenceParameterBufferMPEG2) {
358 .picture_width = avctx->
width,
359 .picture_height = avctx->
height,
366 .sequence_extension.bits = {
383 *vpic = (VAEncPictureParameterBufferMPEG2) {
384 .forward_reference_picture = VA_INVALID_ID,
385 .backward_reference_picture = VA_INVALID_ID,
386 .reconstructed_picture = VA_INVALID_ID,
387 .coded_buf = VA_INVALID_ID,
390 .f_code = { { 15, 15 }, { 15, 15 } },
392 .picture_coding_extension.bits = {
406 .composite_display.bits = {
456 vpic->picture_type = VAEncPictureTypeIntra;
459 vpic->picture_type = VAEncPictureTypePredictive;
463 vpic->picture_type = VAEncPictureTypeBidirectional;
472 vpic->f_code[0][0] = pce->
f_code[0][0];
473 vpic->f_code[0][1] = pce->
f_code[0][1];
474 vpic->f_code[1][0] = pce->
f_code[1][0];
475 vpic->f_code[1][1] = pce->
f_code[1][1];
506 vslice->quantiser_scale_code = qp;
541 "%d / %d / %d for I- / P- / B-frames.\n",
568 .sequence_params_size =
sizeof(VAEncSequenceParameterBufferMPEG2),
571 .picture_params_size =
sizeof(VAEncPictureParameterBufferMPEG2),
574 .slice_params_size =
sizeof(VAEncSliceParameterBufferMPEG2),
577 .sequence_header_type = VAEncPackedHeaderSequence,
580 .picture_header_type = VAEncPackedHeaderPicture,
598 switch (avctx->
level) {
610 if (avctx->
height % 4096 == 0 || avctx->
width % 4096 == 0) {
612 "height or width divisible by 4096.\n");
617 VA_ENC_PACKED_HEADER_PICTURE;
634 #define OFFSET(x) offsetof(VAAPIEncodeMPEG2Context, x) 635 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM) 639 {
"profile",
"Set profile (in profile_and_level_indication)",
643 #define PROFILE(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \ 644 { .i64 = value }, 0, 0, FLAGS, "profile" 649 {
"level",
"Set level (in profile_and_level_indication)",
651 { .i64 = 4 }, 0, 15,
FLAGS,
"level" },
653 #define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \ 654 { .i64 = value }, 0, 0, FLAGS, "level" 655 {
LEVEL(
"low", 10) },
656 {
LEVEL(
"main", 8) },
657 {
LEVEL(
"high_1440", 6) },
658 {
LEVEL(
"high", 4) },
668 {
"i_qfactor",
"1" },
669 {
"i_qoffset",
"0" },
670 {
"b_qfactor",
"6/5" },
671 {
"b_qoffset",
"0" },
672 {
"global_quality",
"10" },
686 .
name =
"mpeg2_vaapi",
694 .priv_class = &vaapi_encode_mpeg2_class,
696 .
defaults = vaapi_encode_mpeg2_defaults,
701 .wrapper_name =
"vaapi",
static av_cold int vaapi_encode_mpeg2_configure(AVCodecContext *avctx)
MPEG2RawExtensionData sequence_extension
uint8_t frame_pred_frame_dct
uint8_t extension_start_code_identifier
#define FF_PROFILE_MPEG2_MAIN
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
#define se(name, range_min, range_max)
uint16_t bit_rate_extension
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
static const VAAPIEncodeProfile vaapi_encode_mpeg2_profiles[]
static av_cold int init(AVCodecContext *avctx)
MPEG2RawSequenceExtension sequence
#define AV_CODEC_CAP_HARDWARE
Codec is backed by a hardware implementation.
uint8_t progressive_sequence
int ff_cbs_init(CodedBitstreamContext **ctx_ptr, enum AVCodecID codec_id, void *log_ctx)
Create and initialise a new context for the given codec.
const char * av_default_item_name(void *ptr)
Return the context name.
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...
uint16_t display_horizontal_size
MPEG2RawExtensionData sequence_display_extension
void * codec_sequence_params
static av_cold int vaapi_encode_mpeg2_init(AVCodecContext *avctx)
unsigned int vbv_buffer_size
float i_quant_offset
qscale offset between P and I-frames
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
uint8_t composite_display_flag
uint8_t transfer_characteristics
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#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.
static int vaapi_encode_mpeg2_write_picture_header(AVCodecContext *avctx, VAAPIEncodePicture *pic, char *data, size_t *data_len)
static int vaapi_encode_mpeg2_add_header(AVCodecContext *avctx, CodedBitstreamFragment *frag, int type, void *header)
static const AVClass vaapi_encode_mpeg2_class
uint8_t repeat_first_field
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...
uint16_t display_vertical_size
static double av_q2d(AVRational a)
Convert an AVRational to a double.
VASurfaceID recon_surface
static const uint8_t header[24]
MPEG2RawSequenceHeader sequence_header
static int vaapi_encode_mpeg2_write_fragment(AVCodecContext *avctx, char *data, size_t *data_len, CodedBitstreamFragment *frag)
MPEG2RawPictureCodingExtension picture_coding
uint8_t colour_description
size_t data_size
The number of bytes in the bitstream.
AVCodec ff_mpeg2_vaapi_encoder
#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.
static int vaapi_encode_mpeg2_init_picture_params(AVCodecContext *avctx, VAAPIEncodePicture *pic)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static const AVCodecDefault vaapi_encode_mpeg2_defaults[]
MPEG2RawPictureHeader picture_header
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 AVCodecDefault defaults[]
void ff_mpeg12_find_best_frame_rate(AVRational frame_rate, int *code, int *ext_n, int *ext_d, int nonstandard)
void * codec_picture_params
size_t data_bit_padding
The number of bits which should be ignored in the final byte.
int rc_buffer_size
decoder bitstream buffer size
CodedBitstreamContext * cbc
#define PROFILE(name, value)
static av_cold int vaapi_encode_mpeg2_close(AVCodecContext *avctx)
static int vaapi_encode_mpeg2_init_sequence_params(AVCodecContext *avctx)
uint8_t progressive_frame
uint8_t concealment_motion_vectors
int width
picture width / height.
unsigned int f_code_vertical
#define FF_PROFILE_UNKNOWN
const VAAPIEncodeProfile * profiles
av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
VAAPIEncodeContext common
void * codec_picture_params
uint8_t horizontal_size_extension
preferred ID for MPEG-1/2 video decoding
uint8_t * data
Pointer to the bitstream form of this fragment.
int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Write the content of the fragment to its own internal buffer.
struct VAAPIEncodePicture * refs[MAX_PICTURE_REFERENCES]
static int vaapi_encode_mpeg2_init_slice_params(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodeSlice *slice)
uint8_t picture_structure
const struct VAAPIEncodeType * codec
Libavcodec external API header.
MPEG2RawSequenceDisplayExtension sequence_display
Coded bitstream fragment structure, combining one or more units.
main external API structure.
uint8_t sub_carrier_phase
uint8_t frame_rate_extension_n
uint8_t vbv_buffer_size_extension
uint8_t frame_rate_extension_d
static const AVOption vaapi_encode_mpeg2_options[]
CodedBitstreamFragment current_fragment
Describe the class of an AVClass context structure.
Context structure for coded bitstream operations.
#define LEVEL(name, value)
enum AVColorSpace colorspace
YUV colorspace type.
Rational number (pair of numerator and denominator).
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
MPEG2RawExtensionData picture_coding_extension
static const VAAPIEncodeType vaapi_encode_type_mpeg2
uint8_t extension_start_code
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
unsigned int f_code_horizontal
static enum AVPixelFormat pix_fmts[]
int global_quality
Global quality for codecs which cannot change it per frame.
#define VAAPI_ENCODE_COMMON_OPTIONS
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
int ff_vaapi_encode2(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *input_image, int *got_packet)
uint8_t intra_dc_precision
uint8_t profile_and_level_indication
uint8_t vertical_size_extension
#define FF_PROFILE_MPEG2_SIMPLE
void * codec_slice_params
MPEG2RawGroupOfPicturesHeader gop_header
uint8_t matrix_coefficients
unsigned int desired_packed_headers
static int vaapi_encode_mpeg2_write_sequence_header(AVCodecContext *avctx, char *data, size_t *data_len)
AVPixelFormat
Pixel format.
av_cold int ff_vaapi_encode_close(AVCodecContext *avctx)
union MPEG2RawExtensionData::@61 data