| @@ -597,6 +597,13 @@ static int select_rc_mode(AVCodecContext *avctx, QSVEncContext *q) · 596 unmodified lines |
| 597 | 597 | else if (want_vcm) { |
| 598 | 598 | rc_mode = MFX_RATECONTROL_VCM; |
| 599 | 599 | rc_desc = "video conferencing mode (VCM)"; |
| 600 | + |
| 601 | + if (!avctx->bit_rate) { |
| 602 | + av_log(avctx, AV_LOG_ERROR, "Using the %s ratecontrol method without " |
| 603 | + "setting bitrate. Please use the b option to set the desired " |
| 604 | + "bitrate.\n", rc_desc); |
| 605 | + return AVERROR(EINVAL); |
| 606 | + } |
| 600 | 607 | } |
| 601 | 608 | #endif |
| 602 | 609 | else if (want_la) { |
| @@ -606,32 +613,50 @@ static int select_rc_mode(AVCodecContext *avctx, QSVEncContext *q) · 3 unmodified lines |
| 606 | 613 | if (avctx->global_quality > 0) { |
| 607 | 614 | rc_mode = MFX_RATECONTROL_LA_ICQ; |
| 608 | 615 | rc_desc = "intelligent constant quality with lookahead (LA_ICQ)"; |
| 616 | + } else if (!avctx->bit_rate) { |
| 617 | + av_log(avctx, AV_LOG_ERROR, "Using the %s ratecontrol method without " |
| 618 | + "setting bitrate. Please use the b option to set the desired " |
| 619 | + "bitrate.\n", rc_desc); |
| 620 | + return AVERROR(EINVAL); |
| 609 | 621 | } |
| 610 | 622 | } |
| 611 | 623 | else if (avctx->global_quality > 0 && !avctx->rc_max_rate) { |
| 612 | 624 | rc_mode = MFX_RATECONTROL_ICQ; |
| 613 | 625 | rc_desc = "intelligent constant quality (ICQ)"; |
| 614 | 626 | } |
| 615 | | − else if (avctx->rc_max_rate == avctx->bit_rate) { |
| 616 | | − rc_mode = MFX_RATECONTROL_CBR; |
| 617 | | − rc_desc = "constant bitrate (CBR)"; |
| 618 | | − } |
| 627 | + else if (avctx->bit_rate) { |
| 628 | + if (avctx->rc_max_rate == avctx->bit_rate) { |
| 629 | + rc_mode = MFX_RATECONTROL_CBR; |
| 630 | + rc_desc = "constant bitrate (CBR)"; |
| 631 | + } |
| 619 | 632 | #if QSV_HAVE_AVBR |
| 620 | | − else if (!avctx->rc_max_rate && |
| 621 | | − (avctx->codec_id == AV_CODEC_ID_H264 || avctx->codec_id == AV_CODEC_ID_HEVC) && |
| 622 | | − q->avbr_accuracy && |
| 623 | | − q->avbr_convergence) { |
| 624 | | − rc_mode = MFX_RATECONTROL_AVBR; |
| 625 | | − rc_desc = "average variable bitrate (AVBR)"; |
| 626 | | − } |
| 633 | + else if (!avctx->rc_max_rate && |
| 634 | + (avctx->codec_id == AV_CODEC_ID_H264 || avctx->codec_id == AV_CODEC_ID_HEVC) && |
| 635 | + q->avbr_accuracy && |
| 636 | + q->avbr_convergence) { |
| 637 | + rc_mode = MFX_RATECONTROL_AVBR; |
| 638 | + rc_desc = "average variable bitrate (AVBR)"; |
| 639 | + } |
| 627 | 640 | #endif |
| 628 | | − else if (avctx->global_quality > 0) { |
| 629 | | − rc_mode = MFX_RATECONTROL_QVBR; |
| 630 | | − rc_desc = "constant quality with VBR algorithm (QVBR)"; |
| 631 | | − } |
| 632 | | − else { |
| 633 | | − rc_mode = MFX_RATECONTROL_VBR; |
| 634 | | − rc_desc = "variable bitrate (VBR)"; |
| 641 | + else if (avctx->global_quality > 0) { |
| 642 | + rc_mode = MFX_RATECONTROL_QVBR; |
| 643 | + rc_desc = "constant quality with VBR algorithm (QVBR)"; |
| 644 | + } else { |
| 645 | + rc_mode = MFX_RATECONTROL_VBR; |
| 646 | + rc_desc = "variable bitrate (VBR)"; |
| 647 | + } |
| 648 | + } else { |
| 649 | + rc_mode = MFX_RATECONTROL_CQP; |
| 650 | + rc_desc = "constant quantization parameter (CQP)"; |
| 651 | + if (avctx->codec_id == AV_CODEC_ID_AV1) |
| 652 | + avctx->global_quality = FF_QP2LAMBDA * 128; |
| 653 | + else |
| 654 | + avctx->global_quality = FF_QP2LAMBDA * 26; |
| 655 | + av_log(avctx, AV_LOG_WARNING, "Using the constant quantization " |
| 656 | + "parameter (CQP) by default. Please use the global_quality " |
| 657 | + "option and other options for a quality-based mode or the b " |
| 658 | + "option and other options for a bitrate-based mode if the " |
| 659 | + "default is not the desired choice.\n"); |
| 635 | 660 | } |
| 636 | 661 | |
| 637 | 662 | q->param.mfx.RateControlMethod = rc_mode; |