FFmpeg
Loading...
Searching...
No Matches
vaapi_encode_mpeg2.c
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#include <va/va.h>
20#include <va/va_enc_mpeg2.h>
21
22#include "libavutil/avassert.h"
23#include "libavutil/opt.h"
24
25#include "avcodec.h"
26#include "cbs.h"
27#include "cbs_mpeg2.h"
28#include "codec_internal.h"
29#include "mpeg12.h"
30#include "vaapi_encode.h"
31
66
67
69 char *data, size_t *data_len,
71{
73 int err;
74
75 err = ff_cbs_write_fragment_data(priv->cbc, frag);
76 if (err < 0) {
77 av_log(avctx, AV_LOG_ERROR, "Failed to write packed header.\n");
78 return err;
79 }
80
81 if (*data_len < 8 * frag->data_size - frag->data_bit_padding) {
82 av_log(avctx, AV_LOG_ERROR, "Access unit too large: "
83 "%zu < %zu.\n", *data_len,
84 8 * frag->data_size - frag->data_bit_padding);
85 return AVERROR(ENOSPC);
86 }
87
88 memcpy(data, frag->data, frag->data_size);
89 *data_len = 8 * frag->data_size - frag->data_bit_padding;
90
91 return 0;
92}
93
96 int type, void *header)
97{
98 int err;
99
100 err = ff_cbs_insert_unit_content(frag, -1, type, header, NULL);
101 if (err < 0) {
102 av_log(avctx, AV_LOG_ERROR, "Failed to add header: "
103 "type = %d.\n", type);
104 return err;
105 }
106
107 return 0;
108}
109
111 char *data, size_t *data_len)
112{
113 VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
115 int err;
116
118 &priv->sequence_header);
119 if (err < 0)
120 goto fail;
121
123 &priv->sequence_extension);
124 if (err < 0)
125 goto fail;
126
129 if (err < 0)
130 goto fail;
131
133 &priv->gop_header);
134 if (err < 0)
135 goto fail;
136
137 err = vaapi_encode_mpeg2_write_fragment(avctx, data, data_len, frag);
138fail:
139 ff_cbs_fragment_reset(frag);
140 return 0;
141}
142
145 char *data, size_t *data_len)
146{
147 VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
149 int err;
150
152 &priv->picture_header);
153 if (err < 0)
154 goto fail;
155
158 if (err < 0)
159 goto fail;
160
161 err = vaapi_encode_mpeg2_write_fragment(avctx, data, data_len, frag);
162fail:
163 ff_cbs_fragment_reset(frag);
164 return 0;
165}
166
168{
169 FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
171 VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
178 VAEncSequenceParameterBufferMPEG2 *vseq = ctx->codec_sequence_params;
179 VAEncPictureParameterBufferMPEG2 *vpic = ctx->codec_picture_params;
180 int code, ext_n, ext_d;
181
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));
188
189
190 if (ctx->va_bit_rate > 0) {
191 priv->bit_rate = (ctx->va_bit_rate + 399) / 400;
192 } else {
193 // Unknown (not a bitrate-targetting mode), so just use the
194 // highest value.
195 priv->bit_rate = 0x3fffffff;
196 }
197 if (avctx->rc_buffer_size > 0) {
198 priv->vbv_buffer_size = (avctx->rc_buffer_size + (1 << 14) - 1) >> 14;
199 } else {
200 // Unknown, so guess a value from the bitrate.
201 priv->vbv_buffer_size = priv->bit_rate >> 14;
202 }
203
204 switch (avctx->level) {
205 case 4: // High.
206 case 6: // High 1440.
207 priv->f_code_horizontal = 9;
208 priv->f_code_vertical = 5;
209 break;
210 case 8: // Main.
211 priv->f_code_horizontal = 8;
212 priv->f_code_vertical = 5;
213 break;
214 case 10: // Low.
215 default:
216 priv->f_code_horizontal = 7;
217 priv->f_code_vertical = 4;
218 break;
219 }
220
221
222 // Sequence header
223
225
226 sh->horizontal_size_value = avctx->width & 0xfff;
227 sh->vertical_size_value = avctx->height & 0xfff;
228
229 if (avctx->sample_aspect_ratio.num != 0 &&
230 avctx->sample_aspect_ratio.den != 0) {
232 (AVRational) { avctx->width, avctx->height });
233
234 if (av_cmp_q(avctx->sample_aspect_ratio, (AVRational) { 1, 1 }) == 0) {
236 } else if (av_cmp_q(dar, (AVRational) { 3, 4 }) == 0) {
238 } else if (av_cmp_q(dar, (AVRational) { 9, 16 }) == 0) {
240 } else if (av_cmp_q(dar, (AVRational) { 100, 221 }) == 0) {
242 } else {
243 av_log(avctx, AV_LOG_WARNING, "Sample aspect ratio %d:%d is not "
244 "representable, signalling square pixels instead.\n",
246 avctx->sample_aspect_ratio.den);
248 }
249 } else {
250 // Unknown - assume square pixels.
252 }
253
254 if (avctx->framerate.num > 0 && avctx->framerate.den > 0)
255 priv->frame_rate = avctx->framerate;
256 else
257 priv->frame_rate = av_inv_q(avctx->time_base);
259 &code, &ext_n, &ext_d, 0);
260 sh->frame_rate_code = code;
261
262 sh->bit_rate_value = priv->bit_rate & 0x3ffff;
263 sh->vbv_buffer_size_value = priv->vbv_buffer_size & 0x3ff;
264
268
269
270 // Sequence extension
271
275
276 se->profile_and_level_indication = avctx->profile << 4 | avctx->level;
277 se->progressive_sequence = 1;
278 se->chroma_format = 1;
279
280 se->horizontal_size_extension = avctx->width >> 12;
281 se->vertical_size_extension = avctx->height >> 12;
282
283 se->bit_rate_extension = priv->bit_rate >> 18;
284 se->vbv_buffer_size_extension = priv->vbv_buffer_size >> 10;
285 se->low_delay = base_ctx->b_per_p == 0;
286
287 se->frame_rate_extension_n = ext_n;
288 se->frame_rate_extension_d = ext_d;
289
290
291 // Sequence display extension
292
297
298 // Unspecified video format, from table 6-6.
299 sde->video_format = 5;
300
301 sde->colour_primaries = avctx->color_primaries;
303 sde->matrix_coefficients = avctx->colorspace;
304 sde->colour_description =
308
309 sde->display_horizontal_size = avctx->width;
310 sde->display_vertical_size = avctx->height;
311
312
313 // GOP header
314
316
317 // Marker bit in the middle of time_code.
318 goph->time_code = 1 << 12;
319 goph->closed_gop = 1;
320 goph->broken_link = 0;
321
322
323 // Defaults for picture header
324
325 ph->picture_start_code = MPEG2_START_PICTURE;
326
327 ph->vbv_delay = 0xffff; // Not currently calculated.
328
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;
333
334
335 // Defaults for picture coding extension
336
341
342 pce->intra_dc_precision = 0;
343 pce->picture_structure = 3;
344 pce->top_field_first = 0;
345 pce->frame_pred_frame_dct = 1;
347 pce->q_scale_type = 0;
348 pce->intra_vlc_format = 0;
349 pce->alternate_scan = 0;
350 pce->repeat_first_field = 0;
351 pce->progressive_frame = 1;
352 pce->composite_display_flag = 0;
353
354
355
356 *vseq = (VAEncSequenceParameterBufferMPEG2) {
357 .intra_period = base_ctx->gop_size,
358 .ip_period = base_ctx->b_per_p + 1,
359
360 .picture_width = avctx->width,
361 .picture_height = avctx->height,
362
363 .bits_per_second = ctx->va_bit_rate,
364 .frame_rate = av_q2d(priv->frame_rate),
365 .aspect_ratio_information = sh->aspect_ratio_information,
366 .vbv_buffer_size = priv->vbv_buffer_size,
367
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,
375 },
376
377 .new_gop_header = 1,
378 .gop_header.bits = {
379 .time_code = goph->time_code,
380 .closed_gop = goph->closed_gop,
381 .broken_link = goph->broken_link,
382 },
383 };
384
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,
390
391 .vbv_delay = 0xffff,
392 .f_code = { { 15, 15 }, { 15, 15 } },
393
394 .picture_coding_extension.bits = {
395 .intra_dc_precision = pce->intra_dc_precision,
396 .picture_structure = pce->picture_structure,
397 .top_field_first = pce->top_field_first,
398 .frame_pred_frame_dct = pce->frame_pred_frame_dct,
399 .concealment_motion_vectors = pce->concealment_motion_vectors,
400 .q_scale_type = pce->q_scale_type,
401 .intra_vlc_format = pce->intra_vlc_format,
402 .alternate_scan = pce->alternate_scan,
403 .repeat_first_field = pce->repeat_first_field,
404 .progressive_frame = pce->progressive_frame,
405 .composite_display_flag = pce->composite_display_flag,
406 },
407
408 .composite_display.bits = {
409 .v_axis = pce->v_axis,
410 .field_sequence = pce->field_sequence,
411 .sub_carrier = pce->sub_carrier,
412 .burst_amplitude = pce->burst_amplitude,
413 .sub_carrier_phase = pce->sub_carrier_phase,
414 },
415 };
416
417 return 0;
418}
419
422{
423 VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
424 VAAPIEncodePicture *vaapi_pic = pic->priv;
427 VAEncPictureParameterBufferMPEG2 *vpic = vaapi_pic->codec_picture_params;
428
429 if (pic->type == FF_HW_PICTURE_TYPE_IDR || pic->type == FF_HW_PICTURE_TYPE_I) {
430 ph->temporal_reference = 0;
431 ph->picture_coding_type = 1;
432 priv->last_i_frame = pic->display_order;
433 } else {
434 ph->temporal_reference = pic->display_order - priv->last_i_frame;
435 ph->picture_coding_type = pic->type == FF_HW_PICTURE_TYPE_B ? 3 : 2;
436 }
437
438 if (pic->type == FF_HW_PICTURE_TYPE_P || pic->type == FF_HW_PICTURE_TYPE_B) {
439 pce->f_code[0][0] = priv->f_code_horizontal;
440 pce->f_code[0][1] = priv->f_code_vertical;
441 } else {
442 pce->f_code[0][0] = 15;
443 pce->f_code[0][1] = 15;
444 }
445 if (pic->type == FF_HW_PICTURE_TYPE_B) {
446 pce->f_code[1][0] = priv->f_code_horizontal;
447 pce->f_code[1][1] = priv->f_code_vertical;
448 } else {
449 pce->f_code[1][0] = 15;
450 pce->f_code[1][1] = 15;
451 }
452
453 vpic->reconstructed_picture = vaapi_pic->recon_surface;
454 vpic->coded_buf = vaapi_pic->output_buffer;
455
456 switch (pic->type) {
459 vpic->picture_type = VAEncPictureTypeIntra;
460 break;
462 vpic->picture_type = VAEncPictureTypePredictive;
463 vpic->forward_reference_picture = ((VAAPIEncodePicture *)pic->refs[0][0]->priv)->recon_surface;
464 break;
466 vpic->picture_type = VAEncPictureTypeBidirectional;
467 vpic->forward_reference_picture = ((VAAPIEncodePicture *)pic->refs[0][0]->priv)->recon_surface;
468 vpic->backward_reference_picture = ((VAAPIEncodePicture *)pic->refs[1][0]->priv)->recon_surface;
469 break;
470 default:
471 av_assert0(0 && "invalid picture type");
472 }
473
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];
479
480 return 0;
481}
482
485 VAAPIEncodeSlice *slice)
486{
487 VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
488 VAEncSliceParameterBufferMPEG2 *vslice = slice->codec_slice_params;
489 int qp;
490
491 vslice->macroblock_address = slice->block_start;
492 vslice->num_macroblocks = slice->block_size;
493
494 switch (pic->type) {
497 qp = priv->quant_i;
498 break;
500 qp = priv->quant_p;
501 break;
503 qp = priv->quant_b;
504 break;
505 default:
506 av_assert0(0 && "invalid picture type");
507 }
508
509 vslice->quantiser_scale_code = qp;
510 vslice->is_intra_slice = (pic->type == FF_HW_PICTURE_TYPE_IDR ||
511 pic->type == FF_HW_PICTURE_TYPE_I);
512
513 return 0;
514}
515
517{
519 VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
520 int err;
521
522 err = ff_cbs_init(&priv->cbc, AV_CODEC_ID_MPEG2VIDEO, avctx);
523 if (err < 0)
524 return err;
525
526 if (ctx->va_rc_mode == VA_RC_CQP) {
527 priv->quant_p = av_clip(ctx->rc_quality, 1, 31);
528 if (avctx->i_quant_factor > 0.0)
529 priv->quant_i =
530 av_clip((avctx->i_quant_factor * priv->quant_p +
531 avctx->i_quant_offset) + 0.5, 1, 31);
532 else
533 priv->quant_i = priv->quant_p;
534 if (avctx->b_quant_factor > 0.0)
535 priv->quant_b =
536 av_clip((avctx->b_quant_factor * priv->quant_p +
537 avctx->b_quant_offset) + 0.5, 1, 31);
538 else
539 priv->quant_b = priv->quant_p;
540
541 av_log(avctx, AV_LOG_DEBUG, "Using fixed quantiser "
542 "%d / %d / %d for I- / P- / B-frames.\n",
543 priv->quant_i, priv->quant_p, priv->quant_b);
544
545 } else {
546 priv->quant_i = 16;
547 priv->quant_p = 16;
548 priv->quant_b = 16;
549 }
550
551 ctx->slice_block_rows = FFALIGN(avctx->height, 16) / 16;
552 ctx->slice_block_cols = FFALIGN(avctx->width, 16) / 16;
553
554 ctx->nb_slices = ctx->slice_block_rows;
555 ctx->slice_size = 1;
556
557 ctx->roi_quant_range = 31;
558
559 return 0;
560}
561
563 { AV_PROFILE_MPEG2_MAIN, 8, 3, 1, 1, VAProfileMPEG2Main },
564 { AV_PROFILE_MPEG2_SIMPLE, 8, 3, 1, 1, VAProfileMPEG2Simple },
566};
567
569 .profiles = vaapi_encode_mpeg2_profiles,
570
571 .flags = FF_HW_FLAG_B_PICTURES,
572
573 .configure = &vaapi_encode_mpeg2_configure,
574
575 .default_quality = 10,
576
577 .sequence_params_size = sizeof(VAEncSequenceParameterBufferMPEG2),
578 .init_sequence_params = &vaapi_encode_mpeg2_init_sequence_params,
579
580 .picture_params_size = sizeof(VAEncPictureParameterBufferMPEG2),
581 .init_picture_params = &vaapi_encode_mpeg2_init_picture_params,
582
583 .slice_params_size = sizeof(VAEncSliceParameterBufferMPEG2),
584 .init_slice_params = &vaapi_encode_mpeg2_init_slice_params,
585
586 .sequence_header_type = VAEncPackedHeaderSequence,
588
589 .picture_header_type = VAEncPackedHeaderPicture,
590 .write_picture_header = &vaapi_encode_mpeg2_write_picture_header,
591};
592
594{
596 VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
597
599
600 if (avctx->profile == AV_PROFILE_UNKNOWN)
601 avctx->profile = priv->profile;
602 if (avctx->level == AV_LEVEL_UNKNOWN)
603 avctx->level = priv->level;
604
605 // Reject unknown levels (these are required to set f_code for
606 // motion vector encoding).
607 switch (avctx->level) {
608 case 4: // High
609 case 6: // High 1440
610 case 8: // Main
611 case 10: // Low
612 break;
613 default:
614 av_log(avctx, AV_LOG_ERROR, "Unknown MPEG-2 level %d.\n",
615 avctx->level);
616 return AVERROR(EINVAL);
617 }
618
619 if (avctx->height % 4096 == 0 || avctx->width % 4096 == 0) {
620 av_log(avctx, AV_LOG_ERROR, "MPEG-2 does not support picture "
621 "height or width divisible by 4096.\n");
622 return AVERROR(EINVAL);
623 }
624
625 ctx->desired_packed_headers = VA_ENC_PACKED_HEADER_SEQUENCE |
626 VA_ENC_PACKED_HEADER_PICTURE;
627
628 return ff_vaapi_encode_init(avctx);
629}
630
632{
633 VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
634
635 ff_cbs_fragment_free(&priv->current_fragment);
636 ff_cbs_close(&priv->cbc);
637
638 return ff_vaapi_encode_close(avctx);
639}
640
641#define OFFSET(x) offsetof(VAAPIEncodeMPEG2Context, x)
642#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
647
648 { "profile", "Set profile (in profile_and_level_indication)",
650 { .i64 = AV_PROFILE_UNKNOWN }, AV_PROFILE_UNKNOWN, 7, FLAGS, .unit = "profile" },
651
652#define PROFILE(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
653 { .i64 = value }, 0, 0, FLAGS, .unit = "profile"
654 { PROFILE("simple", AV_PROFILE_MPEG2_SIMPLE) },
655 { PROFILE("main", AV_PROFILE_MPEG2_MAIN) },
656#undef PROFILE
657
658 { "level", "Set level (in profile_and_level_indication)",
660 { .i64 = 4 }, 0, 15, FLAGS, .unit = "level" },
661
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) },
668#undef LEVEL
669
670 { NULL },
671};
672
674 { "b", "0" },
675 { "bf", "1" },
676 { "g", "120" },
677 { "i_qfactor", "1" },
678 { "i_qoffset", "0" },
679 { "b_qfactor", "6/5" },
680 { "b_qoffset", "0" },
681 { "qmin", "-1" },
682 { "qmax", "-1" },
683 { NULL },
684};
685
687 .class_name = "mpeg2_vaapi",
688 .item_name = av_default_item_name,
690 .version = LIBAVUTIL_VERSION_INT,
691};
692
694 .p.name = "mpeg2_vaapi",
695 CODEC_LONG_NAME("MPEG-2 (VAAPI)"),
696 .p.type = AVMEDIA_TYPE_VIDEO,
698 .priv_data_size = sizeof(VAAPIEncodeMPEG2Context),
701 .close = &vaapi_encode_mpeg2_close,
702 .p.priv_class = &vaapi_encode_mpeg2_class,
703 .p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE |
705 .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE |
707 .defaults = vaapi_encode_mpeg2_defaults,
709 .color_ranges = AVCOL_RANGE_MPEG,
710 .hw_configs = ff_vaapi_encode_hw_configs,
711 .p.wrapper_name = "vaapi",
712};
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.
Definition avassert.h:42
Libavcodec external API header.
#define se(name, range_min, range_max)
Definition cbs_h264.c:67
static int FUNC ph(CodedBitstreamContext *ctx, RWContext *rw, H266RawPH *current)
@ MPEG2_EXTENSION_SEQUENCE_DISPLAY
Definition cbs_mpeg2.h:46
@ MPEG2_EXTENSION_PICTURE_CODING
Definition cbs_mpeg2.h:51
@ MPEG2_EXTENSION_SEQUENCE
Definition cbs_mpeg2.h:45
@ MPEG2_START_PICTURE
Definition cbs_mpeg2.h:29
@ MPEG2_START_SEQUENCE_HEADER
Definition cbs_mpeg2.h:33
@ MPEG2_START_EXTENSION
Definition cbs_mpeg2.h:35
@ MPEG2_START_GROUP
Definition cbs_mpeg2.h:37
#define FLAGS
Definition cmdutils.c:598
#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_clip
Definition common.h:100
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
#define AV_PROFILE_MPEG2_MAIN
Definition defs.h:104
#define AV_PROFILE_UNKNOWN
Definition defs.h:65
#define AV_LEVEL_UNKNOWN
Definition defs.h:209
#define AV_PROFILE_MPEG2_SIMPLE
Definition defs.h:105
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
#define fail
Definition test.h:479
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
Definition codec.h:147
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition codec.h:79
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition codec.h:49
#define AV_CODEC_CAP_HARDWARE
Codec is backed by a hardware implementation.
Definition codec.h:133
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
Definition codec_id.h:52
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:241
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition rational.h:104
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
Definition rational.h:89
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition rational.h:159
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
Definition rational.c:88
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
#define LIBAVUTIL_VERSION_INT
Definition version.h:85
#define HW_BASE_ENCODE_COMMON_OPTIONS
@ FF_HW_FLAG_B_PICTURES
@ FF_HW_PICTURE_TYPE_P
@ FF_HW_PICTURE_TYPE_I
@ FF_HW_PICTURE_TYPE_B
@ FF_HW_PICTURE_TYPE_IDR
cl_device_type type
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)
#define av_cold
Definition attributes.h:117
#define FFALIGN(x, a)
Definition macros.h:78
void ff_mpeg12_find_best_frame_rate(AVRational frame_rate, int *code, int *ext_n, int *ext_d, int nonstandard)
const char data[16]
Definition mxf.c:149
int profile
Definition mxfenc.c:2299
AVOptions.
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition pixfmt.h:766
@ AV_PIX_FMT_VAAPI
Hardware acceleration through VA-API, data[3] contains a VASurfaceID.
Definition pixfmt.h:126
@ AVCOL_PRI_UNSPECIFIED
Definition pixfmt.h:645
@ AVCOL_TRC_UNSPECIFIED
Definition pixfmt.h:675
@ AVCOL_SPC_UNSPECIFIED
Definition pixfmt.h:709
static const uint8_t header[24]
Definition sdr2.c:68
const uint8_t * code
Definition spdifenc.c:433
Describe the class of an AVClass context structure.
Definition log.h:76
main external API structure.
Definition avcodec.h:443
int width
picture width / height.
Definition avcodec.h:604
int rc_buffer_size
decoder bitstream buffer size
Definition avcodec.h:1273
float b_quant_offset
qscale offset between IP and B-frames
Definition avcodec.h:797
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition avcodec.h:657
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...
Definition avcodec.h:790
AVRational framerate
Definition avcodec.h:563
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
Definition avcodec.h:628
int level
Encoding level descriptor.
Definition avcodec.h:1646
int profile
profile
Definition avcodec.h:1636
enum AVColorSpace colorspace
YUV colorspace type.
Definition avcodec.h:671
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition avcodec.h:664
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition avcodec.h:547
float i_quant_factor
qscale factor between P- and I-frames If > 0 then the last P-frame quantizer will be used (q = lastp_...
Definition avcodec.h:806
void * priv_data
Definition avcodec.h:470
float i_quant_offset
qscale offset between P and I-frames
Definition avcodec.h:813
AVOption.
Definition opt.h:428
Rational number (pair of numerator and denominator).
Definition rational.h:58
int num
Numerator.
Definition rational.h:59
int den
Denominator.
Definition rational.h:60
Context structure for coded bitstream operations.
Definition cbs.h:226
Coded bitstream fragment structure, combining one or more units.
Definition cbs.h:129
size_t data_bit_padding
The number of bits which should be ignored in the final byte.
Definition cbs.h:146
size_t data_size
The number of bytes in the bitstream.
Definition cbs.h:142
uint8_t * data
Pointer to the bitstream form of this fragment.
Definition cbs.h:135
struct FFHWBaseEncodePicture * refs[MAX_REFERENCE_LIST_NUM][MAX_PICTURE_REFERENCES]
MPEG2RawPictureCodingExtension picture_coding
Definition cbs_mpeg2.h:185
uint8_t extension_start_code
Definition cbs_mpeg2.h:178
MPEG2RawSequenceDisplayExtension sequence_display
Definition cbs_mpeg2.h:183
MPEG2RawSequenceExtension sequence
Definition cbs_mpeg2.h:182
union MPEG2RawExtensionData::@070215134007105004266170356251251155306352224353 data
uint8_t extension_start_code_identifier
Definition cbs_mpeg2.h:179
uint8_t sequence_header_code
Definition cbs_mpeg2.h:60
uint8_t constrained_parameters_flag
Definition cbs_mpeg2.h:68
uint8_t aspect_ratio_information
Definition cbs_mpeg2.h:64
uint16_t horizontal_size_value
Definition cbs_mpeg2.h:62
uint16_t vbv_buffer_size_value
Definition cbs_mpeg2.h:67
uint16_t vertical_size_value
Definition cbs_mpeg2.h:63
uint8_t load_non_intra_quantiser_matrix
Definition cbs_mpeg2.h:72
uint8_t load_intra_quantiser_matrix
Definition cbs_mpeg2.h:70
MPEG2RawGroupOfPicturesHeader gop_header
MPEG2RawPictureHeader picture_header
MPEG2RawExtensionData sequence_extension
CodedBitstreamContext * cbc
MPEG2RawExtensionData picture_coding_extension
MPEG2RawSequenceHeader sequence_header
MPEG2RawExtensionData sequence_display_extension
VAAPIEncodeContext common
CodedBitstreamFragment current_fragment
void * codec_picture_params
VASurfaceID recon_surface
VABufferID output_buffer
void * codec_slice_params
uint8_t level
Definition svq3.c:208
#define av_log(a,...)
#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)
#define OFFSET(x)
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)