2016-03-24 01:49:35 +02:00
|
|
|
/*
|
2016-05-08 23:43:52 +02:00
|
|
|
* This file is part of FFmpeg.
|
2016-03-24 01:49:35 +02:00
|
|
|
*
|
2016-05-08 23:43:52 +02:00
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2016-03-24 01:49:35 +02:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
2016-05-08 23:43:52 +02:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2016-03-24 01:49:35 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2016-05-08 23:43:52 +02:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2016-03-24 01:49:35 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
2016-03-24 01:49:35 +02:00
|
|
|
#include <va/va.h>
|
|
|
|
#include <va/va_enc_h264.h>
|
|
|
|
|
|
|
|
#include "libavutil/avassert.h"
|
2017-05-07 16:01:42 +02:00
|
|
|
#include "libavutil/common.h"
|
2016-03-24 01:49:35 +02:00
|
|
|
#include "libavutil/internal.h"
|
|
|
|
#include "libavutil/opt.h"
|
|
|
|
|
2023-01-09 20:40:24 +02:00
|
|
|
#include "atsc_a53.h"
|
2016-03-24 01:49:35 +02:00
|
|
|
#include "avcodec.h"
|
2017-05-07 16:01:42 +02:00
|
|
|
#include "cbs.h"
|
|
|
|
#include "cbs_h264.h"
|
2022-03-16 19:18:28 +02:00
|
|
|
#include "codec_internal.h"
|
2016-05-18 09:16:35 +02:00
|
|
|
#include "h264.h"
|
2018-09-19 00:30:58 +02:00
|
|
|
#include "h264_levels.h"
|
2016-05-17 16:52:58 +02:00
|
|
|
#include "h264_sei.h"
|
2021-11-19 20:50:49 +02:00
|
|
|
#include "h2645data.h"
|
2016-03-24 01:49:35 +02:00
|
|
|
#include "vaapi_encode.h"
|
2022-02-23 12:55:45 +02:00
|
|
|
#include "version.h"
|
2016-03-24 01:49:35 +02:00
|
|
|
|
|
|
|
enum {
|
2017-05-07 16:01:42 +02:00
|
|
|
SEI_TIMING = 0x01,
|
|
|
|
SEI_IDENTIFIER = 0x02,
|
2017-05-08 00:02:09 +02:00
|
|
|
SEI_RECOVERY_POINT = 0x04,
|
2023-01-09 20:40:24 +02:00
|
|
|
SEI_A53_CC = 0x08,
|
2016-03-24 01:49:35 +02:00
|
|
|
};
|
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
// Random (version 4) ISO 11578 UUID.
|
|
|
|
static const uint8_t vaapi_encode_h264_sei_identifier_uuid[16] = {
|
|
|
|
0x59, 0x94, 0x8b, 0x28, 0x11, 0xec, 0x45, 0xaf,
|
|
|
|
0x96, 0x75, 0x19, 0xd4, 0x1f, 0xea, 0xa9, 0x4d,
|
|
|
|
};
|
2016-03-24 01:49:35 +02:00
|
|
|
|
2018-12-20 22:39:58 +02:00
|
|
|
typedef struct VAAPIEncodeH264Picture {
|
|
|
|
int frame_num;
|
|
|
|
int pic_order_cnt;
|
|
|
|
|
|
|
|
int64_t last_idr_frame;
|
|
|
|
uint16_t idr_pic_id;
|
|
|
|
|
|
|
|
int primary_pic_type;
|
|
|
|
int slice_type;
|
|
|
|
|
|
|
|
int cpb_delay;
|
|
|
|
int dpb_delay;
|
|
|
|
} VAAPIEncodeH264Picture;
|
|
|
|
|
2016-03-24 01:49:35 +02:00
|
|
|
typedef struct VAAPIEncodeH264Context {
|
2018-08-23 01:44:34 +02:00
|
|
|
VAAPIEncodeContext common;
|
|
|
|
|
|
|
|
// User options.
|
|
|
|
int qp;
|
|
|
|
int quality;
|
|
|
|
int coder;
|
|
|
|
int aud;
|
|
|
|
int sei;
|
|
|
|
int profile;
|
|
|
|
int level;
|
|
|
|
|
|
|
|
// Derived settings.
|
2016-03-24 01:49:35 +02:00
|
|
|
int mb_width;
|
|
|
|
int mb_height;
|
|
|
|
|
|
|
|
int fixed_qp_idr;
|
|
|
|
int fixed_qp_p;
|
|
|
|
int fixed_qp_b;
|
|
|
|
|
2018-12-20 22:39:58 +02:00
|
|
|
int dpb_frames;
|
2016-05-17 16:52:58 +02:00
|
|
|
|
2018-08-23 01:44:34 +02:00
|
|
|
// Writer structures.
|
2017-05-07 16:01:42 +02:00
|
|
|
CodedBitstreamContext *cbc;
|
|
|
|
CodedBitstreamFragment current_access_unit;
|
2018-08-23 01:44:34 +02:00
|
|
|
|
|
|
|
H264RawAUD raw_aud;
|
|
|
|
H264RawSPS raw_sps;
|
|
|
|
H264RawPPS raw_pps;
|
|
|
|
H264RawSlice raw_slice;
|
|
|
|
|
|
|
|
H264RawSEIBufferingPeriod sei_buffering_period;
|
|
|
|
H264RawSEIPicTiming sei_pic_timing;
|
|
|
|
H264RawSEIRecoveryPoint sei_recovery_point;
|
2021-01-01 23:35:11 +02:00
|
|
|
SEIRawUserDataUnregistered sei_identifier;
|
2018-08-23 01:44:34 +02:00
|
|
|
char *sei_identifier_string;
|
2023-01-09 20:40:24 +02:00
|
|
|
SEIRawUserDataRegistered sei_a53cc;
|
|
|
|
void *sei_a53cc_data;
|
2018-08-23 01:44:34 +02:00
|
|
|
|
2017-05-07 23:58:56 +02:00
|
|
|
int aud_needed;
|
2017-05-07 16:01:42 +02:00
|
|
|
int sei_needed;
|
2017-10-25 01:15:55 +02:00
|
|
|
int sei_cbr_workaround_needed;
|
2016-03-24 01:49:35 +02:00
|
|
|
} VAAPIEncodeH264Context;
|
|
|
|
|
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
static int vaapi_encode_h264_write_access_unit(AVCodecContext *avctx,
|
|
|
|
char *data, size_t *data_len,
|
|
|
|
CodedBitstreamFragment *au)
|
2016-03-24 01:49:35 +02:00
|
|
|
{
|
2018-08-23 01:44:34 +02:00
|
|
|
VAAPIEncodeH264Context *priv = avctx->priv_data;
|
2017-05-07 16:01:42 +02:00
|
|
|
int err;
|
2016-03-24 01:49:35 +02:00
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
err = ff_cbs_write_fragment_data(priv->cbc, au);
|
|
|
|
if (err < 0) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Failed to write packed header.\n");
|
|
|
|
return err;
|
2016-03-24 01:49:35 +02:00
|
|
|
}
|
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
if (*data_len < 8 * au->data_size - au->data_bit_padding) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Access unit too large: "
|
|
|
|
"%zu < %zu.\n", *data_len,
|
|
|
|
8 * au->data_size - au->data_bit_padding);
|
|
|
|
return AVERROR(ENOSPC);
|
2016-05-17 16:52:58 +02:00
|
|
|
}
|
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
memcpy(data, au->data, au->data_size);
|
|
|
|
*data_len = 8 * au->data_size - au->data_bit_padding;
|
2016-05-17 16:52:58 +02:00
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
return 0;
|
2016-05-18 11:19:07 +02:00
|
|
|
}
|
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
static int vaapi_encode_h264_add_nal(AVCodecContext *avctx,
|
|
|
|
CodedBitstreamFragment *au,
|
|
|
|
void *nal_unit)
|
2016-05-17 16:52:58 +02:00
|
|
|
{
|
2017-05-07 16:01:42 +02:00
|
|
|
H264RawNALUnitHeader *header = nal_unit;
|
|
|
|
int err;
|
2016-05-17 16:52:58 +02:00
|
|
|
|
2020-07-06 00:34:25 +02:00
|
|
|
err = ff_cbs_insert_unit_content(au, -1,
|
2018-02-11 02:51:33 +02:00
|
|
|
header->nal_unit_type, nal_unit, NULL);
|
2017-05-07 16:01:42 +02:00
|
|
|
if (err < 0) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Failed to add NAL unit: "
|
|
|
|
"type = %d.\n", header->nal_unit_type);
|
|
|
|
return err;
|
2016-05-17 16:52:58 +02:00
|
|
|
}
|
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
return 0;
|
2016-05-17 16:52:58 +02:00
|
|
|
}
|
|
|
|
|
2016-03-24 01:49:35 +02:00
|
|
|
static int vaapi_encode_h264_write_sequence_header(AVCodecContext *avctx,
|
|
|
|
char *data, size_t *data_len)
|
|
|
|
{
|
2018-08-23 01:44:34 +02:00
|
|
|
VAAPIEncodeH264Context *priv = avctx->priv_data;
|
2017-05-07 16:01:42 +02:00
|
|
|
CodedBitstreamFragment *au = &priv->current_access_unit;
|
2016-03-24 01:49:35 +02:00
|
|
|
int err;
|
|
|
|
|
2017-05-07 23:58:56 +02:00
|
|
|
if (priv->aud_needed) {
|
2018-08-23 01:44:34 +02:00
|
|
|
err = vaapi_encode_h264_add_nal(avctx, au, &priv->raw_aud);
|
2017-05-07 23:58:56 +02:00
|
|
|
if (err < 0)
|
|
|
|
goto fail;
|
|
|
|
priv->aud_needed = 0;
|
|
|
|
}
|
|
|
|
|
2018-08-23 01:44:34 +02:00
|
|
|
err = vaapi_encode_h264_add_nal(avctx, au, &priv->raw_sps);
|
2016-03-24 01:49:35 +02:00
|
|
|
if (err < 0)
|
2017-05-07 16:01:42 +02:00
|
|
|
goto fail;
|
2016-03-24 01:49:35 +02:00
|
|
|
|
2018-08-23 01:44:34 +02:00
|
|
|
err = vaapi_encode_h264_add_nal(avctx, au, &priv->raw_pps);
|
2016-03-24 01:49:35 +02:00
|
|
|
if (err < 0)
|
2017-05-07 16:01:42 +02:00
|
|
|
goto fail;
|
2016-03-24 01:49:35 +02:00
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
err = vaapi_encode_h264_write_access_unit(avctx, data, data_len, au);
|
|
|
|
fail:
|
2020-07-06 00:34:25 +02:00
|
|
|
ff_cbs_fragment_reset(au);
|
2017-05-07 16:01:42 +02:00
|
|
|
return err;
|
2016-03-24 01:49:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int vaapi_encode_h264_write_slice_header(AVCodecContext *avctx,
|
|
|
|
VAAPIEncodePicture *pic,
|
|
|
|
VAAPIEncodeSlice *slice,
|
|
|
|
char *data, size_t *data_len)
|
|
|
|
{
|
2018-08-23 01:44:34 +02:00
|
|
|
VAAPIEncodeH264Context *priv = avctx->priv_data;
|
2017-05-07 16:01:42 +02:00
|
|
|
CodedBitstreamFragment *au = &priv->current_access_unit;
|
|
|
|
int err;
|
2016-03-24 01:49:35 +02:00
|
|
|
|
2017-05-07 23:58:56 +02:00
|
|
|
if (priv->aud_needed) {
|
2018-08-23 01:44:34 +02:00
|
|
|
err = vaapi_encode_h264_add_nal(avctx, au, &priv->raw_aud);
|
2017-05-07 23:58:56 +02:00
|
|
|
if (err < 0)
|
|
|
|
goto fail;
|
|
|
|
priv->aud_needed = 0;
|
|
|
|
}
|
|
|
|
|
2018-08-23 01:44:34 +02:00
|
|
|
err = vaapi_encode_h264_add_nal(avctx, au, &priv->raw_slice);
|
2017-05-07 16:01:42 +02:00
|
|
|
if (err < 0)
|
|
|
|
goto fail;
|
2016-03-24 01:49:35 +02:00
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
err = vaapi_encode_h264_write_access_unit(avctx, data, data_len, au);
|
|
|
|
fail:
|
2020-07-06 00:34:25 +02:00
|
|
|
ff_cbs_fragment_reset(au);
|
2017-05-07 16:01:42 +02:00
|
|
|
return err;
|
2016-03-24 01:49:35 +02:00
|
|
|
}
|
|
|
|
|
2016-05-17 16:52:58 +02:00
|
|
|
static int vaapi_encode_h264_write_extra_header(AVCodecContext *avctx,
|
|
|
|
VAAPIEncodePicture *pic,
|
|
|
|
int index, int *type,
|
|
|
|
char *data, size_t *data_len)
|
|
|
|
{
|
2018-08-23 01:44:34 +02:00
|
|
|
VAAPIEncodeH264Context *priv = avctx->priv_data;
|
2017-05-07 16:01:42 +02:00
|
|
|
CodedBitstreamFragment *au = &priv->current_access_unit;
|
2021-01-01 23:35:13 +02:00
|
|
|
int err;
|
2017-05-07 16:01:42 +02:00
|
|
|
|
|
|
|
if (priv->sei_needed) {
|
2017-05-07 23:58:56 +02:00
|
|
|
if (priv->aud_needed) {
|
2018-08-23 01:44:34 +02:00
|
|
|
err = vaapi_encode_h264_add_nal(avctx, au, &priv->raw_aud);
|
2017-10-18 20:39:10 +02:00
|
|
|
if (err < 0)
|
|
|
|
goto fail;
|
2017-05-07 23:58:56 +02:00
|
|
|
priv->aud_needed = 0;
|
|
|
|
}
|
|
|
|
|
2018-05-03 07:51:48 +02:00
|
|
|
if (priv->sei_needed & SEI_IDENTIFIER) {
|
2021-01-01 23:35:13 +02:00
|
|
|
err = ff_cbs_sei_add_message(priv->cbc, au, 1,
|
|
|
|
SEI_TYPE_USER_DATA_UNREGISTERED,
|
|
|
|
&priv->sei_identifier, NULL);
|
|
|
|
if (err < 0)
|
|
|
|
goto fail;
|
2017-05-07 16:01:42 +02:00
|
|
|
}
|
2018-05-03 07:51:48 +02:00
|
|
|
if (priv->sei_needed & SEI_TIMING) {
|
2017-05-07 16:01:42 +02:00
|
|
|
if (pic->type == PICTURE_TYPE_IDR) {
|
2021-01-01 23:35:13 +02:00
|
|
|
err = ff_cbs_sei_add_message(priv->cbc, au, 1,
|
|
|
|
SEI_TYPE_BUFFERING_PERIOD,
|
|
|
|
&priv->sei_buffering_period, NULL);
|
|
|
|
if (err < 0)
|
|
|
|
goto fail;
|
2017-05-07 16:01:42 +02:00
|
|
|
}
|
2021-01-01 23:35:13 +02:00
|
|
|
err = ff_cbs_sei_add_message(priv->cbc, au, 1,
|
|
|
|
SEI_TYPE_PIC_TIMING,
|
|
|
|
&priv->sei_pic_timing, NULL);
|
|
|
|
if (err < 0)
|
|
|
|
goto fail;
|
2017-05-07 16:01:42 +02:00
|
|
|
}
|
2018-05-03 07:51:48 +02:00
|
|
|
if (priv->sei_needed & SEI_RECOVERY_POINT) {
|
2021-01-01 23:35:13 +02:00
|
|
|
err = ff_cbs_sei_add_message(priv->cbc, au, 1,
|
|
|
|
SEI_TYPE_RECOVERY_POINT,
|
|
|
|
&priv->sei_recovery_point, NULL);
|
|
|
|
if (err < 0)
|
|
|
|
goto fail;
|
2017-05-08 00:02:09 +02:00
|
|
|
}
|
2023-01-09 20:40:24 +02:00
|
|
|
if (priv->sei_needed & SEI_A53_CC) {
|
|
|
|
err = ff_cbs_sei_add_message(priv->cbc, au, 1,
|
|
|
|
SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35,
|
|
|
|
&priv->sei_a53cc, NULL);
|
|
|
|
if (err < 0)
|
|
|
|
goto fail;
|
|
|
|
}
|
2016-05-17 16:52:58 +02:00
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
priv->sei_needed = 0;
|
2016-05-17 16:52:58 +02:00
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
err = vaapi_encode_h264_write_access_unit(avctx, data, data_len, au);
|
|
|
|
if (err < 0)
|
|
|
|
goto fail;
|
2016-05-17 16:52:58 +02:00
|
|
|
|
2020-07-06 00:34:25 +02:00
|
|
|
ff_cbs_fragment_reset(au);
|
2017-05-07 16:01:42 +02:00
|
|
|
|
2017-10-18 20:46:53 +02:00
|
|
|
*type = VAEncPackedHeaderRawData;
|
2017-05-07 16:01:42 +02:00
|
|
|
return 0;
|
2017-10-25 01:15:55 +02:00
|
|
|
|
2017-11-16 01:43:56 +02:00
|
|
|
#if !CONFIG_VAAPI_1
|
2017-10-25 01:15:55 +02:00
|
|
|
} else if (priv->sei_cbr_workaround_needed) {
|
|
|
|
// Insert a zero-length header using the old SEI type. This is
|
|
|
|
// required to avoid triggering broken behaviour on Intel platforms
|
|
|
|
// in CBR mode where an invalid SEI message is generated by the
|
|
|
|
// driver and inserted into the stream.
|
|
|
|
*data_len = 0;
|
|
|
|
*type = VAEncPackedHeaderH264_SEI;
|
|
|
|
priv->sei_cbr_workaround_needed = 0;
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
|
2016-05-17 16:52:58 +02:00
|
|
|
} else {
|
|
|
|
return AVERROR_EOF;
|
|
|
|
}
|
2017-05-07 16:01:42 +02:00
|
|
|
|
|
|
|
fail:
|
2020-07-06 00:34:25 +02:00
|
|
|
ff_cbs_fragment_reset(au);
|
2017-05-07 16:01:42 +02:00
|
|
|
return err;
|
2016-05-17 16:52:58 +02:00
|
|
|
}
|
|
|
|
|
2016-03-24 01:49:35 +02:00
|
|
|
static int vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx)
|
|
|
|
{
|
2017-05-07 16:01:42 +02:00
|
|
|
VAAPIEncodeContext *ctx = avctx->priv_data;
|
2018-08-23 01:44:34 +02:00
|
|
|
VAAPIEncodeH264Context *priv = avctx->priv_data;
|
|
|
|
H264RawSPS *sps = &priv->raw_sps;
|
|
|
|
H264RawPPS *pps = &priv->raw_pps;
|
2017-05-07 16:01:42 +02:00
|
|
|
VAEncSequenceParameterBufferH264 *vseq = ctx->codec_sequence_params;
|
|
|
|
VAEncPictureParameterBufferH264 *vpic = ctx->codec_picture_params;
|
2016-03-24 01:49:35 +02:00
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
memset(sps, 0, sizeof(*sps));
|
|
|
|
memset(pps, 0, sizeof(*pps));
|
2016-03-24 01:49:35 +02:00
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
sps->nal_unit_header.nal_ref_idc = 3;
|
|
|
|
sps->nal_unit_header.nal_unit_type = H264_NAL_SPS;
|
2016-03-24 01:49:35 +02:00
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
sps->profile_idc = avctx->profile & 0xff;
|
2018-09-19 00:30:49 +02:00
|
|
|
|
|
|
|
if (avctx->profile == FF_PROFILE_H264_CONSTRAINED_BASELINE ||
|
|
|
|
avctx->profile == FF_PROFILE_H264_MAIN)
|
|
|
|
sps->constraint_set1_flag = 1;
|
|
|
|
|
|
|
|
if (avctx->profile == FF_PROFILE_H264_HIGH)
|
|
|
|
sps->constraint_set3_flag = ctx->gop_size == 1;
|
|
|
|
|
|
|
|
if (avctx->profile == FF_PROFILE_H264_MAIN ||
|
|
|
|
avctx->profile == FF_PROFILE_H264_HIGH) {
|
|
|
|
sps->constraint_set4_flag = 1;
|
|
|
|
sps->constraint_set5_flag = ctx->b_per_p == 0;
|
|
|
|
}
|
2016-03-24 01:49:35 +02:00
|
|
|
|
2018-09-19 00:30:58 +02:00
|
|
|
if (ctx->gop_size == 1)
|
2018-12-20 22:39:58 +02:00
|
|
|
priv->dpb_frames = 0;
|
2018-09-19 00:30:58 +02:00
|
|
|
else
|
2018-12-20 22:39:58 +02:00
|
|
|
priv->dpb_frames = 1 + ctx->max_b_depth;
|
2018-09-19 00:30:58 +02:00
|
|
|
|
|
|
|
if (avctx->level != FF_LEVEL_UNKNOWN) {
|
|
|
|
sps->level_idc = avctx->level;
|
|
|
|
} else {
|
|
|
|
const H264LevelDescriptor *level;
|
2019-03-20 11:14:47 +02:00
|
|
|
int framerate;
|
|
|
|
|
|
|
|
if (avctx->framerate.num > 0 && avctx->framerate.den > 0)
|
|
|
|
framerate = avctx->framerate.num / avctx->framerate.den;
|
|
|
|
else
|
|
|
|
framerate = 0;
|
2018-09-19 00:30:58 +02:00
|
|
|
|
|
|
|
level = ff_h264_guess_level(sps->profile_idc,
|
|
|
|
avctx->bit_rate,
|
2019-03-20 11:14:47 +02:00
|
|
|
framerate,
|
2018-09-19 00:30:58 +02:00
|
|
|
priv->mb_width * 16,
|
|
|
|
priv->mb_height * 16,
|
2018-12-20 22:39:58 +02:00
|
|
|
priv->dpb_frames);
|
2018-09-19 00:30:58 +02:00
|
|
|
if (level) {
|
|
|
|
av_log(avctx, AV_LOG_VERBOSE, "Using level %s.\n", level->name);
|
|
|
|
if (level->constraint_set3_flag)
|
|
|
|
sps->constraint_set3_flag = 1;
|
|
|
|
sps->level_idc = level->level_idc;
|
|
|
|
} else {
|
|
|
|
av_log(avctx, AV_LOG_WARNING, "Stream will not conform "
|
|
|
|
"to any level: using level 6.2.\n");
|
|
|
|
sps->level_idc = 62;
|
|
|
|
}
|
|
|
|
}
|
2016-03-24 01:49:35 +02:00
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
sps->seq_parameter_set_id = 0;
|
|
|
|
sps->chroma_format_idc = 1;
|
2016-03-24 01:49:35 +02:00
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
sps->log2_max_frame_num_minus4 = 4;
|
2023-01-17 13:17:58 +02:00
|
|
|
sps->pic_order_cnt_type = ctx->max_b_depth ? 0 : 2;
|
|
|
|
if (sps->pic_order_cnt_type == 0) {
|
|
|
|
sps->log2_max_pic_order_cnt_lsb_minus4 = 4;
|
|
|
|
}
|
2017-05-07 16:01:42 +02:00
|
|
|
|
2018-12-20 22:39:58 +02:00
|
|
|
sps->max_num_ref_frames = priv->dpb_frames;
|
2017-05-07 16:01:42 +02:00
|
|
|
|
|
|
|
sps->pic_width_in_mbs_minus1 = priv->mb_width - 1;
|
|
|
|
sps->pic_height_in_map_units_minus1 = priv->mb_height - 1;
|
|
|
|
|
|
|
|
sps->frame_mbs_only_flag = 1;
|
|
|
|
sps->direct_8x8_inference_flag = 1;
|
2016-04-13 00:14:23 +02:00
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
if (avctx->width != 16 * priv->mb_width ||
|
|
|
|
avctx->height != 16 * priv->mb_height) {
|
|
|
|
sps->frame_cropping_flag = 1;
|
|
|
|
|
|
|
|
sps->frame_crop_left_offset = 0;
|
|
|
|
sps->frame_crop_right_offset =
|
|
|
|
(16 * priv->mb_width - avctx->width) / 2;
|
|
|
|
sps->frame_crop_top_offset = 0;
|
|
|
|
sps->frame_crop_bottom_offset =
|
|
|
|
(16 * priv->mb_height - avctx->height) / 2;
|
|
|
|
} else {
|
|
|
|
sps->frame_cropping_flag = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sps->vui_parameters_present_flag = 1;
|
|
|
|
|
|
|
|
if (avctx->sample_aspect_ratio.num != 0 &&
|
|
|
|
avctx->sample_aspect_ratio.den != 0) {
|
2018-10-28 19:13:53 +02:00
|
|
|
int num, den, i;
|
|
|
|
av_reduce(&num, &den, avctx->sample_aspect_ratio.num,
|
|
|
|
avctx->sample_aspect_ratio.den, 65535);
|
2021-11-19 20:50:49 +02:00
|
|
|
for (i = 0; i < FF_ARRAY_ELEMS(ff_h2645_pixel_aspect); i++) {
|
|
|
|
if (num == ff_h2645_pixel_aspect[i].num &&
|
|
|
|
den == ff_h2645_pixel_aspect[i].den) {
|
2017-05-07 16:01:42 +02:00
|
|
|
sps->vui.aspect_ratio_idc = i;
|
|
|
|
break;
|
2016-05-17 16:14:57 +02:00
|
|
|
}
|
|
|
|
}
|
2021-11-19 20:50:49 +02:00
|
|
|
if (i >= FF_ARRAY_ELEMS(ff_h2645_pixel_aspect)) {
|
2017-05-07 16:01:42 +02:00
|
|
|
sps->vui.aspect_ratio_idc = 255;
|
2018-10-28 19:13:53 +02:00
|
|
|
sps->vui.sar_width = num;
|
|
|
|
sps->vui.sar_height = den;
|
2017-05-07 16:01:42 +02:00
|
|
|
}
|
|
|
|
sps->vui.aspect_ratio_info_present_flag = 1;
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:46:47 +02:00
|
|
|
// Unspecified video format, from table E-2.
|
|
|
|
sps->vui.video_format = 5;
|
|
|
|
sps->vui.video_full_range_flag =
|
|
|
|
avctx->color_range == AVCOL_RANGE_JPEG;
|
|
|
|
sps->vui.colour_primaries = avctx->color_primaries;
|
|
|
|
sps->vui.transfer_characteristics = avctx->color_trc;
|
|
|
|
sps->vui.matrix_coefficients = avctx->colorspace;
|
|
|
|
if (avctx->color_primaries != AVCOL_PRI_UNSPECIFIED ||
|
2017-05-07 16:01:42 +02:00
|
|
|
avctx->color_trc != AVCOL_TRC_UNSPECIFIED ||
|
2020-11-03 00:46:47 +02:00
|
|
|
avctx->colorspace != AVCOL_SPC_UNSPECIFIED)
|
|
|
|
sps->vui.colour_description_present_flag = 1;
|
|
|
|
if (avctx->color_range != AVCOL_RANGE_UNSPECIFIED ||
|
|
|
|
sps->vui.colour_description_present_flag)
|
2017-05-07 16:01:42 +02:00
|
|
|
sps->vui.video_signal_type_present_flag = 1;
|
2016-05-17 16:14:57 +02:00
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
if (avctx->chroma_sample_location != AVCHROMA_LOC_UNSPECIFIED) {
|
|
|
|
sps->vui.chroma_loc_info_present_flag = 1;
|
|
|
|
sps->vui.chroma_sample_loc_type_top_field =
|
|
|
|
sps->vui.chroma_sample_loc_type_bottom_field =
|
|
|
|
avctx->chroma_sample_location - 1;
|
|
|
|
}
|
2016-05-17 16:14:57 +02:00
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
sps->vui.timing_info_present_flag = 1;
|
|
|
|
if (avctx->framerate.num > 0 && avctx->framerate.den > 0) {
|
|
|
|
sps->vui.num_units_in_tick = avctx->framerate.den;
|
|
|
|
sps->vui.time_scale = 2 * avctx->framerate.num;
|
|
|
|
sps->vui.fixed_frame_rate_flag = 1;
|
|
|
|
} else {
|
|
|
|
sps->vui.num_units_in_tick = avctx->time_base.num;
|
|
|
|
sps->vui.time_scale = 2 * avctx->time_base.den;
|
|
|
|
sps->vui.fixed_frame_rate_flag = 0;
|
|
|
|
}
|
2016-04-13 00:14:23 +02:00
|
|
|
|
2018-08-23 01:44:34 +02:00
|
|
|
if (priv->sei & SEI_TIMING) {
|
2017-05-07 16:01:42 +02:00
|
|
|
H264RawHRD *hrd = &sps->vui.nal_hrd_parameters;
|
2018-08-23 01:44:34 +02:00
|
|
|
H264RawSEIBufferingPeriod *bp = &priv->sei_buffering_period;
|
2016-05-17 16:52:58 +02:00
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
sps->vui.nal_hrd_parameters_present_flag = 1;
|
2016-05-17 16:52:58 +02:00
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
hrd->cpb_cnt_minus1 = 0;
|
2016-05-17 16:52:58 +02:00
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
// Try to scale these to a sensible range so that the
|
|
|
|
// golomb encode of the value is not overlong.
|
|
|
|
hrd->bit_rate_scale =
|
2018-09-19 00:30:45 +02:00
|
|
|
av_clip_uintp2(av_log2(ctx->va_bit_rate) - 15 - 6, 4);
|
2017-05-07 16:01:42 +02:00
|
|
|
hrd->bit_rate_value_minus1[0] =
|
2018-09-19 00:30:45 +02:00
|
|
|
(ctx->va_bit_rate >> hrd->bit_rate_scale + 6) - 1;
|
2016-05-17 16:52:58 +02:00
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
hrd->cpb_size_scale =
|
2019-05-06 17:21:29 +02:00
|
|
|
av_clip_uintp2(av_log2(ctx->hrd_params.buffer_size) - 15 - 4, 4);
|
2017-05-07 16:01:42 +02:00
|
|
|
hrd->cpb_size_value_minus1[0] =
|
2019-05-06 17:21:29 +02:00
|
|
|
(ctx->hrd_params.buffer_size >> hrd->cpb_size_scale + 4) - 1;
|
2016-05-17 16:52:58 +02:00
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
// CBR mode as defined for the HRD cannot be achieved without filler
|
|
|
|
// data, so this flag cannot be set even with VAAPI CBR modes.
|
|
|
|
hrd->cbr_flag[0] = 0;
|
2016-05-17 16:52:58 +02:00
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
hrd->initial_cpb_removal_delay_length_minus1 = 23;
|
|
|
|
hrd->cpb_removal_delay_length_minus1 = 23;
|
|
|
|
hrd->dpb_output_delay_length_minus1 = 7;
|
|
|
|
hrd->time_offset_length = 0;
|
2016-05-17 16:52:58 +02:00
|
|
|
|
2018-08-23 01:44:34 +02:00
|
|
|
bp->seq_parameter_set_id = sps->seq_parameter_set_id;
|
2016-05-17 16:52:58 +02:00
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
// This calculation can easily overflow 32 bits.
|
2018-08-23 01:44:34 +02:00
|
|
|
bp->nal.initial_cpb_removal_delay[0] = 90000 *
|
2019-05-06 17:21:29 +02:00
|
|
|
(uint64_t)ctx->hrd_params.initial_buffer_fullness /
|
|
|
|
ctx->hrd_params.buffer_size;
|
2018-08-23 01:44:34 +02:00
|
|
|
bp->nal.initial_cpb_removal_delay_offset[0] = 0;
|
2017-05-07 16:01:42 +02:00
|
|
|
} else {
|
|
|
|
sps->vui.nal_hrd_parameters_present_flag = 0;
|
|
|
|
sps->vui.low_delay_hrd_flag = 1 - sps->vui.fixed_frame_rate_flag;
|
2016-03-24 01:49:35 +02:00
|
|
|
}
|
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
sps->vui.bitstream_restriction_flag = 1;
|
|
|
|
sps->vui.motion_vectors_over_pic_boundaries_flag = 1;
|
2018-09-19 00:31:00 +02:00
|
|
|
sps->vui.log2_max_mv_length_horizontal = 15;
|
|
|
|
sps->vui.log2_max_mv_length_vertical = 15;
|
2018-12-20 22:39:58 +02:00
|
|
|
sps->vui.max_num_reorder_frames = ctx->max_b_depth;
|
|
|
|
sps->vui.max_dec_frame_buffering = ctx->max_b_depth + 1;
|
2016-03-24 01:49:35 +02:00
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
pps->nal_unit_header.nal_ref_idc = 3;
|
|
|
|
pps->nal_unit_header.nal_unit_type = H264_NAL_PPS;
|
2016-03-24 01:49:35 +02:00
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
pps->pic_parameter_set_id = 0;
|
|
|
|
pps->seq_parameter_set_id = 0;
|
2016-03-24 01:49:35 +02:00
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
pps->entropy_coding_mode_flag =
|
|
|
|
!(sps->profile_idc == FF_PROFILE_H264_BASELINE ||
|
|
|
|
sps->profile_idc == FF_PROFILE_H264_EXTENDED ||
|
|
|
|
sps->profile_idc == FF_PROFILE_H264_CAVLC_444);
|
2018-08-23 01:44:34 +02:00
|
|
|
if (!priv->coder && pps->entropy_coding_mode_flag)
|
2017-05-07 16:01:42 +02:00
|
|
|
pps->entropy_coding_mode_flag = 0;
|
2016-03-24 01:49:35 +02:00
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
pps->num_ref_idx_l0_default_active_minus1 = 0;
|
|
|
|
pps->num_ref_idx_l1_default_active_minus1 = 0;
|
2016-03-24 01:49:35 +02:00
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
pps->pic_init_qp_minus26 = priv->fixed_qp_idr - 26;
|
2016-03-24 01:49:35 +02:00
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
if (sps->profile_idc == FF_PROFILE_H264_BASELINE ||
|
|
|
|
sps->profile_idc == FF_PROFILE_H264_EXTENDED ||
|
|
|
|
sps->profile_idc == FF_PROFILE_H264_MAIN) {
|
|
|
|
pps->more_rbsp_data = 0;
|
|
|
|
} else {
|
|
|
|
pps->more_rbsp_data = 1;
|
|
|
|
|
|
|
|
pps->transform_8x8_mode_flag = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*vseq = (VAEncSequenceParameterBufferH264) {
|
|
|
|
.seq_parameter_set_id = sps->seq_parameter_set_id,
|
|
|
|
.level_idc = sps->level_idc,
|
2018-09-19 00:30:47 +02:00
|
|
|
.intra_period = ctx->gop_size,
|
|
|
|
.intra_idr_period = ctx->gop_size,
|
2017-05-07 16:01:42 +02:00
|
|
|
.ip_period = ctx->b_per_p + 1,
|
|
|
|
|
2018-09-19 00:30:45 +02:00
|
|
|
.bits_per_second = ctx->va_bit_rate,
|
2017-05-07 16:01:42 +02:00
|
|
|
.max_num_ref_frames = sps->max_num_ref_frames,
|
|
|
|
.picture_width_in_mbs = sps->pic_width_in_mbs_minus1 + 1,
|
|
|
|
.picture_height_in_mbs = sps->pic_height_in_map_units_minus1 + 1,
|
|
|
|
|
|
|
|
.seq_fields.bits = {
|
|
|
|
.chroma_format_idc = sps->chroma_format_idc,
|
|
|
|
.frame_mbs_only_flag = sps->frame_mbs_only_flag,
|
|
|
|
.mb_adaptive_frame_field_flag = sps->mb_adaptive_frame_field_flag,
|
|
|
|
.seq_scaling_matrix_present_flag = sps->seq_scaling_matrix_present_flag,
|
|
|
|
.direct_8x8_inference_flag = sps->direct_8x8_inference_flag,
|
|
|
|
.log2_max_frame_num_minus4 = sps->log2_max_frame_num_minus4,
|
|
|
|
.pic_order_cnt_type = sps->pic_order_cnt_type,
|
|
|
|
.log2_max_pic_order_cnt_lsb_minus4 = sps->log2_max_pic_order_cnt_lsb_minus4,
|
|
|
|
.delta_pic_order_always_zero_flag = sps->delta_pic_order_always_zero_flag,
|
|
|
|
},
|
|
|
|
|
|
|
|
.bit_depth_luma_minus8 = sps->bit_depth_luma_minus8,
|
|
|
|
.bit_depth_chroma_minus8 = sps->bit_depth_chroma_minus8,
|
|
|
|
|
|
|
|
.frame_cropping_flag = sps->frame_cropping_flag,
|
|
|
|
.frame_crop_left_offset = sps->frame_crop_left_offset,
|
|
|
|
.frame_crop_right_offset = sps->frame_crop_right_offset,
|
|
|
|
.frame_crop_top_offset = sps->frame_crop_top_offset,
|
|
|
|
.frame_crop_bottom_offset = sps->frame_crop_bottom_offset,
|
|
|
|
|
|
|
|
.vui_parameters_present_flag = sps->vui_parameters_present_flag,
|
|
|
|
|
|
|
|
.vui_fields.bits = {
|
|
|
|
.aspect_ratio_info_present_flag = sps->vui.aspect_ratio_info_present_flag,
|
|
|
|
.timing_info_present_flag = sps->vui.timing_info_present_flag,
|
|
|
|
.bitstream_restriction_flag = sps->vui.bitstream_restriction_flag,
|
|
|
|
.log2_max_mv_length_horizontal = sps->vui.log2_max_mv_length_horizontal,
|
|
|
|
.log2_max_mv_length_vertical = sps->vui.log2_max_mv_length_vertical,
|
|
|
|
},
|
|
|
|
|
|
|
|
.aspect_ratio_idc = sps->vui.aspect_ratio_idc,
|
|
|
|
.sar_width = sps->vui.sar_width,
|
|
|
|
.sar_height = sps->vui.sar_height,
|
|
|
|
.num_units_in_tick = sps->vui.num_units_in_tick,
|
|
|
|
.time_scale = sps->vui.time_scale,
|
|
|
|
};
|
2016-03-24 01:49:35 +02:00
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
*vpic = (VAEncPictureParameterBufferH264) {
|
|
|
|
.CurrPic = {
|
|
|
|
.picture_id = VA_INVALID_ID,
|
|
|
|
.flags = VA_PICTURE_H264_INVALID,
|
|
|
|
},
|
|
|
|
|
|
|
|
.coded_buf = VA_INVALID_ID,
|
|
|
|
|
|
|
|
.pic_parameter_set_id = pps->pic_parameter_set_id,
|
|
|
|
.seq_parameter_set_id = pps->seq_parameter_set_id,
|
|
|
|
|
|
|
|
.pic_init_qp = pps->pic_init_qp_minus26 + 26,
|
|
|
|
.num_ref_idx_l0_active_minus1 = pps->num_ref_idx_l0_default_active_minus1,
|
|
|
|
.num_ref_idx_l1_active_minus1 = pps->num_ref_idx_l1_default_active_minus1,
|
|
|
|
|
|
|
|
.chroma_qp_index_offset = pps->chroma_qp_index_offset,
|
|
|
|
.second_chroma_qp_index_offset = pps->second_chroma_qp_index_offset,
|
|
|
|
|
|
|
|
.pic_fields.bits = {
|
|
|
|
.entropy_coding_mode_flag = pps->entropy_coding_mode_flag,
|
|
|
|
.weighted_pred_flag = pps->weighted_pred_flag,
|
|
|
|
.weighted_bipred_idc = pps->weighted_bipred_idc,
|
|
|
|
.constrained_intra_pred_flag = pps->constrained_intra_pred_flag,
|
|
|
|
.transform_8x8_mode_flag = pps->transform_8x8_mode_flag,
|
|
|
|
.deblocking_filter_control_present_flag =
|
|
|
|
pps->deblocking_filter_control_present_flag,
|
|
|
|
.redundant_pic_cnt_present_flag = pps->redundant_pic_cnt_present_flag,
|
|
|
|
.pic_order_present_flag =
|
|
|
|
pps->bottom_field_pic_order_in_frame_present_flag,
|
|
|
|
.pic_scaling_matrix_present_flag = pps->pic_scaling_matrix_present_flag,
|
|
|
|
},
|
|
|
|
};
|
2016-03-24 01:49:35 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,
|
|
|
|
VAAPIEncodePicture *pic)
|
|
|
|
{
|
2017-05-07 16:01:42 +02:00
|
|
|
VAAPIEncodeContext *ctx = avctx->priv_data;
|
2018-08-23 01:44:34 +02:00
|
|
|
VAAPIEncodeH264Context *priv = avctx->priv_data;
|
2018-12-20 22:39:58 +02:00
|
|
|
VAAPIEncodeH264Picture *hpic = pic->priv_data;
|
|
|
|
VAAPIEncodePicture *prev = pic->prev;
|
|
|
|
VAAPIEncodeH264Picture *hprev = prev ? prev->priv_data : NULL;
|
2017-05-07 16:01:42 +02:00
|
|
|
VAEncPictureParameterBufferH264 *vpic = pic->codec_picture_params;
|
2016-03-24 01:49:35 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (pic->type == PICTURE_TYPE_IDR) {
|
|
|
|
av_assert0(pic->display_order == pic->encode_order);
|
2018-12-20 22:39:58 +02:00
|
|
|
|
|
|
|
hpic->frame_num = 0;
|
|
|
|
hpic->last_idr_frame = pic->display_order;
|
|
|
|
hpic->idr_pic_id = hprev ? hprev->idr_pic_id + 1 : 0;
|
|
|
|
|
|
|
|
hpic->primary_pic_type = 0;
|
|
|
|
hpic->slice_type = 7;
|
2016-03-24 01:49:35 +02:00
|
|
|
} else {
|
2018-12-20 22:39:58 +02:00
|
|
|
av_assert0(prev);
|
2017-05-07 16:01:42 +02:00
|
|
|
|
2018-12-20 22:39:58 +02:00
|
|
|
hpic->frame_num = hprev->frame_num + prev->is_reference;
|
|
|
|
|
|
|
|
hpic->last_idr_frame = hprev->last_idr_frame;
|
|
|
|
hpic->idr_pic_id = hprev->idr_pic_id;
|
2017-05-07 16:01:42 +02:00
|
|
|
|
|
|
|
if (pic->type == PICTURE_TYPE_I) {
|
2018-12-20 22:39:58 +02:00
|
|
|
hpic->slice_type = 7;
|
|
|
|
hpic->primary_pic_type = 0;
|
2017-05-07 16:01:42 +02:00
|
|
|
} else if (pic->type == PICTURE_TYPE_P) {
|
2018-12-20 22:39:58 +02:00
|
|
|
hpic->slice_type = 5;
|
|
|
|
hpic->primary_pic_type = 1;
|
2017-05-07 16:01:42 +02:00
|
|
|
} else {
|
2018-12-20 22:39:58 +02:00
|
|
|
hpic->slice_type = 6;
|
|
|
|
hpic->primary_pic_type = 2;
|
2017-05-07 16:01:42 +02:00
|
|
|
}
|
2016-03-24 01:49:35 +02:00
|
|
|
}
|
2018-12-20 22:39:58 +02:00
|
|
|
hpic->pic_order_cnt = pic->display_order - hpic->last_idr_frame;
|
2023-01-17 13:17:58 +02:00
|
|
|
if (priv->raw_sps.pic_order_cnt_type == 2) {
|
|
|
|
hpic->pic_order_cnt *= 2;
|
|
|
|
}
|
|
|
|
|
2018-12-20 22:39:58 +02:00
|
|
|
hpic->dpb_delay = pic->display_order - pic->encode_order + ctx->max_b_depth;
|
|
|
|
hpic->cpb_delay = pic->encode_order - hpic->last_idr_frame;
|
2016-03-24 01:49:35 +02:00
|
|
|
|
2018-08-23 01:44:34 +02:00
|
|
|
if (priv->aud) {
|
2017-05-07 23:58:56 +02:00
|
|
|
priv->aud_needed = 1;
|
2018-08-23 01:44:34 +02:00
|
|
|
priv->raw_aud = (H264RawAUD) {
|
|
|
|
.nal_unit_header = {
|
|
|
|
.nal_unit_type = H264_NAL_AUD,
|
|
|
|
},
|
2018-12-20 22:39:58 +02:00
|
|
|
.primary_pic_type = hpic->primary_pic_type,
|
2018-08-23 01:44:34 +02:00
|
|
|
};
|
2017-05-07 23:58:56 +02:00
|
|
|
} else {
|
|
|
|
priv->aud_needed = 0;
|
|
|
|
}
|
|
|
|
|
2018-05-03 07:51:48 +02:00
|
|
|
priv->sei_needed = 0;
|
|
|
|
|
2018-08-23 01:44:34 +02:00
|
|
|
if (priv->sei & SEI_IDENTIFIER && pic->encode_order == 0)
|
2018-05-03 07:51:48 +02:00
|
|
|
priv->sei_needed |= SEI_IDENTIFIER;
|
2017-11-16 01:43:56 +02:00
|
|
|
#if !CONFIG_VAAPI_1
|
2017-10-25 01:15:55 +02:00
|
|
|
if (ctx->va_rc_mode == VA_RC_CBR)
|
|
|
|
priv->sei_cbr_workaround_needed = 1;
|
|
|
|
#endif
|
2017-05-07 16:01:42 +02:00
|
|
|
|
2018-08-23 01:44:34 +02:00
|
|
|
if (priv->sei & SEI_TIMING) {
|
|
|
|
priv->sei_pic_timing = (H264RawSEIPicTiming) {
|
2018-12-20 22:39:58 +02:00
|
|
|
.cpb_removal_delay = 2 * hpic->cpb_delay,
|
|
|
|
.dpb_output_delay = 2 * hpic->dpb_delay,
|
2018-08-23 01:44:34 +02:00
|
|
|
};
|
2017-05-07 16:01:42 +02:00
|
|
|
|
2018-05-03 07:51:48 +02:00
|
|
|
priv->sei_needed |= SEI_TIMING;
|
2017-05-07 16:01:42 +02:00
|
|
|
}
|
2016-03-24 01:49:35 +02:00
|
|
|
|
2018-08-23 01:44:34 +02:00
|
|
|
if (priv->sei & SEI_RECOVERY_POINT && pic->type == PICTURE_TYPE_I) {
|
|
|
|
priv->sei_recovery_point = (H264RawSEIRecoveryPoint) {
|
|
|
|
.recovery_frame_cnt = 0,
|
|
|
|
.exact_match_flag = 1,
|
|
|
|
.broken_link_flag = ctx->b_per_p > 0,
|
|
|
|
};
|
2017-05-08 00:02:09 +02:00
|
|
|
|
2018-05-03 07:51:48 +02:00
|
|
|
priv->sei_needed |= SEI_RECOVERY_POINT;
|
2017-05-08 00:02:09 +02:00
|
|
|
}
|
|
|
|
|
2023-01-09 20:40:24 +02:00
|
|
|
if (priv->sei & SEI_A53_CC) {
|
|
|
|
int err;
|
|
|
|
size_t sei_a53cc_len;
|
|
|
|
av_freep(&priv->sei_a53cc_data);
|
|
|
|
err = ff_alloc_a53_sei(pic->input_image, 0, &priv->sei_a53cc_data, &sei_a53cc_len);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
if (priv->sei_a53cc_data != NULL) {
|
|
|
|
priv->sei_a53cc.itu_t_t35_country_code = 181;
|
|
|
|
priv->sei_a53cc.data = (uint8_t *)priv->sei_a53cc_data + 1;
|
|
|
|
priv->sei_a53cc.data_length = sei_a53cc_len - 1;
|
|
|
|
|
|
|
|
priv->sei_needed |= SEI_A53_CC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
vpic->CurrPic = (VAPictureH264) {
|
|
|
|
.picture_id = pic->recon_surface,
|
2018-12-20 22:39:58 +02:00
|
|
|
.frame_idx = hpic->frame_num,
|
2017-05-07 16:01:42 +02:00
|
|
|
.flags = 0,
|
2018-12-20 22:39:58 +02:00
|
|
|
.TopFieldOrderCnt = hpic->pic_order_cnt,
|
|
|
|
.BottomFieldOrderCnt = hpic->pic_order_cnt,
|
2017-05-07 16:01:42 +02:00
|
|
|
};
|
2016-03-24 01:49:35 +02:00
|
|
|
|
|
|
|
for (i = 0; i < pic->nb_refs; i++) {
|
2018-12-20 22:39:58 +02:00
|
|
|
VAAPIEncodePicture *ref = pic->refs[i];
|
|
|
|
VAAPIEncodeH264Picture *href;
|
2017-05-07 16:01:42 +02:00
|
|
|
|
2016-05-16 15:01:31 +02:00
|
|
|
av_assert0(ref && ref->encode_order < pic->encode_order);
|
2018-12-20 22:39:58 +02:00
|
|
|
href = ref->priv_data;
|
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
vpic->ReferenceFrames[i] = (VAPictureH264) {
|
|
|
|
.picture_id = ref->recon_surface,
|
2018-12-20 22:39:58 +02:00
|
|
|
.frame_idx = href->frame_num,
|
2017-05-07 16:01:42 +02:00
|
|
|
.flags = VA_PICTURE_H264_SHORT_TERM_REFERENCE,
|
2018-12-20 22:39:58 +02:00
|
|
|
.TopFieldOrderCnt = href->pic_order_cnt,
|
|
|
|
.BottomFieldOrderCnt = href->pic_order_cnt,
|
2017-05-07 16:01:42 +02:00
|
|
|
};
|
2016-03-24 01:49:35 +02:00
|
|
|
}
|
|
|
|
for (; i < FF_ARRAY_ELEMS(vpic->ReferenceFrames); i++) {
|
2017-05-07 16:01:42 +02:00
|
|
|
vpic->ReferenceFrames[i] = (VAPictureH264) {
|
|
|
|
.picture_id = VA_INVALID_ID,
|
|
|
|
.flags = VA_PICTURE_H264_INVALID,
|
|
|
|
};
|
2016-03-24 01:49:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
vpic->coded_buf = pic->output_buffer;
|
|
|
|
|
2018-12-20 22:39:58 +02:00
|
|
|
vpic->frame_num = hpic->frame_num;
|
2017-05-07 16:01:42 +02:00
|
|
|
|
|
|
|
vpic->pic_fields.bits.idr_pic_flag = (pic->type == PICTURE_TYPE_IDR);
|
2016-03-24 01:49:35 +02:00
|
|
|
vpic->pic_fields.bits.reference_pic_flag = (pic->type != PICTURE_TYPE_B);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-20 22:39:58 +02:00
|
|
|
static void vaapi_encode_h264_default_ref_pic_list(AVCodecContext *avctx,
|
|
|
|
VAAPIEncodePicture *pic,
|
|
|
|
VAAPIEncodePicture **rpl0,
|
|
|
|
VAAPIEncodePicture **rpl1,
|
|
|
|
int *rpl_size)
|
|
|
|
{
|
|
|
|
VAAPIEncodePicture *prev;
|
|
|
|
VAAPIEncodeH264Picture *hp, *hn, *hc;
|
|
|
|
int i, j, n = 0;
|
|
|
|
|
|
|
|
prev = pic->prev;
|
|
|
|
av_assert0(prev);
|
|
|
|
hp = pic->priv_data;
|
|
|
|
|
|
|
|
for (i = 0; i < pic->prev->nb_dpb_pics; i++) {
|
|
|
|
hn = prev->dpb[i]->priv_data;
|
|
|
|
av_assert0(hn->frame_num < hp->frame_num);
|
|
|
|
|
|
|
|
if (pic->type == PICTURE_TYPE_P) {
|
|
|
|
for (j = n; j > 0; j--) {
|
|
|
|
hc = rpl0[j - 1]->priv_data;
|
|
|
|
av_assert0(hc->frame_num != hn->frame_num);
|
|
|
|
if (hc->frame_num > hn->frame_num)
|
|
|
|
break;
|
|
|
|
rpl0[j] = rpl0[j - 1];
|
|
|
|
}
|
|
|
|
rpl0[j] = prev->dpb[i];
|
|
|
|
|
|
|
|
} else if (pic->type == PICTURE_TYPE_B) {
|
|
|
|
for (j = n; j > 0; j--) {
|
|
|
|
hc = rpl0[j - 1]->priv_data;
|
|
|
|
av_assert0(hc->pic_order_cnt != hp->pic_order_cnt);
|
|
|
|
if (hc->pic_order_cnt < hp->pic_order_cnt) {
|
|
|
|
if (hn->pic_order_cnt > hp->pic_order_cnt ||
|
|
|
|
hn->pic_order_cnt < hc->pic_order_cnt)
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
if (hn->pic_order_cnt > hc->pic_order_cnt)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rpl0[j] = rpl0[j - 1];
|
|
|
|
}
|
|
|
|
rpl0[j] = prev->dpb[i];
|
|
|
|
|
|
|
|
for (j = n; j > 0; j--) {
|
|
|
|
hc = rpl1[j - 1]->priv_data;
|
|
|
|
av_assert0(hc->pic_order_cnt != hp->pic_order_cnt);
|
|
|
|
if (hc->pic_order_cnt > hp->pic_order_cnt) {
|
|
|
|
if (hn->pic_order_cnt < hp->pic_order_cnt ||
|
|
|
|
hn->pic_order_cnt > hc->pic_order_cnt)
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
if (hn->pic_order_cnt < hc->pic_order_cnt)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rpl1[j] = rpl1[j - 1];
|
|
|
|
}
|
|
|
|
rpl1[j] = prev->dpb[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
++n;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pic->type == PICTURE_TYPE_B) {
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
if (rpl0[i] != rpl1[i])
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i == n)
|
|
|
|
FFSWAP(VAAPIEncodePicture*, rpl1[0], rpl1[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pic->type == PICTURE_TYPE_P ||
|
|
|
|
pic->type == PICTURE_TYPE_B) {
|
|
|
|
av_log(avctx, AV_LOG_DEBUG, "Default RefPicList0 for fn=%d/poc=%d:",
|
|
|
|
hp->frame_num, hp->pic_order_cnt);
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
hn = rpl0[i]->priv_data;
|
|
|
|
av_log(avctx, AV_LOG_DEBUG, " fn=%d/poc=%d",
|
|
|
|
hn->frame_num, hn->pic_order_cnt);
|
|
|
|
}
|
|
|
|
av_log(avctx, AV_LOG_DEBUG, "\n");
|
|
|
|
}
|
|
|
|
if (pic->type == PICTURE_TYPE_B) {
|
|
|
|
av_log(avctx, AV_LOG_DEBUG, "Default RefPicList1 for fn=%d/poc=%d:",
|
|
|
|
hp->frame_num, hp->pic_order_cnt);
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
hn = rpl1[i]->priv_data;
|
|
|
|
av_log(avctx, AV_LOG_DEBUG, " fn=%d/poc=%d",
|
|
|
|
hn->frame_num, hn->pic_order_cnt);
|
|
|
|
}
|
|
|
|
av_log(avctx, AV_LOG_DEBUG, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
*rpl_size = n;
|
|
|
|
}
|
|
|
|
|
2016-03-24 01:49:35 +02:00
|
|
|
static int vaapi_encode_h264_init_slice_params(AVCodecContext *avctx,
|
|
|
|
VAAPIEncodePicture *pic,
|
|
|
|
VAAPIEncodeSlice *slice)
|
|
|
|
{
|
2018-08-23 01:44:34 +02:00
|
|
|
VAAPIEncodeH264Context *priv = avctx->priv_data;
|
2018-12-20 22:39:58 +02:00
|
|
|
VAAPIEncodeH264Picture *hpic = pic->priv_data;
|
|
|
|
VAAPIEncodePicture *prev = pic->prev;
|
2018-08-23 01:44:34 +02:00
|
|
|
H264RawSPS *sps = &priv->raw_sps;
|
|
|
|
H264RawPPS *pps = &priv->raw_pps;
|
|
|
|
H264RawSliceHeader *sh = &priv->raw_slice.header;
|
2017-05-07 16:01:42 +02:00
|
|
|
VAEncPictureParameterBufferH264 *vpic = pic->codec_picture_params;
|
|
|
|
VAEncSliceParameterBufferH264 *vslice = slice->codec_slice_params;
|
2018-12-20 22:39:58 +02:00
|
|
|
int i, j;
|
2016-03-24 01:49:35 +02:00
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
if (pic->type == PICTURE_TYPE_IDR) {
|
|
|
|
sh->nal_unit_header.nal_unit_type = H264_NAL_IDR_SLICE;
|
|
|
|
sh->nal_unit_header.nal_ref_idc = 3;
|
|
|
|
} else {
|
|
|
|
sh->nal_unit_header.nal_unit_type = H264_NAL_SLICE;
|
2018-12-20 22:39:58 +02:00
|
|
|
sh->nal_unit_header.nal_ref_idc = pic->is_reference;
|
2017-05-07 16:01:42 +02:00
|
|
|
}
|
|
|
|
|
2018-09-23 23:52:58 +02:00
|
|
|
sh->first_mb_in_slice = slice->block_start;
|
2018-12-20 22:39:58 +02:00
|
|
|
sh->slice_type = hpic->slice_type;
|
2017-05-07 16:01:42 +02:00
|
|
|
|
|
|
|
sh->pic_parameter_set_id = pps->pic_parameter_set_id;
|
2016-03-24 01:49:35 +02:00
|
|
|
|
2018-12-20 22:39:58 +02:00
|
|
|
sh->frame_num = hpic->frame_num &
|
|
|
|
((1 << (4 + sps->log2_max_frame_num_minus4)) - 1);
|
|
|
|
sh->idr_pic_id = hpic->idr_pic_id;
|
|
|
|
sh->pic_order_cnt_lsb = hpic->pic_order_cnt &
|
2017-05-07 16:01:42 +02:00
|
|
|
((1 << (4 + sps->log2_max_pic_order_cnt_lsb_minus4)) - 1);
|
|
|
|
|
|
|
|
sh->direct_spatial_mv_pred_flag = 1;
|
|
|
|
|
|
|
|
if (pic->type == PICTURE_TYPE_B)
|
|
|
|
sh->slice_qp_delta = priv->fixed_qp_b - (pps->pic_init_qp_minus26 + 26);
|
|
|
|
else if (pic->type == PICTURE_TYPE_P)
|
|
|
|
sh->slice_qp_delta = priv->fixed_qp_p - (pps->pic_init_qp_minus26 + 26);
|
2016-03-24 01:49:35 +02:00
|
|
|
else
|
2017-05-07 16:01:42 +02:00
|
|
|
sh->slice_qp_delta = priv->fixed_qp_idr - (pps->pic_init_qp_minus26 + 26);
|
2016-03-24 01:49:35 +02:00
|
|
|
|
2018-12-20 22:39:58 +02:00
|
|
|
if (pic->is_reference && pic->type != PICTURE_TYPE_IDR) {
|
|
|
|
VAAPIEncodePicture *discard_list[MAX_DPB_SIZE];
|
|
|
|
int discard = 0, keep = 0;
|
|
|
|
|
|
|
|
// Discard everything which is in the DPB of the previous frame but
|
|
|
|
// not in the DPB of this one.
|
|
|
|
for (i = 0; i < prev->nb_dpb_pics; i++) {
|
|
|
|
for (j = 0; j < pic->nb_dpb_pics; j++) {
|
|
|
|
if (prev->dpb[i] == pic->dpb[j])
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (j == pic->nb_dpb_pics) {
|
|
|
|
discard_list[discard] = prev->dpb[i];
|
|
|
|
++discard;
|
|
|
|
} else {
|
|
|
|
++keep;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
av_assert0(keep <= priv->dpb_frames);
|
|
|
|
|
|
|
|
if (discard == 0) {
|
|
|
|
sh->adaptive_ref_pic_marking_mode_flag = 0;
|
|
|
|
} else {
|
|
|
|
sh->adaptive_ref_pic_marking_mode_flag = 1;
|
|
|
|
for (i = 0; i < discard; i++) {
|
|
|
|
VAAPIEncodeH264Picture *old = discard_list[i]->priv_data;
|
|
|
|
av_assert0(old->frame_num < hpic->frame_num);
|
|
|
|
sh->mmco[i].memory_management_control_operation = 1;
|
|
|
|
sh->mmco[i].difference_of_pic_nums_minus1 =
|
|
|
|
hpic->frame_num - old->frame_num - 1;
|
|
|
|
}
|
|
|
|
sh->mmco[i].memory_management_control_operation = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the intended references are not the first entries of RefPicListN
|
|
|
|
// by default, use ref-pic-list-modification to move them there.
|
|
|
|
if (pic->type == PICTURE_TYPE_P || pic->type == PICTURE_TYPE_B) {
|
|
|
|
VAAPIEncodePicture *def_l0[MAX_DPB_SIZE], *def_l1[MAX_DPB_SIZE];
|
|
|
|
VAAPIEncodeH264Picture *href;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
vaapi_encode_h264_default_ref_pic_list(avctx, pic,
|
|
|
|
def_l0, def_l1, &n);
|
|
|
|
|
|
|
|
if (pic->type == PICTURE_TYPE_P) {
|
|
|
|
int need_rplm = 0;
|
|
|
|
for (i = 0; i < pic->nb_refs; i++) {
|
|
|
|
av_assert0(pic->refs[i]);
|
|
|
|
if (pic->refs[i] != def_l0[i])
|
|
|
|
need_rplm = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
sh->ref_pic_list_modification_flag_l0 = need_rplm;
|
|
|
|
if (need_rplm) {
|
|
|
|
int pic_num = hpic->frame_num;
|
|
|
|
for (i = 0; i < pic->nb_refs; i++) {
|
|
|
|
href = pic->refs[i]->priv_data;
|
|
|
|
av_assert0(href->frame_num != pic_num);
|
|
|
|
if (href->frame_num < pic_num) {
|
|
|
|
sh->rplm_l0[i].modification_of_pic_nums_idc = 0;
|
|
|
|
sh->rplm_l0[i].abs_diff_pic_num_minus1 =
|
|
|
|
pic_num - href->frame_num - 1;
|
|
|
|
} else {
|
|
|
|
sh->rplm_l0[i].modification_of_pic_nums_idc = 1;
|
|
|
|
sh->rplm_l0[i].abs_diff_pic_num_minus1 =
|
|
|
|
href->frame_num - pic_num - 1;
|
|
|
|
}
|
|
|
|
pic_num = href->frame_num;
|
|
|
|
}
|
|
|
|
sh->rplm_l0[i].modification_of_pic_nums_idc = 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
int need_rplm_l0 = 0, need_rplm_l1 = 0;
|
|
|
|
int n0 = 0, n1 = 0;
|
|
|
|
for (i = 0; i < pic->nb_refs; i++) {
|
|
|
|
av_assert0(pic->refs[i]);
|
|
|
|
href = pic->refs[i]->priv_data;
|
|
|
|
av_assert0(href->pic_order_cnt != hpic->pic_order_cnt);
|
|
|
|
if (href->pic_order_cnt < hpic->pic_order_cnt) {
|
|
|
|
if (pic->refs[i] != def_l0[n0])
|
|
|
|
need_rplm_l0 = 1;
|
|
|
|
++n0;
|
|
|
|
} else {
|
|
|
|
if (pic->refs[i] != def_l1[n1])
|
|
|
|
need_rplm_l1 = 1;
|
|
|
|
++n1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sh->ref_pic_list_modification_flag_l0 = need_rplm_l0;
|
|
|
|
if (need_rplm_l0) {
|
|
|
|
int pic_num = hpic->frame_num;
|
|
|
|
for (i = j = 0; i < pic->nb_refs; i++) {
|
|
|
|
href = pic->refs[i]->priv_data;
|
|
|
|
if (href->pic_order_cnt > hpic->pic_order_cnt)
|
|
|
|
continue;
|
|
|
|
av_assert0(href->frame_num != pic_num);
|
|
|
|
if (href->frame_num < pic_num) {
|
|
|
|
sh->rplm_l0[j].modification_of_pic_nums_idc = 0;
|
|
|
|
sh->rplm_l0[j].abs_diff_pic_num_minus1 =
|
|
|
|
pic_num - href->frame_num - 1;
|
|
|
|
} else {
|
|
|
|
sh->rplm_l0[j].modification_of_pic_nums_idc = 1;
|
|
|
|
sh->rplm_l0[j].abs_diff_pic_num_minus1 =
|
|
|
|
href->frame_num - pic_num - 1;
|
|
|
|
}
|
|
|
|
pic_num = href->frame_num;
|
|
|
|
++j;
|
|
|
|
}
|
|
|
|
av_assert0(j == n0);
|
|
|
|
sh->rplm_l0[j].modification_of_pic_nums_idc = 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
sh->ref_pic_list_modification_flag_l1 = need_rplm_l1;
|
|
|
|
if (need_rplm_l1) {
|
|
|
|
int pic_num = hpic->frame_num;
|
|
|
|
for (i = j = 0; i < pic->nb_refs; i++) {
|
|
|
|
href = pic->refs[i]->priv_data;
|
|
|
|
if (href->pic_order_cnt < hpic->pic_order_cnt)
|
|
|
|
continue;
|
|
|
|
av_assert0(href->frame_num != pic_num);
|
|
|
|
if (href->frame_num < pic_num) {
|
|
|
|
sh->rplm_l1[j].modification_of_pic_nums_idc = 0;
|
|
|
|
sh->rplm_l1[j].abs_diff_pic_num_minus1 =
|
|
|
|
pic_num - href->frame_num - 1;
|
|
|
|
} else {
|
|
|
|
sh->rplm_l1[j].modification_of_pic_nums_idc = 1;
|
|
|
|
sh->rplm_l1[j].abs_diff_pic_num_minus1 =
|
|
|
|
href->frame_num - pic_num - 1;
|
|
|
|
}
|
|
|
|
pic_num = href->frame_num;
|
|
|
|
++j;
|
|
|
|
}
|
|
|
|
av_assert0(j == n1);
|
|
|
|
sh->rplm_l1[j].modification_of_pic_nums_idc = 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-24 01:49:35 +02:00
|
|
|
|
2018-09-23 23:52:58 +02:00
|
|
|
vslice->macroblock_address = slice->block_start;
|
|
|
|
vslice->num_macroblocks = slice->block_size;
|
2016-03-24 01:49:35 +02:00
|
|
|
|
|
|
|
vslice->macroblock_info = VA_INVALID_ID;
|
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
vslice->slice_type = sh->slice_type % 5;
|
|
|
|
vslice->pic_parameter_set_id = sh->pic_parameter_set_id;
|
|
|
|
vslice->idr_pic_id = sh->idr_pic_id;
|
|
|
|
|
|
|
|
vslice->pic_order_cnt_lsb = sh->pic_order_cnt_lsb;
|
2016-03-24 01:49:35 +02:00
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
vslice->direct_spatial_mv_pred_flag = sh->direct_spatial_mv_pred_flag;
|
2016-03-24 01:49:35 +02:00
|
|
|
|
|
|
|
for (i = 0; i < FF_ARRAY_ELEMS(vslice->RefPicList0); i++) {
|
|
|
|
vslice->RefPicList0[i].picture_id = VA_INVALID_ID;
|
|
|
|
vslice->RefPicList0[i].flags = VA_PICTURE_H264_INVALID;
|
|
|
|
vslice->RefPicList1[i].picture_id = VA_INVALID_ID;
|
|
|
|
vslice->RefPicList1[i].flags = VA_PICTURE_H264_INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
av_assert0(pic->nb_refs <= 2);
|
|
|
|
if (pic->nb_refs >= 1) {
|
2016-04-27 19:45:23 +02:00
|
|
|
// Backward reference for P- or B-frame.
|
2016-03-24 01:49:35 +02:00
|
|
|
av_assert0(pic->type == PICTURE_TYPE_P ||
|
|
|
|
pic->type == PICTURE_TYPE_B);
|
|
|
|
vslice->RefPicList0[0] = vpic->ReferenceFrames[0];
|
|
|
|
}
|
|
|
|
if (pic->nb_refs >= 2) {
|
2016-04-27 19:45:23 +02:00
|
|
|
// Forward reference for B-frame.
|
2016-03-24 01:49:35 +02:00
|
|
|
av_assert0(pic->type == PICTURE_TYPE_B);
|
|
|
|
vslice->RefPicList1[0] = vpic->ReferenceFrames[1];
|
|
|
|
}
|
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
vslice->slice_qp_delta = sh->slice_qp_delta;
|
2016-03-24 01:49:35 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-09-18 15:55:26 +02:00
|
|
|
static av_cold int vaapi_encode_h264_configure(AVCodecContext *avctx)
|
2016-04-13 00:14:23 +02:00
|
|
|
{
|
|
|
|
VAAPIEncodeContext *ctx = avctx->priv_data;
|
2018-08-23 01:44:34 +02:00
|
|
|
VAAPIEncodeH264Context *priv = avctx->priv_data;
|
2017-05-07 16:01:42 +02:00
|
|
|
int err;
|
|
|
|
|
|
|
|
err = ff_cbs_init(&priv->cbc, AV_CODEC_ID_H264, avctx);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
2016-04-13 00:14:23 +02:00
|
|
|
|
2016-09-18 15:55:26 +02:00
|
|
|
priv->mb_width = FFALIGN(avctx->width, 16) / 16;
|
|
|
|
priv->mb_height = FFALIGN(avctx->height, 16) / 16;
|
|
|
|
|
|
|
|
if (ctx->va_rc_mode == VA_RC_CQP) {
|
2019-02-10 21:46:55 +02:00
|
|
|
priv->fixed_qp_p = av_clip(ctx->rc_quality, 1, 51);
|
2016-09-18 15:55:26 +02:00
|
|
|
if (avctx->i_quant_factor > 0.0)
|
2019-02-10 21:46:55 +02:00
|
|
|
priv->fixed_qp_idr =
|
|
|
|
av_clip((avctx->i_quant_factor * priv->fixed_qp_p +
|
|
|
|
avctx->i_quant_offset) + 0.5, 1, 51);
|
2016-09-18 15:55:26 +02:00
|
|
|
else
|
|
|
|
priv->fixed_qp_idr = priv->fixed_qp_p;
|
|
|
|
if (avctx->b_quant_factor > 0.0)
|
2019-02-10 21:46:55 +02:00
|
|
|
priv->fixed_qp_b =
|
|
|
|
av_clip((avctx->b_quant_factor * priv->fixed_qp_p +
|
|
|
|
avctx->b_quant_offset) + 0.5, 1, 51);
|
2016-09-18 15:55:26 +02:00
|
|
|
else
|
|
|
|
priv->fixed_qp_b = priv->fixed_qp_p;
|
|
|
|
|
|
|
|
av_log(avctx, AV_LOG_DEBUG, "Using fixed QP = "
|
|
|
|
"%d / %d / %d for IDR- / P- / B-frames.\n",
|
|
|
|
priv->fixed_qp_idr, priv->fixed_qp_p, priv->fixed_qp_b);
|
|
|
|
|
2019-02-10 21:46:55 +02:00
|
|
|
} else {
|
2016-09-18 15:55:26 +02:00
|
|
|
// These still need to be set for pic_init_qp/slice_qp_delta.
|
|
|
|
priv->fixed_qp_idr = 26;
|
|
|
|
priv->fixed_qp_p = 26;
|
|
|
|
priv->fixed_qp_b = 26;
|
2019-02-10 21:46:55 +02:00
|
|
|
}
|
2016-09-18 15:55:26 +02:00
|
|
|
|
2019-02-10 21:46:55 +02:00
|
|
|
if (!ctx->rc_mode->hrd) {
|
|
|
|
// Timing SEI requires a mode respecting HRD parameters.
|
|
|
|
priv->sei &= ~SEI_TIMING;
|
2016-09-18 15:55:26 +02:00
|
|
|
}
|
|
|
|
|
2018-08-23 01:44:34 +02:00
|
|
|
if (priv->sei & SEI_IDENTIFIER) {
|
2017-05-07 16:01:42 +02:00
|
|
|
const char *lavc = LIBAVCODEC_IDENT;
|
|
|
|
const char *vaapi = VA_VERSION_S;
|
|
|
|
const char *driver;
|
|
|
|
int len;
|
|
|
|
|
2018-08-23 01:44:34 +02:00
|
|
|
memcpy(priv->sei_identifier.uuid_iso_iec_11578,
|
2017-05-07 16:01:42 +02:00
|
|
|
vaapi_encode_h264_sei_identifier_uuid,
|
2018-08-23 01:44:34 +02:00
|
|
|
sizeof(priv->sei_identifier.uuid_iso_iec_11578));
|
2017-05-07 16:01:42 +02:00
|
|
|
|
|
|
|
driver = vaQueryVendorString(ctx->hwctx->display);
|
|
|
|
if (!driver)
|
|
|
|
driver = "unknown driver";
|
|
|
|
|
|
|
|
len = snprintf(NULL, 0, "%s / VAAPI %s / %s", lavc, vaapi, driver);
|
|
|
|
if (len >= 0) {
|
2018-08-23 01:44:34 +02:00
|
|
|
priv->sei_identifier_string = av_malloc(len + 1);
|
|
|
|
if (!priv->sei_identifier_string)
|
2017-05-07 16:01:42 +02:00
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
2018-08-23 01:44:34 +02:00
|
|
|
snprintf(priv->sei_identifier_string, len + 1,
|
2017-05-07 16:01:42 +02:00
|
|
|
"%s / VAAPI %s / %s", lavc, vaapi, driver);
|
|
|
|
|
2018-08-23 01:44:34 +02:00
|
|
|
priv->sei_identifier.data = priv->sei_identifier_string;
|
|
|
|
priv->sei_identifier.data_length = len + 1;
|
2017-05-07 16:01:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-07 21:26:49 +02:00
|
|
|
ctx->roi_quant_range = 51 + 6 * (ctx->profile->depth - 8);
|
|
|
|
|
2016-04-13 00:14:23 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-19 00:30:40 +02:00
|
|
|
static const VAAPIEncodeProfile vaapi_encode_h264_profiles[] = {
|
|
|
|
{ FF_PROFILE_H264_HIGH, 8, 3, 1, 1, VAProfileH264High },
|
|
|
|
{ FF_PROFILE_H264_MAIN, 8, 3, 1, 1, VAProfileH264Main },
|
|
|
|
{ FF_PROFILE_H264_CONSTRAINED_BASELINE,
|
|
|
|
8, 3, 1, 1, VAProfileH264ConstrainedBaseline },
|
|
|
|
{ FF_PROFILE_UNKNOWN }
|
|
|
|
};
|
|
|
|
|
2016-09-18 15:55:26 +02:00
|
|
|
static const VAAPIEncodeType vaapi_encode_type_h264 = {
|
2018-09-19 00:30:40 +02:00
|
|
|
.profiles = vaapi_encode_h264_profiles,
|
|
|
|
|
2018-12-20 22:39:56 +02:00
|
|
|
.flags = FLAG_SLICE_CONTROL |
|
|
|
|
FLAG_B_PICTURES |
|
2018-12-20 22:39:58 +02:00
|
|
|
FLAG_B_PICTURE_REFERENCES |
|
2018-12-20 22:39:56 +02:00
|
|
|
FLAG_NON_IDR_KEY_PICTURES,
|
2018-09-23 23:52:58 +02:00
|
|
|
|
2019-02-10 21:46:55 +02:00
|
|
|
.default_quality = 20,
|
|
|
|
|
2016-09-18 15:55:26 +02:00
|
|
|
.configure = &vaapi_encode_h264_configure,
|
2016-04-13 00:14:23 +02:00
|
|
|
|
2018-12-20 22:39:58 +02:00
|
|
|
.picture_priv_data_size = sizeof(VAAPIEncodeH264Picture),
|
|
|
|
|
2016-09-18 15:55:26 +02:00
|
|
|
.sequence_params_size = sizeof(VAEncSequenceParameterBufferH264),
|
|
|
|
.init_sequence_params = &vaapi_encode_h264_init_sequence_params,
|
|
|
|
|
|
|
|
.picture_params_size = sizeof(VAEncPictureParameterBufferH264),
|
|
|
|
.init_picture_params = &vaapi_encode_h264_init_picture_params,
|
2016-03-24 01:49:35 +02:00
|
|
|
|
2016-09-18 15:55:26 +02:00
|
|
|
.slice_params_size = sizeof(VAEncSliceParameterBufferH264),
|
|
|
|
.init_slice_params = &vaapi_encode_h264_init_slice_params,
|
|
|
|
|
|
|
|
.sequence_header_type = VAEncPackedHeaderSequence,
|
|
|
|
.write_sequence_header = &vaapi_encode_h264_write_sequence_header,
|
|
|
|
|
|
|
|
.slice_header_type = VAEncPackedHeaderH264_Slice,
|
|
|
|
.write_slice_header = &vaapi_encode_h264_write_slice_header,
|
|
|
|
|
|
|
|
.write_extra_header = &vaapi_encode_h264_write_extra_header,
|
|
|
|
};
|
|
|
|
|
|
|
|
static av_cold int vaapi_encode_h264_init(AVCodecContext *avctx)
|
2016-03-24 01:49:35 +02:00
|
|
|
{
|
2018-08-23 01:44:34 +02:00
|
|
|
VAAPIEncodeContext *ctx = avctx->priv_data;
|
|
|
|
VAAPIEncodeH264Context *priv = avctx->priv_data;
|
2016-04-13 00:13:31 +02:00
|
|
|
|
2016-09-18 15:55:26 +02:00
|
|
|
ctx->codec = &vaapi_encode_type_h264;
|
2016-03-24 01:49:35 +02:00
|
|
|
|
2017-11-29 23:31:11 +02:00
|
|
|
if (avctx->profile == FF_PROFILE_UNKNOWN)
|
2018-08-23 01:44:34 +02:00
|
|
|
avctx->profile = priv->profile;
|
2017-11-29 23:31:11 +02:00
|
|
|
if (avctx->level == FF_LEVEL_UNKNOWN)
|
2018-08-23 01:44:34 +02:00
|
|
|
avctx->level = priv->level;
|
2018-09-19 00:30:43 +02:00
|
|
|
if (avctx->compression_level == FF_COMPRESSION_DEFAULT)
|
|
|
|
avctx->compression_level = priv->quality;
|
2017-11-29 23:31:11 +02:00
|
|
|
|
2018-09-19 00:30:40 +02:00
|
|
|
// Reject unsupported profiles.
|
2016-03-24 01:49:35 +02:00
|
|
|
switch (avctx->profile) {
|
2017-10-08 15:48:24 +02:00
|
|
|
case FF_PROFILE_H264_BASELINE:
|
|
|
|
av_log(avctx, AV_LOG_WARNING, "H.264 baseline profile is not "
|
|
|
|
"supported, using constrained baseline profile instead.\n");
|
|
|
|
avctx->profile = FF_PROFILE_H264_CONSTRAINED_BASELINE;
|
2016-03-24 01:49:35 +02:00
|
|
|
break;
|
|
|
|
case FF_PROFILE_H264_EXTENDED:
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "H.264 extended profile "
|
|
|
|
"is not supported.\n");
|
|
|
|
return AVERROR_PATCHWELCOME;
|
|
|
|
case FF_PROFILE_H264_HIGH_10:
|
|
|
|
case FF_PROFILE_H264_HIGH_10_INTRA:
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "H.264 10-bit profiles "
|
|
|
|
"are not supported.\n");
|
|
|
|
return AVERROR_PATCHWELCOME;
|
|
|
|
case FF_PROFILE_H264_HIGH_422:
|
|
|
|
case FF_PROFILE_H264_HIGH_422_INTRA:
|
|
|
|
case FF_PROFILE_H264_HIGH_444:
|
|
|
|
case FF_PROFILE_H264_HIGH_444_PREDICTIVE:
|
|
|
|
case FF_PROFILE_H264_HIGH_444_INTRA:
|
|
|
|
case FF_PROFILE_H264_CAVLC_444:
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "H.264 non-4:2:0 profiles "
|
|
|
|
"are not supported.\n");
|
|
|
|
return AVERROR_PATCHWELCOME;
|
2016-05-18 00:08:57 +02:00
|
|
|
}
|
2016-03-24 01:49:35 +02:00
|
|
|
|
2018-09-19 00:30:58 +02:00
|
|
|
if (avctx->level != FF_LEVEL_UNKNOWN && avctx->level & ~0xff) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Invalid level %d: must fit "
|
|
|
|
"in 8-bit unsigned integer.\n", avctx->level);
|
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
|
|
|
|
2018-09-19 00:30:48 +02:00
|
|
|
ctx->desired_packed_headers =
|
2016-09-18 15:59:59 +02:00
|
|
|
VA_ENC_PACKED_HEADER_SEQUENCE | // SPS and PPS.
|
|
|
|
VA_ENC_PACKED_HEADER_SLICE | // Slice headers.
|
|
|
|
VA_ENC_PACKED_HEADER_MISC; // SEI.
|
2016-03-24 01:49:35 +02:00
|
|
|
|
2016-09-18 15:55:26 +02:00
|
|
|
ctx->surface_width = FFALIGN(avctx->width, 16);
|
|
|
|
ctx->surface_height = FFALIGN(avctx->height, 16);
|
2016-03-24 01:49:35 +02:00
|
|
|
|
2018-09-23 23:52:58 +02:00
|
|
|
ctx->slice_block_height = ctx->slice_block_width = 16;
|
|
|
|
|
2019-02-10 21:46:55 +02:00
|
|
|
if (priv->qp > 0)
|
|
|
|
ctx->explicit_qp = priv->qp;
|
|
|
|
|
2016-09-18 15:55:26 +02:00
|
|
|
return ff_vaapi_encode_init(avctx);
|
2016-03-24 01:49:35 +02:00
|
|
|
}
|
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
static av_cold int vaapi_encode_h264_close(AVCodecContext *avctx)
|
|
|
|
{
|
2018-08-23 01:44:34 +02:00
|
|
|
VAAPIEncodeH264Context *priv = avctx->priv_data;
|
2017-05-07 16:01:42 +02:00
|
|
|
|
2020-07-06 00:34:25 +02:00
|
|
|
ff_cbs_fragment_free(&priv->current_access_unit);
|
2018-08-23 01:44:34 +02:00
|
|
|
ff_cbs_close(&priv->cbc);
|
|
|
|
av_freep(&priv->sei_identifier_string);
|
2023-01-09 20:40:24 +02:00
|
|
|
av_freep(&priv->sei_a53cc_data);
|
2017-05-07 16:01:42 +02:00
|
|
|
|
|
|
|
return ff_vaapi_encode_close(avctx);
|
|
|
|
}
|
|
|
|
|
2018-08-23 01:44:34 +02:00
|
|
|
#define OFFSET(x) offsetof(VAAPIEncodeH264Context, x)
|
2016-04-13 00:15:40 +02:00
|
|
|
#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
|
|
|
|
static const AVOption vaapi_encode_h264_options[] = {
|
2018-09-19 00:30:41 +02:00
|
|
|
VAAPI_ENCODE_COMMON_OPTIONS,
|
2019-02-10 21:46:55 +02:00
|
|
|
VAAPI_ENCODE_RC_OPTIONS,
|
2018-09-19 00:30:41 +02:00
|
|
|
|
2016-04-27 19:45:23 +02:00
|
|
|
{ "qp", "Constant QP (for P-frames; scaled by qfactor/qoffset for I/B)",
|
2019-02-10 21:46:55 +02:00
|
|
|
OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 52, FLAGS },
|
2016-04-13 00:16:30 +02:00
|
|
|
{ "quality", "Set encode quality (trades off against speed, higher is faster)",
|
2018-09-19 00:30:43 +02:00
|
|
|
OFFSET(quality), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS },
|
2017-08-08 09:33:53 +02:00
|
|
|
{ "coder", "Entropy coder type",
|
|
|
|
OFFSET(coder), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, FLAGS, "coder" },
|
|
|
|
{ "cavlc", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, INT_MIN, INT_MAX, FLAGS, "coder" },
|
|
|
|
{ "cabac", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, INT_MIN, INT_MAX, FLAGS, "coder" },
|
|
|
|
{ "vlc", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, INT_MIN, INT_MAX, FLAGS, "coder" },
|
|
|
|
{ "ac", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, INT_MIN, INT_MAX, FLAGS, "coder" },
|
2017-05-07 16:01:42 +02:00
|
|
|
|
2017-05-07 23:58:56 +02:00
|
|
|
{ "aud", "Include AUD",
|
2018-09-19 00:30:50 +02:00
|
|
|
OFFSET(aud), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
|
2017-05-07 23:58:56 +02:00
|
|
|
|
2017-05-07 16:01:42 +02:00
|
|
|
{ "sei", "Set SEI to include",
|
|
|
|
OFFSET(sei), AV_OPT_TYPE_FLAGS,
|
2023-01-09 20:40:24 +02:00
|
|
|
{ .i64 = SEI_IDENTIFIER | SEI_TIMING | SEI_RECOVERY_POINT | SEI_A53_CC },
|
2017-05-07 16:01:42 +02:00
|
|
|
0, INT_MAX, FLAGS, "sei" },
|
|
|
|
{ "identifier", "Include encoder version identifier",
|
|
|
|
0, AV_OPT_TYPE_CONST, { .i64 = SEI_IDENTIFIER },
|
|
|
|
INT_MIN, INT_MAX, FLAGS, "sei" },
|
|
|
|
{ "timing", "Include timing parameters (buffering_period and pic_timing)",
|
|
|
|
0, AV_OPT_TYPE_CONST, { .i64 = SEI_TIMING },
|
|
|
|
INT_MIN, INT_MAX, FLAGS, "sei" },
|
2017-05-08 00:02:09 +02:00
|
|
|
{ "recovery_point", "Include recovery points where appropriate",
|
|
|
|
0, AV_OPT_TYPE_CONST, { .i64 = SEI_RECOVERY_POINT },
|
|
|
|
INT_MIN, INT_MAX, FLAGS, "sei" },
|
2023-01-09 20:40:24 +02:00
|
|
|
{ "a53_cc", "Include A/53 caption data",
|
|
|
|
0, AV_OPT_TYPE_CONST, { .i64 = SEI_A53_CC },
|
|
|
|
INT_MIN, INT_MAX, FLAGS, "sei" },
|
2017-11-29 23:31:11 +02:00
|
|
|
|
|
|
|
{ "profile", "Set profile (profile_idc and constraint_set*_flag)",
|
|
|
|
OFFSET(profile), AV_OPT_TYPE_INT,
|
2018-09-19 00:30:40 +02:00
|
|
|
{ .i64 = FF_PROFILE_UNKNOWN }, FF_PROFILE_UNKNOWN, 0xffff, FLAGS, "profile" },
|
2017-11-29 23:31:11 +02:00
|
|
|
|
|
|
|
#define PROFILE(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
|
|
|
|
{ .i64 = value }, 0, 0, FLAGS, "profile"
|
|
|
|
{ PROFILE("constrained_baseline", FF_PROFILE_H264_CONSTRAINED_BASELINE) },
|
|
|
|
{ PROFILE("main", FF_PROFILE_H264_MAIN) },
|
|
|
|
{ PROFILE("high", FF_PROFILE_H264_HIGH) },
|
|
|
|
#undef PROFILE
|
|
|
|
|
|
|
|
{ "level", "Set level (level_idc)",
|
|
|
|
OFFSET(level), AV_OPT_TYPE_INT,
|
2018-09-19 00:30:58 +02:00
|
|
|
{ .i64 = FF_LEVEL_UNKNOWN }, FF_LEVEL_UNKNOWN, 0xff, FLAGS, "level" },
|
2017-11-29 23:31:11 +02:00
|
|
|
|
|
|
|
#define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
|
|
|
|
{ .i64 = value }, 0, 0, FLAGS, "level"
|
|
|
|
{ LEVEL("1", 10) },
|
|
|
|
{ LEVEL("1.1", 11) },
|
|
|
|
{ LEVEL("1.2", 12) },
|
|
|
|
{ LEVEL("1.3", 13) },
|
|
|
|
{ LEVEL("2", 20) },
|
|
|
|
{ LEVEL("2.1", 21) },
|
|
|
|
{ LEVEL("2.2", 22) },
|
|
|
|
{ LEVEL("3", 30) },
|
|
|
|
{ LEVEL("3.1", 31) },
|
|
|
|
{ LEVEL("3.2", 32) },
|
|
|
|
{ LEVEL("4", 40) },
|
|
|
|
{ LEVEL("4.1", 41) },
|
|
|
|
{ LEVEL("4.2", 42) },
|
|
|
|
{ LEVEL("5", 50) },
|
|
|
|
{ LEVEL("5.1", 51) },
|
|
|
|
{ LEVEL("5.2", 52) },
|
|
|
|
{ LEVEL("6", 60) },
|
|
|
|
{ LEVEL("6.1", 61) },
|
|
|
|
{ LEVEL("6.2", 62) },
|
|
|
|
#undef LEVEL
|
|
|
|
|
2016-04-13 00:15:40 +02:00
|
|
|
{ NULL },
|
|
|
|
};
|
|
|
|
|
2022-03-16 22:26:11 +02:00
|
|
|
static const FFCodecDefault vaapi_encode_h264_defaults[] = {
|
2016-03-24 01:49:35 +02:00
|
|
|
{ "b", "0" },
|
|
|
|
{ "bf", "2" },
|
|
|
|
{ "g", "120" },
|
2016-08-02 19:02:09 +02:00
|
|
|
{ "i_qfactor", "1" },
|
|
|
|
{ "i_qoffset", "0" },
|
|
|
|
{ "b_qfactor", "6/5" },
|
|
|
|
{ "b_qoffset", "0" },
|
2018-09-19 00:30:46 +02:00
|
|
|
{ "qmin", "-1" },
|
|
|
|
{ "qmax", "-1" },
|
2016-03-24 01:49:35 +02:00
|
|
|
{ NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const AVClass vaapi_encode_h264_class = {
|
|
|
|
.class_name = "h264_vaapi",
|
|
|
|
.item_name = av_default_item_name,
|
2016-04-13 00:15:40 +02:00
|
|
|
.option = vaapi_encode_h264_options,
|
2016-03-24 01:49:35 +02:00
|
|
|
.version = LIBAVUTIL_VERSION_INT,
|
|
|
|
};
|
|
|
|
|
2022-03-16 22:09:54 +02:00
|
|
|
const FFCodec ff_h264_vaapi_encoder = {
|
|
|
|
.p.name = "h264_vaapi",
|
2022-08-29 13:38:02 +02:00
|
|
|
CODEC_LONG_NAME("H.264/AVC (VAAPI)"),
|
2022-03-16 22:09:54 +02:00
|
|
|
.p.type = AVMEDIA_TYPE_VIDEO,
|
|
|
|
.p.id = AV_CODEC_ID_H264,
|
2018-08-23 01:44:34 +02:00
|
|
|
.priv_data_size = sizeof(VAAPIEncodeH264Context),
|
2016-03-24 01:49:35 +02:00
|
|
|
.init = &vaapi_encode_h264_init,
|
2022-03-30 23:28:24 +02:00
|
|
|
FF_CODEC_RECEIVE_PACKET_CB(&ff_vaapi_encode_receive_packet),
|
2017-05-07 16:01:42 +02:00
|
|
|
.close = &vaapi_encode_h264_close,
|
2022-03-16 22:09:54 +02:00
|
|
|
.p.priv_class = &vaapi_encode_h264_class,
|
|
|
|
.p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE |
|
2023-01-04 19:11:19 +02:00
|
|
|
AV_CODEC_CAP_DR1 | AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
|
2022-07-09 22:25:41 +02:00
|
|
|
.caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE |
|
|
|
|
FF_CODEC_CAP_INIT_CLEANUP,
|
2016-03-24 01:49:35 +02:00
|
|
|
.defaults = vaapi_encode_h264_defaults,
|
2022-03-16 22:09:54 +02:00
|
|
|
.p.pix_fmts = (const enum AVPixelFormat[]) {
|
2016-03-24 01:49:35 +02:00
|
|
|
AV_PIX_FMT_VAAPI,
|
|
|
|
AV_PIX_FMT_NONE,
|
|
|
|
},
|
2020-04-13 17:33:17 +02:00
|
|
|
.hw_configs = ff_vaapi_encode_hw_configs,
|
2022-03-16 22:09:54 +02:00
|
|
|
.p.wrapper_name = "vaapi",
|
2016-03-24 01:49:35 +02:00
|
|
|
};
|