20#include <va/va_enc_mpeg2.h>
69 char *
data,
size_t *data_len,
75 err = ff_cbs_write_fragment_data(priv->
cbc, frag);
83 "%zu < %zu.\n", *data_len,
103 "type = %d.\n",
type);
111 char *
data,
size_t *data_len)
139 ff_cbs_fragment_reset(frag);
145 char *
data,
size_t *data_len)
163 ff_cbs_fragment_reset(frag);
178 VAEncSequenceParameterBufferMPEG2 *vseq =
ctx->codec_sequence_params;
179 VAEncPictureParameterBufferMPEG2 *vpic =
ctx->codec_picture_params;
180 int code, ext_n, ext_d;
182 memset(sh, 0,
sizeof(*sh));
183 memset(
se, 0,
sizeof(*
se));
184 memset(sde, 0,
sizeof(*sde));
185 memset(goph, 0,
sizeof(*goph));
186 memset(
ph, 0,
sizeof(*
ph));
187 memset(pce, 0,
sizeof(*pce));
190 if (
ctx->va_bit_rate > 0) {
204 switch (avctx->
level) {
232 (
AVRational) { avctx->width, avctx->height });
244 "representable, signalling square pixels instead.\n",
259 &
code, &ext_n, &ext_d, 0);
276 se->profile_and_level_indication = avctx->
profile << 4 | avctx->
level;
277 se->progressive_sequence = 1;
278 se->chroma_format = 1;
280 se->horizontal_size_extension = avctx->
width >> 12;
281 se->vertical_size_extension = avctx->
height >> 12;
283 se->bit_rate_extension = priv->
bit_rate >> 18;
287 se->frame_rate_extension_n = ext_n;
288 se->frame_rate_extension_d = ext_d;
327 ph->vbv_delay = 0xffff;
329 ph->full_pel_forward_vector = 0;
330 ph->forward_f_code = 7;
331 ph->full_pel_backward_vector = 0;
332 ph->forward_f_code = 7;
356 *vseq = (VAEncSequenceParameterBufferMPEG2) {
358 .ip_period = base_ctx->
b_per_p + 1,
360 .picture_width = avctx->
width,
361 .picture_height = avctx->
height,
363 .bits_per_second =
ctx->va_bit_rate,
368 .sequence_extension.bits = {
369 .profile_and_level_indication =
se->profile_and_level_indication,
370 .progressive_sequence =
se->progressive_sequence,
371 .chroma_format =
se->chroma_format,
372 .low_delay =
se->low_delay,
373 .frame_rate_extension_n =
se->frame_rate_extension_n,
374 .frame_rate_extension_d =
se->frame_rate_extension_d,
385 *vpic = (VAEncPictureParameterBufferMPEG2) {
386 .forward_reference_picture = VA_INVALID_ID,
387 .backward_reference_picture = VA_INVALID_ID,
388 .reconstructed_picture = VA_INVALID_ID,
389 .coded_buf = VA_INVALID_ID,
392 .f_code = { { 15, 15 }, { 15, 15 } },
394 .picture_coding_extension.bits = {
408 .composite_display.bits = {
430 ph->temporal_reference = 0;
431 ph->picture_coding_type = 1;
459 vpic->picture_type = VAEncPictureTypeIntra;
462 vpic->picture_type = VAEncPictureTypePredictive;
466 vpic->picture_type = VAEncPictureTypeBidirectional;
474 vpic->temporal_reference =
ph->temporal_reference;
475 vpic->f_code[0][0] = pce->
f_code[0][0];
476 vpic->f_code[0][1] = pce->
f_code[0][1];
477 vpic->f_code[1][0] = pce->
f_code[1][0];
478 vpic->f_code[1][1] = pce->
f_code[1][1];
509 vslice->quantiser_scale_code = qp;
526 if (
ctx->va_rc_mode == VA_RC_CQP) {
542 "%d / %d / %d for I- / P- / B-frames.\n",
554 ctx->nb_slices =
ctx->slice_block_rows;
557 ctx->roi_quant_range = 31;
575 .default_quality = 10,
577 .sequence_params_size =
sizeof(VAEncSequenceParameterBufferMPEG2),
580 .picture_params_size =
sizeof(VAEncPictureParameterBufferMPEG2),
583 .slice_params_size =
sizeof(VAEncSliceParameterBufferMPEG2),
586 .sequence_header_type = VAEncPackedHeaderSequence,
589 .picture_header_type = VAEncPackedHeaderPicture,
607 switch (avctx->
level) {
619 if (avctx->
height % 4096 == 0 || avctx->
width % 4096 == 0) {
621 "height or width divisible by 4096.\n");
625 ctx->desired_packed_headers = VA_ENC_PACKED_HEADER_SEQUENCE |
626 VA_ENC_PACKED_HEADER_PICTURE;
636 ff_cbs_close(&priv->
cbc);
641#define OFFSET(x) offsetof(VAAPIEncodeMPEG2Context, x)
642#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
648 {
"profile",
"Set profile (in profile_and_level_indication)",
652#define PROFILE(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
653 { .i64 = value }, 0, 0, FLAGS, .unit = "profile"
658 {
"level",
"Set level (in profile_and_level_indication)",
660 { .i64 = 4 }, 0, 15,
FLAGS, .unit =
"level" },
662#define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
663 { .i64 = value }, 0, 0, FLAGS, .unit = "level"
664 {
LEVEL(
"low", 10) },
665 {
LEVEL(
"main", 8) },
666 {
LEVEL(
"high_1440", 6) },
667 {
LEVEL(
"high", 4) },
677 {
"i_qfactor",
"1" },
678 {
"i_qoffset",
"0" },
679 {
"b_qfactor",
"6/5" },
680 {
"b_qoffset",
"0" },
687 .class_name =
"mpeg2_vaapi",
694 .p.name =
"mpeg2_vaapi",
711 .p.wrapper_name =
"vaapi",
const FFCodec ff_mpeg2_vaapi_encoder
static AVFormatContext * ctx
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
#define se(name, range_min, range_max)
static int FUNC ph(CodedBitstreamContext *ctx, RWContext *rw, H266RawPH *current)
@ MPEG2_EXTENSION_SEQUENCE_DISPLAY
@ MPEG2_EXTENSION_PICTURE_CODING
@ MPEG2_EXTENSION_SEQUENCE
@ MPEG2_START_SEQUENCE_HEADER
#define CODEC_PIXFMTS(...)
#define FF_CODEC_CAP_NOT_INIT_THREADSAFE
The codec is not known to be init-threadsafe (i.e.
#define FF_CODEC_RECEIVE_PACKET_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define AV_PROFILE_MPEG2_MAIN
#define AV_PROFILE_UNKNOWN
#define AV_PROFILE_MPEG2_SIMPLE
int(* init)(AVBSFContext *ctx)
@ AV_OPT_TYPE_INT
Underlying C type is int.
#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_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_CAP_HARDWARE
Codec is backed by a hardware implementation.
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
#define LIBAVUTIL_VERSION_INT
#define HW_BASE_ENCODE_COMMON_OPTIONS
const AVCodecHWConfigInternal *const ff_vaapi_encode_hw_configs[]
int ff_vaapi_encode_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
av_cold int ff_vaapi_encode_close(AVCodecContext *avctx)
void ff_mpeg12_find_best_frame_rate(AVRational frame_rate, int *code, int *ext_n, int *ext_d, int nonstandard)
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
@ AV_PIX_FMT_VAAPI
Hardware acceleration through VA-API, data[3] contains a VASurfaceID.
static const uint8_t header[24]
Describe the class of an AVClass context structure.
main external API structure.
int width
picture width / height.
int rc_buffer_size
decoder bitstream buffer size
float b_quant_offset
qscale offset between IP and B-frames
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
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...
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
int level
Encoding level descriptor.
enum AVColorSpace colorspace
YUV colorspace type.
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
float i_quant_factor
qscale factor between P- and I-frames If > 0 then the last P-frame quantizer will be used (q = lastp_...
float i_quant_offset
qscale offset between P and I-frames
Rational number (pair of numerator and denominator).
Context structure for coded bitstream operations.
Coded bitstream fragment structure, combining one or more units.
size_t data_bit_padding
The number of bits which should be ignored in the final byte.
size_t data_size
The number of bytes in the bitstream.
uint8_t * data
Pointer to the bitstream form of this fragment.
struct FFHWBaseEncodePicture * refs[MAX_REFERENCE_LIST_NUM][MAX_PICTURE_REFERENCES]
MPEG2RawPictureCodingExtension picture_coding
uint8_t extension_start_code
MPEG2RawSequenceDisplayExtension sequence_display
MPEG2RawSequenceExtension sequence
union MPEG2RawExtensionData::@070215134007105004266170356251251155306352224353 data
uint8_t extension_start_code_identifier
uint8_t sub_carrier_phase
uint8_t concealment_motion_vectors
uint8_t progressive_frame
uint8_t repeat_first_field
uint8_t frame_pred_frame_dct
uint8_t composite_display_flag
uint8_t picture_structure
uint8_t intra_dc_precision
uint16_t display_vertical_size
uint8_t transfer_characteristics
uint16_t display_horizontal_size
uint8_t colour_description
uint8_t matrix_coefficients
MPEG2RawGroupOfPicturesHeader gop_header
MPEG2RawPictureHeader picture_header
unsigned int vbv_buffer_size
MPEG2RawExtensionData sequence_extension
CodedBitstreamContext * cbc
unsigned int f_code_vertical
MPEG2RawExtensionData picture_coding_extension
MPEG2RawSequenceHeader sequence_header
MPEG2RawExtensionData sequence_display_extension
unsigned int f_code_horizontal
VAAPIEncodeContext common
CodedBitstreamFragment current_fragment
void * codec_picture_params
VASurfaceID recon_surface
void * codec_slice_params
#define VAAPI_ENCODE_COMMON_OPTIONS
#define VAAPI_ENCODE_RC_OPTIONS
static av_cold int vaapi_encode_mpeg2_init(AVCodecContext *avctx)
static const VAAPIEncodeType vaapi_encode_type_mpeg2
static av_cold int vaapi_encode_mpeg2_configure(AVCodecContext *avctx)
static const VAAPIEncodeProfile vaapi_encode_mpeg2_profiles[]
static int vaapi_encode_mpeg2_write_sequence_header(AVCodecContext *avctx, char *data, size_t *data_len)
static const AVOption vaapi_encode_mpeg2_options[]
#define LEVEL(name, value)
static int vaapi_encode_mpeg2_write_picture_header(AVCodecContext *avctx, FFHWBaseEncodePicture *pic, char *data, size_t *data_len)
static int vaapi_encode_mpeg2_write_fragment(AVCodecContext *avctx, char *data, size_t *data_len, CodedBitstreamFragment *frag)
static const FFCodecDefault vaapi_encode_mpeg2_defaults[]
static av_cold int vaapi_encode_mpeg2_close(AVCodecContext *avctx)
static int vaapi_encode_mpeg2_init_sequence_params(AVCodecContext *avctx)
#define PROFILE(name, value)
static int vaapi_encode_mpeg2_add_header(AVCodecContext *avctx, CodedBitstreamFragment *frag, int type, void *header)
static const AVClass vaapi_encode_mpeg2_class
static int vaapi_encode_mpeg2_init_picture_params(AVCodecContext *avctx, FFHWBaseEncodePicture *pic)
static int vaapi_encode_mpeg2_init_slice_params(AVCodecContext *avctx, FFHWBaseEncodePicture *pic, VAAPIEncodeSlice *slice)
static int write_sequence_header(AVCodecContext *avctx, FFHWBaseEncodePicture *base_pic, uint8_t *data, size_t *data_len)