Lines Matching refs:avctx
175 static void dump_video_param(AVCodecContext *avctx, QSVEncContext *q,
195 av_log(avctx, AV_LOG_VERBOSE, "profile: %s; level: %"PRIu16"\n",
196 print_profile(avctx->codec_id, info->CodecProfile), info->CodecLevel);
198 av_log(avctx, AV_LOG_VERBOSE, "GopPicSize: %"PRIu16"; GopRefDist: %"PRIu16"; GopOptFlag: ",
201 av_log(avctx, AV_LOG_VERBOSE, "closed ");
203 av_log(avctx, AV_LOG_VERBOSE, "strict ");
204 av_log(avctx, AV_LOG_VERBOSE, "; IdrInterval: %"PRIu16"\n", info->IdrInterval);
206 av_log(avctx, AV_LOG_VERBOSE, "TargetUsage: %"PRIu16"; RateControlMethod: %s\n",
215 av_log(avctx, AV_LOG_VERBOSE,
219 av_log(avctx, AV_LOG_VERBOSE, "QPI: %"PRIu16"; QPP: %"PRIu16"; QPB: %"PRIu16"\n",
224 av_log(avctx, AV_LOG_VERBOSE,
232 av_log(avctx, AV_LOG_VERBOSE,
237 av_log(avctx, AV_LOG_VERBOSE, "ICQQuality: %"PRIu16"\n", info->ICQQuality);
238 av_log(avctx, AV_LOG_VERBOSE, "NumSlice: %"PRIu16"; NumRefFrame: %"PRIu16"\n",
240 av_log(avctx, AV_LOG_VERBOSE, "RateDistortionOpt: %s\n",
243 av_log(avctx, AV_LOG_VERBOSE, "RecoveryPointSEI: %s\n", print_threestate(co->RecoveryPointSEI));
244 av_log(avctx, AV_LOG_VERBOSE, "VDENC: %s\n", print_threestate(info->LowPower));
246 if (avctx->codec_id == AV_CODEC_ID_H264) {
247 av_log(avctx, AV_LOG_VERBOSE, "Entropy coding: %s; MaxDecFrameBuffering: %"PRIu16"\n",
249 av_log(avctx, AV_LOG_VERBOSE,
253 } else if ((avctx->codec_id == AV_CODEC_ID_HEVC) && QSV_RUNTIME_VERSION_ATLEAST(q->ver, 1, 28)) {
254 av_log(avctx, AV_LOG_VERBOSE,
259 av_log(avctx, AV_LOG_VERBOSE, "FrameRateExtD: %"PRIu32"; FrameRateExtN: %"PRIu32" \n",
267 av_log(avctx, AV_LOG_VERBOSE, "LookAheadDepth: %"PRIu16"\n", co2->LookAheadDepth);
269 av_log(avctx, AV_LOG_VERBOSE, "IntRefType: %"PRIu16"; IntRefCycleSize: %"PRIu16"; IntRefQPDelta: %"PRId16"\n",
272 av_log(avctx, AV_LOG_VERBOSE, "MaxFrameSize: %d; ", co2->MaxFrameSize);
273 av_log(avctx, AV_LOG_VERBOSE, "MaxSliceSize: %d; ", co2->MaxSliceSize);
274 av_log(avctx, AV_LOG_VERBOSE, "\n");
276 av_log(avctx, AV_LOG_VERBOSE,
281 av_log(avctx, AV_LOG_VERBOSE, "Trellis: ");
283 av_log(avctx, AV_LOG_VERBOSE, "off");
285 av_log(avctx, AV_LOG_VERBOSE, "auto");
287 if (co2->Trellis & MFX_TRELLIS_I) av_log(avctx, AV_LOG_VERBOSE, "I");
288 if (co2->Trellis & MFX_TRELLIS_P) av_log(avctx, AV_LOG_VERBOSE, "P");
289 if (co2->Trellis & MFX_TRELLIS_B) av_log(avctx, AV_LOG_VERBOSE, "B");
291 av_log(avctx, AV_LOG_VERBOSE, "\n");
293 av_log(avctx, AV_LOG_VERBOSE,
297 case MFX_LOOKAHEAD_DS_OFF: av_log(avctx, AV_LOG_VERBOSE, "off"); break;
298 case MFX_LOOKAHEAD_DS_2x: av_log(avctx, AV_LOG_VERBOSE, "2x"); break;
299 case MFX_LOOKAHEAD_DS_4x: av_log(avctx, AV_LOG_VERBOSE, "4x"); break;
300 default: av_log(avctx, AV_LOG_VERBOSE, "unknown"); break;
302 av_log(avctx, AV_LOG_VERBOSE, "\n");
304 av_log(avctx, AV_LOG_VERBOSE, "AdaptiveI: %s; AdaptiveB: %s; BRefType: ",
307 case MFX_B_REF_OFF: av_log(avctx, AV_LOG_VERBOSE, "off"); break;
308 case MFX_B_REF_PYRAMID: av_log(avctx, AV_LOG_VERBOSE, "pyramid"); break;
309 default: av_log(avctx, AV_LOG_VERBOSE, "auto"); break;
312 av_log(avctx, AV_LOG_VERBOSE,
315 av_log(avctx, AV_LOG_VERBOSE, "DisableDeblockingIdc: %"PRIu32" \n", co2->DisableDeblockingIdc);
320 av_log(avctx, AV_LOG_VERBOSE, "QVBRQuality: %"PRIu16"\n", co3->QVBRQuality);
322 av_log(avctx, AV_LOG_VERBOSE, "PRefType: ");
324 case MFX_P_REF_DEFAULT: av_log(avctx, AV_LOG_VERBOSE, "default"); break;
325 case MFX_P_REF_SIMPLE: av_log(avctx, AV_LOG_VERBOSE, "simple"); break;
326 case MFX_P_REF_PYRAMID: av_log(avctx, AV_LOG_VERBOSE, "pyramid"); break;
327 default: av_log(avctx, AV_LOG_VERBOSE, "unknown"); break;
329 av_log(avctx, AV_LOG_VERBOSE, "\n");
331 if (avctx->codec_id == AV_CODEC_ID_HEVC)
332 av_log(avctx, AV_LOG_VERBOSE,"GPB: %s\n", print_threestate(co3->GPB));
334 av_log(avctx, AV_LOG_VERBOSE, "TransformSkip: %s \n", print_threestate(co3->TransformSkip));
335 av_log(avctx, AV_LOG_VERBOSE, "IntRefCycleDist: %"PRId16"\n", co3->IntRefCycleDist);
336 av_log(avctx, AV_LOG_VERBOSE, "LowDelayBRC: %s\n", print_threestate(co3->LowDelayBRC));
337 av_log(avctx, AV_LOG_VERBOSE, "MaxFrameSizeI: %d; ", co3->MaxFrameSizeI);
338 av_log(avctx, AV_LOG_VERBOSE, "MaxFrameSizeP: %d\n", co3->MaxFrameSizeP);
342 av_log(avctx, AV_LOG_VERBOSE, "NumTileColumns: %"PRIu16"; NumTileRows: %"PRIu16"\n",
347 static void dump_video_vp9_param(AVCodecContext *avctx, QSVEncContext *q,
360 av_log(avctx, AV_LOG_VERBOSE, "profile: %s \n",
361 print_profile(avctx->codec_id, info->CodecProfile));
363 av_log(avctx, AV_LOG_VERBOSE, "GopPicSize: %"PRIu16"; GopRefDist: %"PRIu16"; GopOptFlag: ",
366 av_log(avctx, AV_LOG_VERBOSE, "closed ");
368 av_log(avctx, AV_LOG_VERBOSE, "strict ");
369 av_log(avctx, AV_LOG_VERBOSE, "; IdrInterval: %"PRIu16"\n", info->IdrInterval);
371 av_log(avctx, AV_LOG_VERBOSE, "TargetUsage: %"PRIu16"; RateControlMethod: %s\n",
376 av_log(avctx, AV_LOG_VERBOSE,
380 av_log(avctx, AV_LOG_VERBOSE, "QPI: %"PRIu16"; QPP: %"PRIu16"; QPB: %"PRIu16"\n",
384 av_log(avctx, AV_LOG_VERBOSE, "ICQQuality: %"PRIu16"\n", info->ICQQuality);
387 av_log(avctx, AV_LOG_VERBOSE, "Unsupported ratecontrol method: %d \n", info->RateControlMethod);
390 av_log(avctx, AV_LOG_VERBOSE, "NumRefFrame: %"PRIu16"\n", info->NumRefFrame);
391 av_log(avctx, AV_LOG_VERBOSE, "FrameRateExtD: %"PRIu32"; FrameRateExtN: %"PRIu32" \n",
395 av_log(avctx, AV_LOG_VERBOSE,
399 av_log(avctx, AV_LOG_VERBOSE, "MaxFrameSize: %d; ", co2->MaxFrameSize);
400 av_log(avctx, AV_LOG_VERBOSE, "\n");
402 av_log(avctx, AV_LOG_VERBOSE,
407 av_log(avctx, AV_LOG_VERBOSE, "VDENC: %s\n", print_threestate(info->LowPower));
409 av_log(avctx, AV_LOG_VERBOSE,
415 av_log(avctx, AV_LOG_VERBOSE, "WriteIVFHeaders: %s \n",
420 static void dump_video_mjpeg_param(AVCodecContext *avctx, QSVEncContext *q)
424 av_log(avctx, AV_LOG_VERBOSE, "Interleaved: %"PRIu16" \n", info->Interleaved);
425 av_log(avctx, AV_LOG_VERBOSE, "Quality: %"PRIu16" \n", info->Quality);
426 av_log(avctx, AV_LOG_VERBOSE, "RestartInterval: %"PRIu16" \n", info->RestartInterval);
428 av_log(avctx, AV_LOG_VERBOSE, "FrameRateExtD: %"PRIu32"; FrameRateExtN: %"PRIu32" \n",
432 static int select_rc_mode(AVCodecContext *avctx, QSVEncContext *q)
438 int want_qscale = !!(avctx->flags & AV_CODEC_FLAG_QSCALE);
442 av_log(avctx, AV_LOG_ERROR,
448 av_log(avctx, AV_LOG_ERROR,
468 if (avctx->global_quality > 0) {
473 else if (avctx->global_quality > 0 && !avctx->rc_max_rate) {
477 else if (avctx->rc_max_rate == avctx->bit_rate) {
482 else if (!avctx->rc_max_rate) {
487 else if (avctx->global_quality > 0) {
497 av_log(avctx, AV_LOG_VERBOSE, "Using the %s ratecontrol method\n", rc_desc);
502 static int check_enc_param(AVCodecContext *avctx, QSVEncContext *q)
513 av_log(avctx, AV_LOG_ERROR, "Current codec type is unsupported\n");
515 av_log(avctx, AV_LOG_ERROR, "Current profile is unsupported\n");
517 av_log(avctx, AV_LOG_ERROR, "Selected ratecontrol mode is unsupported\n");
519 av_log(avctx, AV_LOG_ERROR, "Low power mode is unsupported\n");
521 av_log(avctx, AV_LOG_ERROR, "Current frame rate is unsupported\n");
523 av_log(avctx, AV_LOG_ERROR, "Current picture structure is unsupported\n");
525 av_log(avctx, AV_LOG_ERROR, "Current resolution is unsupported\n");
527 av_log(avctx, AV_LOG_ERROR, "Current pixel format is unsupported\n");
533 static int init_video_param_jpeg(AVCodecContext *avctx, QSVEncContext *q)
535 enum AVPixelFormat sw_format = avctx->pix_fmt == AV_PIX_FMT_QSV ?
536 avctx->sw_pix_fmt : avctx->pix_fmt;
540 ret = ff_qsv_codec_id_to_mfx(avctx->codec_id);
545 if (avctx->level > 0)
546 q->param.mfx.CodecLevel = avctx->level;
559 q->param.mfx.FrameInfo.CropW = avctx->width;
560 q->param.mfx.FrameInfo.CropH = avctx->height;
561 q->param.mfx.FrameInfo.AspectRatioW = avctx->sample_aspect_ratio.num;
562 q->param.mfx.FrameInfo.AspectRatioH = avctx->sample_aspect_ratio.den;
569 q->param.mfx.FrameInfo.Width = FFALIGN(avctx->width, 16);
570 q->param.mfx.FrameInfo.Height = FFALIGN(avctx->height, 16);
572 if (avctx->hw_frames_ctx) {
573 AVHWFramesContext *frames_ctx = (AVHWFramesContext *)avctx->hw_frames_ctx->data;
579 if (avctx->framerate.den > 0 && avctx->framerate.num > 0) {
580 q->param.mfx.FrameInfo.FrameRateExtN = avctx->framerate.num;
581 q->param.mfx.FrameInfo.FrameRateExtD = avctx->framerate.den;
583 q->param.mfx.FrameInfo.FrameRateExtN = avctx->time_base.den;
584 q->param.mfx.FrameInfo.FrameRateExtD = avctx->time_base.num;
588 q->param.mfx.Quality = av_clip(avctx->global_quality, 1, 100);
594 q->param.mfx.FrameInfo.Width = FFALIGN(avctx->width, q->width_align);
595 q->param.mfx.FrameInfo.Height = FFALIGN(avctx->height, q->height_align);
600 static int init_video_param(AVCodecContext *avctx, QSVEncContext *q)
602 enum AVPixelFormat sw_format = avctx->pix_fmt == AV_PIX_FMT_QSV ?
603 avctx->sw_pix_fmt : avctx->pix_fmt;
610 ret = ff_qsv_codec_id_to_mfx(avctx->codec_id);
615 if (avctx->level > 0)
616 q->param.mfx.CodecLevel = avctx->level;
618 if (avctx->compression_level == FF_COMPRESSION_DEFAULT) {
619 avctx->compression_level = q->preset;
620 } else if (avctx->compression_level >= 0) {
621 if (avctx->compression_level > MFX_TARGETUSAGE_BEST_SPEED) {
622 av_log(avctx, AV_LOG_WARNING, "Invalid compression level: "
625 avctx->compression_level = MFX_TARGETUSAGE_BEST_SPEED;
637 q->param.mfx.TargetUsage = avctx->compression_level;
638 q->param.mfx.GopPicSize = FFMAX(0, avctx->gop_size);
639 q->param.mfx.GopRefDist = FFMAX(-1, avctx->max_b_frames) + 1;
640 q->param.mfx.GopOptFlag = avctx->flags & AV_CODEC_FLAG_CLOSED_GOP ?
643 q->param.mfx.NumSlice = avctx->slices;
644 q->param.mfx.NumRefFrame = FFMAX(0, avctx->refs);
658 q->param.mfx.FrameInfo.CropW = avctx->width;
659 q->param.mfx.FrameInfo.CropH = avctx->height;
660 q->param.mfx.FrameInfo.AspectRatioW = avctx->sample_aspect_ratio.num;
661 q->param.mfx.FrameInfo.AspectRatioH = avctx->sample_aspect_ratio.den;
670 q->width_align = (avctx->codec_id != AV_CODEC_ID_HEVC ||
672 q->param.mfx.FrameInfo.Width = FFALIGN(avctx->width, q->width_align);
674 if (avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT) {
686 q->height_align = avctx->codec_id == AV_CODEC_ID_HEVC ? 32 : 16;
688 q->param.mfx.FrameInfo.Height = FFALIGN(avctx->height, q->height_align);
690 if (avctx->hw_frames_ctx) {
691 AVHWFramesContext *frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
697 if (avctx->framerate.den > 0 && avctx->framerate.num > 0) {
698 q->param.mfx.FrameInfo.FrameRateExtN = avctx->framerate.num;
699 q->param.mfx.FrameInfo.FrameRateExtD = avctx->framerate.den;
701 q->param.mfx.FrameInfo.FrameRateExtN = avctx->time_base.den;
702 q->param.mfx.FrameInfo.FrameRateExtD = avctx->time_base.num;
705 ret = select_rc_mode(avctx, q);
710 buffer_size_in_kilobytes = avctx->rc_buffer_size / 8000;
711 initial_delay_in_kilobytes = avctx->rc_initial_buffer_occupancy / 8000;
712 target_bitrate_kbps = avctx->bit_rate / 1000;
713 max_bitrate_kbps = avctx->rc_max_rate / 1000;
733 q->extco3.QVBRQuality = av_clip(avctx->global_quality, 0, 51);
736 quant = avctx->global_quality / FF_QP2LAMBDA;
738 q->param.mfx.QPI = av_clip(quant * fabs(avctx->i_quant_factor) + avctx->i_quant_offset, 0, 51);
740 q->param.mfx.QPB = av_clip(quant * fabs(avctx->b_quant_factor) + avctx->b_quant_offset, 0, 51);
759 q->param.mfx.ICQQuality = av_clip(avctx->global_quality, 1, 51);
766 if (((avctx->codec_id != AV_CODEC_ID_HEVC) || QSV_RUNTIME_VERSION_ATLEAST(q->ver, 1, 28))
767 && (avctx->codec_id != AV_CODEC_ID_VP9)) {
777 if (avctx->codec_id == AV_CODEC_ID_H264) {
781 if (avctx->strict_std_compliance != FF_COMPLIANCE_NORMAL)
782 q->extco.NalHrdConformance = avctx->strict_std_compliance > FF_COMPLIANCE_NORMAL ?
791 } else if (avctx->codec_id == AV_CODEC_ID_HEVC) {
792 if (avctx->strict_std_compliance != FF_COMPLIANCE_NORMAL)
793 q->extco.NalHrdConformance = avctx->strict_std_compliance > FF_COMPLIANCE_NORMAL ?
804 if (avctx->codec_id == AV_CODEC_ID_H264) {
808 if (avctx->trellis >= 0)
809 q->extco2.Trellis = (avctx->trellis == 0) ? MFX_TRELLIS_OFF : (MFX_TRELLIS_I | MFX_TRELLIS_P | MFX_TRELLIS_B);
822 if (avctx->codec_id == AV_CODEC_ID_H264 || avctx->codec_id == AV_CODEC_ID_HEVC) {
839 if ((avctx->qmin >= 0 && avctx->qmax >= 0 && avctx->qmin > avctx->qmax) ||
843 av_log(avctx, AV_LOG_ERROR,
848 if (avctx->qmin >= 0) {
849 q->extco2.MinQPI = avctx->qmin > 51 ? 51 : avctx->qmin;
852 if (avctx->qmax >= 0) {
853 q->extco2.MaxQPI = avctx->qmax > 51 ? 51 : avctx->qmax;
877 if (avctx->codec_id == AV_CODEC_ID_H264) {
884 av_log(avctx,AV_LOG_VERBOSE,"MFMode:%d\n", q->extmfp.MFMode);
892 if (avctx->codec_id == AV_CODEC_ID_HEVC ||
893 avctx->codec_id == AV_CODEC_ID_H264) {
906 av_log(avctx, AV_LOG_WARNING,
911 avctx->max_b_frames != 0) {
912 av_log(avctx, AV_LOG_WARNING,
925 if (avctx->codec_id == AV_CODEC_ID_HEVC) {
936 if (avctx->codec_id == AV_CODEC_ID_VP9) {
947 if (avctx->codec_id == AV_CODEC_ID_HEVC) {
955 q->extvsi.VideoFullRange = (avctx->color_range == AVCOL_RANGE_JPEG);
958 if (avctx->color_primaries != AVCOL_PRI_UNSPECIFIED ||
959 avctx->color_trc != AVCOL_TRC_UNSPECIFIED ||
960 avctx->colorspace != AVCOL_SPC_UNSPECIFIED) {
962 q->extvsi.ColourPrimaries = avctx->color_primaries;
963 q->extvsi.TransferCharacteristics = avctx->color_trc;
964 q->extvsi.MatrixCoefficients = avctx->colorspace;
973 if (!check_enc_param(avctx,q)) {
974 av_log(avctx, AV_LOG_ERROR,
983 static int qsv_retrieve_enc_jpeg_params(AVCodecContext *avctx, QSVEncContext *q)
989 return ff_qsv_print_error(avctx, ret,
998 dump_video_mjpeg_param(avctx, q);
1003 static int qsv_retrieve_enc_vp9_params(AVCodecContext *avctx, QSVEncContext *q)
1047 return ff_qsv_print_error(avctx, ret,
1052 dump_video_vp9_param(avctx, q, ext_buffers);
1057 static int qsv_retrieve_enc_params(AVCodecContext *avctx, QSVEncContext *q)
1099 int need_pps = avctx->codec_id != AV_CODEC_ID_MPEG2VIDEO;
1117 q->hevc_vps = ((avctx->codec_id == AV_CODEC_ID_HEVC) && QSV_RUNTIME_VERSION_ATLEAST(q->ver, 1, 17));
1120 if (avctx->codec_id == AV_CODEC_ID_HEVC && QSV_RUNTIME_VERSION_ATLEAST(q->ver, 1, 13)) {
1130 return ff_qsv_print_error(avctx, ret,
1138 av_log(avctx, AV_LOG_ERROR, "No extradata returned from libmfx.\n");
1142 avctx->extradata_size = extradata.SPSBufSize + need_pps * extradata.PPSBufSize;
1143 avctx->extradata_size += q->hevc_vps * extradata_vps.VPSBufSize;
1145 avctx->extradata = av_malloc(avctx->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
1146 if (!avctx->extradata)
1150 memcpy(avctx->extradata, vps_buf, extradata_vps.VPSBufSize);
1154 memcpy(avctx->extradata + extradata_offset, sps_buf, extradata.SPSBufSize);
1157 memcpy(avctx->extradata + extradata_offset, pps_buf, extradata.PPSBufSize);
1160 memset(avctx->extradata + avctx->extradata_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
1162 cpb_props = ff_add_cpb_side_data(avctx);
1165 cpb_props->max_bitrate = avctx->rc_max_rate;
1166 cpb_props->min_bitrate = avctx->rc_min_rate;
1167 cpb_props->avg_bitrate = avctx->bit_rate;
1168 cpb_props->buffer_size = avctx->rc_buffer_size;
1170 dump_video_param(avctx, q, ext_buffers);
1175 static int qsv_init_opaque_alloc(AVCodecContext *avctx, QSVEncContext *q)
1177 AVQSVContext *qsv = avctx->hwaccel_context;
1212 static int qsvenc_init_session(AVCodecContext *avctx, QSVEncContext *q)
1216 if (avctx->hwaccel_context) {
1217 AVQSVContext *qsv = avctx->hwaccel_context;
1219 } else if (avctx->hw_frames_ctx) {
1220 q->frames_ctx.hw_frames_ctx = av_buffer_ref(avctx->hw_frames_ctx);
1224 ret = ff_qsv_init_session_frames(avctx, &q->internal_qs.session,
1234 } else if (avctx->hw_device_ctx) {
1235 ret = ff_qsv_init_session_device(avctx, &q->internal_qs.session,
1236 avctx->hw_device_ctx, q->load_plugins,
1243 ret = ff_qsv_init_internal_session(avctx, &q->internal_qs,
1254 int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q)
1266 if (avctx->hwaccel_context) {
1267 AVQSVContext *qsv = avctx->hwaccel_context;
1273 if (avctx->hw_frames_ctx) {
1274 AVHWFramesContext *frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
1289 ff_qsv_print_iopattern(avctx, iopattern, "Encoder");
1291 ret = qsvenc_init_session(avctx, q);
1297 return ff_qsv_print_error(avctx, ret,
1302 switch (avctx->codec_id) {
1304 ret = init_video_param_jpeg(avctx, q);
1307 ret = init_video_param(avctx, q);
1313 if (avctx->hwaccel_context) {
1314 AVQSVContext *qsv = avctx->hwaccel_context;
1344 av_log(avctx, AV_LOG_WARNING, "Encoder will work with partial HW acceleration\n");
1346 return ff_qsv_print_error(avctx, ret,
1352 return ff_qsv_print_error(avctx, ret,
1356 ret = qsv_init_opaque_alloc(avctx, q);
1363 return ff_qsv_print_error(avctx, ret,
1366 ff_qsv_print_warning(avctx, ret,
1369 switch (avctx->codec_id) {
1371 ret = qsv_retrieve_enc_jpeg_params(avctx, q);
1374 ret = qsv_retrieve_enc_vp9_params(avctx, q);
1377 ret = qsv_retrieve_enc_params(avctx, q);
1381 av_log(avctx, AV_LOG_ERROR, "Error retrieving encoding parameters.\n");
1385 q->avctx = avctx;
1540 av_log(q->avctx, AV_LOG_ERROR, "map frame to surface failed.\n");
1544 qf->surface.Data.TimeStamp = av_rescale_q(frame->pts, q->avctx->time_base, (AVRational){1, 90000});
1551 static void print_interlace_msg(AVCodecContext *avctx, QSVEncContext *q)
1557 av_log(avctx, AV_LOG_WARNING,
1563 static int set_roi_encode_ctrl(AVCodecContext *avctx, const AVFrame *frame,
1569 if (avctx->codec_id == AV_CODEC_ID_H264)
1571 else if (avctx->codec_id == AV_CODEC_ID_H265)
1588 av_log(avctx, AV_LOG_ERROR, "Invalid ROI Data.\n");
1593 av_log(avctx, AV_LOG_WARNING, "More ROIs set than "
1614 av_log(avctx, AV_LOG_DEBUG, "ROI: (%d,%d)-(%d,%d) -> %+d.\n",
1624 static int update_qp(AVCodecContext *avctx, QSVEncContext *q,
1631 if (avctx->codec_id != AV_CODEC_ID_H264 && avctx->codec_id != AV_CODEC_ID_HEVC)
1638 av_log(avctx, AV_LOG_WARNING, "Invalid qsv_config_qp string. Ignore this metadata\n");
1642 av_log(avctx, AV_LOG_WARNING, "Invalid qp, clip to 0 ~ 51\n");
1645 av_log(avctx, AV_LOG_DEBUG, "Configure qp: %d\n",qp);
1647 new_qp = av_clip(qp * fabs(avctx->i_quant_factor) +
1648 avctx->i_quant_offset, 0, 51);
1650 new_qp = av_clip(qp * fabs(avctx->b_quant_factor) +
1651 avctx->b_quant_offset, 0, 51);
1653 av_log(avctx, AV_LOG_DEBUG,
1660 static int update_parameters(AVCodecContext *avctx, QSVEncContext *q,
1668 needReset = update_qp(avctx, q, frame);
1672 if (avctx->hwaccel_context) {
1673 AVQSVContext *qsv = avctx->hwaccel_context;
1693 av_log(avctx, AV_LOG_DEBUG, "Parameter change, call msdk reset.\n");
1696 return ff_qsv_print_error(avctx, ret, "Error during resetting");
1701 static int encode_frame(AVCodecContext *avctx, QSVEncContext *q,
1716 av_log(avctx, AV_LOG_ERROR, "Error submitting the frame for encoding.\n");
1733 av_log(avctx, AV_LOG_ERROR, "Error allocating the output packet\n");
1743 if (avctx->codec_id == AV_CODEC_ID_H264) {
1760 q->set_encode_ctrl_cb(avctx, frame, &qsv_frame->enc_ctrl);
1763 if ((avctx->codec_id == AV_CODEC_ID_H264 ||
1764 avctx->codec_id == AV_CODEC_ID_H265) &&
1766 ret = set_roi_encode_ctrl(avctx, frame, enc_ctrl);
1782 ff_qsv_print_warning(avctx, ret, "Warning during encoding");
1786 0 : ff_qsv_print_error(avctx, ret, "Error during encoding");
1791 print_interlace_msg(avctx, q);
1802 if (avctx->codec_id == AV_CODEC_ID_H264) {
1814 int ff_qsv_encode(AVCodecContext *avctx, QSVEncContext *q,
1819 ret = update_parameters(avctx, q, frame);
1823 ret = encode_frame(avctx, q, frame);
1840 qpkt.pkt.dts = av_rescale_q(qpkt.bs->DecodeTimeStamp, (AVRational){1, 90000}, avctx->time_base);
1841 qpkt.pkt.pts = av_rescale_q(qpkt.bs->TimeStamp, (AVRational){1, 90000}, avctx->time_base);
1855 av_log(avctx, AV_LOG_WARNING, "Unknown FrameType, set pict_type to AV_PICTURE_TYPE_NONE.\n");
1857 av_log(avctx, AV_LOG_ERROR, "Invalid FrameType:%d.\n", qpkt.bs->FrameType);
1861 if (avctx->codec_id == AV_CODEC_ID_H264) {
1880 int ff_qsv_enc_close(AVCodecContext *avctx, QSVEncContext *q)
1906 if (avctx->codec_id == AV_CODEC_ID_H264) {