65 uint8_t vps_buf[128], vps_rbsp_buf[128];
66 uint8_t *new_extradata;
68 int ret,
i,
type, vps_size;
110 vps.vps_max_layers = 1;
111 vps.vps_max_sub_layers =
sps.max_sub_layers;
112 vps.vps_temporal_id_nesting_flag =
sps.temporal_id_nesting;
113 memcpy(&
vps.ptl, &
sps.ptl,
sizeof(
vps.ptl));
114 vps.vps_sub_layer_ordering_info_present_flag = 1;
116 vps.vps_max_dec_pic_buffering[
i] =
sps.temporal_layer[
i].max_dec_pic_buffering;
117 vps.vps_num_reorder_pics[
i] =
sps.temporal_layer[
i].num_reorder_pics;
118 vps.vps_max_latency_increase[
i] =
sps.temporal_layer[
i].max_latency_increase;
121 vps.vps_num_layer_sets = 1;
122 vps.vps_timing_info_present_flag =
sps.vui.vui_timing_info_present_flag;
123 vps.vps_num_units_in_tick =
sps.vui.vui_num_units_in_tick;
124 vps.vps_time_scale =
sps.vui.vui_time_scale;
125 vps.vps_poc_proportional_to_timing_flag =
sps.vui.vui_poc_proportional_to_timing_flag;
126 vps.vps_num_ticks_poc_diff_one =
sps.vui.vui_num_ticks_poc_diff_one_minus1 + 1;
127 vps.vps_num_hrd_parameters = 0;
140 bytestream2_put_be32(&pbc, 1);
142 bytestream2_put_byte(&pbc, 1);
146 bytestream2_put_be24(&pbc, 3);
149 bytestream2_put_byte(&pbc, bytestream2_get_byte(&gbc));
156 memcpy(new_extradata, vps_buf, vps_size);
181 const int mapping[3] = {1, 2, 0};
182 const int chroma_den = 50000;
183 const int luma_den = 10000;
185 mfxExtMasteringDisplayColourVolume *mdcv =
av_mallocz(
sizeof(mfxExtMasteringDisplayColourVolume));
190 mdcv->Header.BufferId = MFX_EXTBUFF_MASTERING_DISPLAY_COLOUR_VOLUME;
191 mdcv->Header.BufferSz =
sizeof(*mdcv);
193 for (
i = 0;
i < 3;
i++) {
194 const int j = mapping[
i];
196 mdcv->DisplayPrimariesX[
i] =
200 mdcv->DisplayPrimariesY[
i] =
213 mdcv->MaxDisplayMasteringLuminance =
215 mdcv->MinDisplayMasteringLuminance =
217 mdcv->MaxDisplayMasteringLuminance);
219 enc_ctrl->ExtParam[enc_ctrl->NumExtParam++] = (mfxExtBuffer *)mdcv;
226 mfxExtContentLightLevelInfo * clli =
av_mallocz(
sizeof(mfxExtContentLightLevelInfo));
231 clli->Header.BufferId = MFX_EXTBUFF_CONTENT_LIGHT_LEVEL_INFO;
232 clli->Header.BufferSz =
sizeof(*clli);
234 clli->MaxContentLightLevel =
FFMIN(clm->
MaxCLL, 65535);
235 clli->MaxPicAverageLightLevel =
FFMIN(clm->
MaxFALL, 65535);
237 enc_ctrl->ExtParam[enc_ctrl->NumExtParam++] = (mfxExtBuffer *)clli;
249 static const char *
const uid_hevcenc_sw =
"2fca99749fdb49aeb121a5b63ef568f7";
250 static const char *
const uid_hevcenc_hw =
"6fadc791a0c2eb479ab6dcd5ea9da347";
254 "load_plugins is not empty, but load_plugin is not set to 'none'."
255 "The load_plugin value will be ignored.\n");
304#define OFFSET(x) offsetof(QSVHEVCEncContext, x)
305#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
327 {
"idr_interval",
"Distance (in I-frames) between IDR frames",
OFFSET(qsv.idr_interval),
AV_OPT_TYPE_INT, { .i64 = 0 }, -1, INT_MAX,
VE, .unit =
"idr_interval" },
328 {
"begin_only",
"Output an IDR-frame only at the beginning of the stream", 0,
AV_OPT_TYPE_CONST, { .i64 = -1 }, 0, 0,
VE, .unit =
"idr_interval" },
334 {
"load_plugins",
"A :-separate list of hexadecimal plugin UIDs to load in an internal session",
337 {
"look_ahead_depth",
"Depth of look ahead in number frames, available when extbrc option is enabled",
OFFSET(qsv.look_ahead_depth),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 100,
VE },
339 {
"unknown",
NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = MFX_PROFILE_UNKNOWN }, INT_MIN, INT_MAX,
VE, .unit =
"profile" },
340 {
"main",
NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = MFX_PROFILE_HEVC_MAIN }, INT_MIN, INT_MAX,
VE, .unit =
"profile" },
341 {
"main10",
NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = MFX_PROFILE_HEVC_MAIN10 }, INT_MIN, INT_MAX,
VE, .unit =
"profile" },
342 {
"mainsp",
NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = MFX_PROFILE_HEVC_MAINSP }, INT_MIN, INT_MAX,
VE, .unit =
"profile" },
343 {
"rext",
NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = MFX_PROFILE_HEVC_REXT }, INT_MIN, INT_MAX,
VE, .unit =
"profile" },
344#if QSV_VERSION_ATLEAST(1, 32)
345 {
"scc",
NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = MFX_PROFILE_HEVC_SCC }, INT_MIN, INT_MAX,
VE, .unit =
"profile" },
347 {
"tier",
"Set the encoding tier (only level >= 4 can support high tier)",
OFFSET(qsv.tier),
AV_OPT_TYPE_INT, { .i64 = MFX_TIER_HEVC_HIGH }, MFX_TIER_HEVC_MAIN, MFX_TIER_HEVC_HIGH,
VE, .unit =
"tier" },
351 {
"gpb",
"1: GPB (generalized P/B frame); 0: regular P frame",
OFFSET(qsv.gpb),
AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1,
VE},
353 {
"tile_cols",
"Number of columns for tiled encoding",
OFFSET(qsv.tile_cols),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, UINT16_MAX,
VE },
354 {
"tile_rows",
"Number of rows for tiled encoding",
OFFSET(qsv.tile_rows),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, UINT16_MAX,
VE },
355 {
"recovery_point_sei",
"Insert recovery point SEI messages",
OFFSET(qsv.recovery_point_sei),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1,
VE },
357 {
"pic_timing_sei",
"Insert picture timing SEI with pic_struct_syntax element",
OFFSET(qsv.pic_timing_sei),
AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1,
VE },
358 {
"transform_skip",
"Turn this option ON to enable transformskip",
OFFSET(qsv.transform_skip),
AV_OPT_TYPE_INT, { .i64 = -1}, -1, 1,
VE},
359 {
"int_ref_type",
"Intra refresh type. B frames should be set to 0",
OFFSET(qsv.int_ref_type),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, UINT16_MAX,
VE, .unit =
"int_ref_type" },
364 {
"int_ref_cycle_size",
"Number of frames in the intra refresh cycle",
OFFSET(qsv.int_ref_cycle_size),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, UINT16_MAX,
VE },
365 {
"int_ref_qp_delta",
"QP difference for the refresh MBs",
OFFSET(qsv.int_ref_qp_delta),
AV_OPT_TYPE_INT, { .i64 = INT16_MIN }, INT16_MIN, INT16_MAX,
VE },
366 {
"int_ref_cycle_dist",
"Distance between the beginnings of the intra-refresh cycles in frames",
OFFSET(qsv.int_ref_cycle_dist),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT16_MAX,
VE },
390 .p.name =
"hevc_qsv",
404 .p.priv_class = &
class,
408 .p.wrapper_name =
"qsv",
const FFCodec ff_hevc_qsv_encoder
Libavcodec external API header.
static av_always_inline int bytestream2_tell_p(const PutByteContext *p)
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
static av_always_inline int bytestream2_get_bytes_left(const GetByteContext *g)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
#define i(width, name, range_min, range_max)
static int FUNC sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
static int FUNC vps(CodedBitstreamContext *ctx, RWContext *rw, H265RawVPS *current)
#define CODEC_PIXFMTS(...)
#define FF_CODEC_CAP_NOT_INIT_THREADSAFE
The codec is not known to be init-threadsafe (i.e.
#define FF_CODEC_ENCODE_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...
common internal and external API header
bitstream reader API header.
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define AV_CODEC_CAP_HYBRID
Codec is potentially backed by a hardware implementation, but not necessarily.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_malloc but the buffer has additional AV_INPUT_BUFFER_PADDING_SIZE at the end w...
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
@ AV_FRAME_DATA_CONTENT_LIGHT_LEVEL
Content light level (based on CTA-861.3).
@ AV_FRAME_DATA_MASTERING_DISPLAY_METADATA
Mastering display metadata associated with a video frame.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
#define LIBAVUTIL_VERSION_INT
int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id, unsigned nuh_layer_id, int apply_defdispwin, const HEVCVPS *const *vps_list, AVCodecContext *avctx)
Parse the SPS from the bitstream into the provided HEVCSPS struct.
int ff_hevc_encode_nal_vps(HEVCVPS *vps, unsigned int id, uint8_t *buf, int buf_size)
int ff_h2645_extract_rbsp(const uint8_t *src, int length, H2645RBSP *rbsp, H2645NAL *nal, int small_padding)
Extract the raw (unescaped) bitstream.
Memory handling functions.
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
@ AVCOL_RANGE_JPEG
Full range content.
#define AV_PIX_FMT_X2RGB10
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
@ AV_PIX_FMT_VUYX
packed VUYX 4:4:4:4, 32bpp, Variant of VUYA where alpha channel is left undefined
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
@ AV_PIX_FMT_YUYV422
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
@ AV_PIX_FMT_QSV
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
#define QSV_RUNTIME_VERSION_ATLEAST(MFX_VERSION, MAJOR, MINOR)
int ff_qsv_enc_close(AVCodecContext *avctx, QSVEncContext *q)
int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q)
int ff_qsv_encode(AVCodecContext *avctx, QSVEncContext *q, AVPacket *pkt, const AVFrame *frame, int *got_packet)
const AVCodecHWConfigInternal *const ff_qsv_enc_hw_configs[]
#define QSV_OPTION_P_STRATEGY
#define QSV_OPTION_LOW_DELAY_BRC
#define QSV_OPTION_MAX_SLICE_SIZE
#define QSV_OPTION_SCENARIO
#define QSV_OPTION_DBLK_IDC
#define QSV_OPTION_B_STRATEGY
#define QSV_OPTION_MAX_FRAME_SIZE
#define QSV_OPTION_SKIP_FRAME
#define QSV_OPTION_ADAPTIVE_I
#define QSV_OPTION_EXTBRC
#define QSV_OPTION_ADAPTIVE_B
#define QSV_OPTION_MAX_MIN_QP
static int qsv_enc_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
static const FFCodecDefault qsv_enc_defaults[]
static av_cold int qsv_enc_init(AVCodecContext *avctx)
static av_cold int qsv_enc_close(AVCodecContext *avctx)
static int qsv_enc_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
static int generate_fake_vps(QSVEncContext *q, AVCodecContext *avctx)
static av_cold int qsv_enc_init(AVCodecContext *avctx)
static int qsv_hevc_set_encode_ctrl(AVCodecContext *avctx, const AVFrame *frame, mfxEncodeCtrl *enc_ctrl)
static av_cold int qsv_enc_close(AVCodecContext *avctx)
Describe the class of an AVClass context structure.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
main external API structure.
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
unsigned MaxFALL
Max average light level per frame (cd/m^2).
unsigned MaxCLL
Max content light level (cd/m^2).
Structure to hold side data for an AVFrame.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
int rbsp_buffer_alloc_size
SetEncodeCtrlCB * set_encode_ctrl_cb