20 #include <va/va_enc_mpeg2.h>
49 #define vseq_var(name) vseq->name, name
50 #define vseqext_field(name) vseq->sequence_extension.bits.name, name
51 #define vgop_field(name) vseq->gop_header.bits.name, name
52 #define vpic_var(name) vpic->name, name
53 #define vpcext_field(name) vpic->picture_coding_extension.bits.name, name
54 #define vcomp_field(name) vpic->composite_display.bits.name, name
56 #define u2(width, value, name) put_bits(&pbc, width, value)
57 #define u(width, ...) u2(width, __VA_ARGS__)
60 char *
data,
size_t *data_len)
71 u(12, vseq->picture_width, horizontal_size_value);
72 u(12, vseq->picture_height, vertical_size_value);
74 u(4, 8, frame_rate_code);
75 u(18, priv->
bit_rate & 0x3fff, bit_rate_value);
78 u(1, 0, constrained_parameters_flag);
79 u(1, 0, load_intra_quantiser_matrix);
81 u(1, 0, load_non_intra_quantiser_matrix);
88 u(4, 1, extension_start_code_identifier);
92 u(2, 0, horizontal_size_extension);
93 u(2, 0, vertical_size_extension);
94 u(12, priv->
bit_rate >> 18, bit_rate_extension);
120 char *
data,
size_t *data_len)
123 int picture_coding_type;
131 switch (vpic->picture_type) {
132 case VAEncPictureTypeIntra:
135 case VAEncPictureTypePredictive:
138 case VAEncPictureTypeBidirectional:
142 av_assert0(0 &&
"invalid picture_coding_type");
144 u(3, picture_coding_type, picture_coding_type);
145 u(16, 0xffff, vbv_delay);
146 if (picture_coding_type == 2 || picture_coding_type == 3) {
147 u(1, 0, full_pel_forward_vector);
148 u(3, 7, forward_f_code);
150 if (picture_coding_type == 3) {
151 u(1, 0, full_pel_backward_vector);
152 u(3, 7, backward_f_code);
154 u(1, 0, extra_bit_picture);
160 u(4, 8, extension_start_code_identifier);
174 u(1, 1, chroma_420_type);
177 if (vpic->picture_coding_extension.bits.composite_display_flag) {
201 vseq->intra_period = avctx->
gop_size;
202 vseq->ip_period = ctx->
b_per_p + 1;
204 vseq->picture_width = avctx->
width;
205 vseq->picture_height = avctx->
height;
207 vseq->bits_per_second = avctx->
bit_rate;
213 vseq->aspect_ratio_information = 1;
216 vseq->sequence_extension.bits.profile_and_level_indication =
218 vseq->sequence_extension.bits.progressive_sequence = 1;
219 vseq->sequence_extension.bits.chroma_format = 1;
220 vseq->sequence_extension.bits.low_delay = 0;
221 vseq->sequence_extension.bits.frame_rate_extension_n = 0;
222 vseq->sequence_extension.bits.frame_rate_extension_d = 0;
224 vseq->new_gop_header = 0;
225 vseq->gop_header.bits.time_code = 0;
226 vseq->gop_header.bits.closed_gop = 1;
227 vseq->gop_header.bits.broken_link = 0;
229 vpic->forward_reference_picture = VA_INVALID_ID;
230 vpic->backward_reference_picture = VA_INVALID_ID;
231 vpic->reconstructed_picture = VA_INVALID_ID;
233 vpic->coded_buf = VA_INVALID_ID;
235 vpic->temporal_reference = 0;
236 vpic->f_code[0][0] = 15;
237 vpic->f_code[0][1] = 15;
238 vpic->f_code[1][0] = 15;
239 vpic->f_code[1][1] = 15;
241 vpic->picture_coding_extension.bits.intra_dc_precision = 0;
242 vpic->picture_coding_extension.bits.picture_structure = 3;
243 vpic->picture_coding_extension.bits.top_field_first = 0;
244 vpic->picture_coding_extension.bits.frame_pred_frame_dct = 1;
245 vpic->picture_coding_extension.bits.concealment_motion_vectors = 0;
246 vpic->picture_coding_extension.bits.q_scale_type = 0;
247 vpic->picture_coding_extension.bits.intra_vlc_format = 0;
248 vpic->picture_coding_extension.bits.alternate_scan = 0;
249 vpic->picture_coding_extension.bits.repeat_first_field = 0;
250 vpic->picture_coding_extension.bits.progressive_frame = 1;
251 vpic->picture_coding_extension.bits.composite_display_flag = 0;
267 switch (avctx->
level) {
287 vpic->picture_type = VAEncPictureTypeIntra;
291 vpic->picture_type = VAEncPictureTypePredictive;
293 vpic->f_code[0][0] = fch;
294 vpic->f_code[0][1] = fcv;
297 vpic->picture_type = VAEncPictureTypeBidirectional;
300 vpic->f_code[0][0] = fch;
301 vpic->f_code[0][1] = fcv;
302 vpic->f_code[1][0] = fch;
303 vpic->f_code[1][1] = fcv;
329 vslice->num_macroblocks = priv->
mb_width;
346 vslice->quantiser_scale_code = qp;
379 "%d / %d / %d for I- / P- / B-frames.\n",
394 .sequence_params_size =
sizeof(VAEncSequenceParameterBufferMPEG2),
397 .picture_params_size =
sizeof(VAEncPictureParameterBufferMPEG2),
400 .slice_params_size =
sizeof(VAEncSliceParameterBufferMPEG2),
403 .sequence_header_type = VAEncPackedHeaderSequence,
406 .picture_header_type = VAEncPackedHeaderPicture,
434 VA_ENC_PACKED_HEADER_PICTURE;
447 {
"i_qfactor",
"1" },
448 {
"i_qoffset",
"0" },
449 {
"b_qfactor",
"6/5" },
450 {
"b_qoffset",
"0" },
451 {
"global_quality",
"10" },
456 .
name =
"mpeg2_vaapi",
465 .
defaults = vaapi_encode_mpeg2_defaults,
static av_cold int vaapi_encode_mpeg2_configure(AVCodecContext *avctx)
#define FF_PROFILE_MPEG2_MAIN
#define vcomp_field(name)
VAEntrypoint va_entrypoint
ptrdiff_t const GLvoid * data
int64_t bit_rate
the average bitrate
av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
static av_cold int init(AVCodecContext *avctx)
av_cold int ff_vaapi_encode_close(AVCodecContext *avctx)
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...
unsigned int va_packed_headers
#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)
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...
VASurfaceID recon_surface
AVCodec ff_mpeg2_vaapi_encoder
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define vpcext_field(name)
static int vaapi_encode_mpeg2_init_picture_params(AVCodecContext *avctx, VAAPIEncodePicture *pic)
int ff_vaapi_encode2(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *input_image, int *got_packet)
#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[]
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_...
void * codec_picture_params
static int put_bits_count(PutBitContext *s)
int rc_buffer_size
decoder bitstream buffer size
common internal API header
static int vaapi_encode_mpeg2_init_sequence_params(AVCodecContext *avctx)
int width
picture width / height.
unsigned int va_rt_format
void * codec_picture_params
#define vseqext_field(name)
preferred ID for MPEG-1/2 video decoding
struct VAAPIEncodePicture * refs[MAX_PICTURE_REFERENCES]
static int vaapi_encode_mpeg2_init_slice_params(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodeSlice *slice)
const struct VAAPIEncodeType * codec
Libavcodec external API header.
main external API structure.
static const VAAPIEncodeType vaapi_encode_type_mpeg2
float b_quant_offset
qscale offset between IP and B-frames
static enum AVPixelFormat pix_fmts[]
int global_quality
Global quality for codecs which cannot change it per frame.
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
common internal api header.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
common internal and external API header
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
#define FF_PROFILE_MPEG2_SIMPLE
void * codec_slice_params
#define PICTURE_START_CODE
static const AVCodecDefault defaults[]
static int vaapi_encode_mpeg2_write_sequence_header(AVCodecContext *avctx, char *data, size_t *data_len)
AVPixelFormat
Pixel format.