Use VideoCodec complexity to determine AV1 encoder cpu_speed.
Bug: webrtc:13744 Change-Id: Ib6d62dcdf7346d886c0aca09735c7d5c1f3e2455 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/252340 Reviewed-by: Erik Språng <sprang@webrtc.org> Auto-Submit: Michael Horowitz <mhoro@google.com> Commit-Queue: Michael Horowitz <mhoro@google.com> Cr-Commit-Position: refs/heads/main@{#36125}
This commit is contained in:
@ -49,21 +49,6 @@ constexpr int kLagInFrames = 0; // No look ahead.
|
||||
constexpr int kRtpTicksPerSecond = 90000;
|
||||
constexpr float kMinimumFrameRate = 1.0;
|
||||
|
||||
// Only positive speeds, range for real-time coding currently is: 6 - 8.
|
||||
// Lower means slower/better quality, higher means fastest/lower quality.
|
||||
int GetCpuSpeed(int width, int height, int number_of_cores) {
|
||||
// For smaller resolutions, use lower speed setting (get some coding gain at
|
||||
// the cost of increased encoding complexity).
|
||||
if (number_of_cores > 4 && width * height < 320 * 180)
|
||||
return 6;
|
||||
else if (width * height >= 1280 * 720)
|
||||
return 9;
|
||||
else if (width * height >= 640 * 360)
|
||||
return 8;
|
||||
else
|
||||
return 7;
|
||||
}
|
||||
|
||||
aom_superblock_size_t GetSuperblockSize(int width, int height, int threads) {
|
||||
int resolution = width * height;
|
||||
if (threads >= 4 && resolution >= 960 * 540 && resolution < 1920 * 1080)
|
||||
@ -93,6 +78,9 @@ class LibaomAv1Encoder final : public VideoEncoder {
|
||||
EncoderInfo GetEncoderInfo() const override;
|
||||
|
||||
private:
|
||||
// Get value to be used for encoder cpu_speed setting
|
||||
int GetCpuSpeed(int width, int height);
|
||||
|
||||
// Determine number of encoder threads to use.
|
||||
int NumberOfThreads(int width, int height, int number_of_cores);
|
||||
|
||||
@ -247,9 +235,8 @@ int LibaomAv1Encoder::InitEncode(const VideoCodec* codec_settings,
|
||||
inited_ = true;
|
||||
|
||||
// Set control parameters
|
||||
ret = aom_codec_control(
|
||||
&ctx_, AOME_SET_CPUUSED,
|
||||
GetCpuSpeed(cfg_.g_w, cfg_.g_h, settings.number_of_cores));
|
||||
ret = aom_codec_control(&ctx_, AOME_SET_CPUUSED,
|
||||
GetCpuSpeed(cfg_.g_w, cfg_.g_h));
|
||||
if (ret != AOM_CODEC_OK) {
|
||||
RTC_LOG(LS_WARNING) << "LibaomAv1Encoder::EncodeInit returned " << ret
|
||||
<< " on control AV1E_SET_CPUUSED.";
|
||||
@ -419,6 +406,42 @@ int LibaomAv1Encoder::InitEncode(const VideoCodec* codec_settings,
|
||||
return WEBRTC_VIDEO_CODEC_OK;
|
||||
}
|
||||
|
||||
// Only positive speeds, range for real-time coding currently is: 6 - 8.
|
||||
// Lower means slower/better quality, higher means fastest/lower quality.
|
||||
int LibaomAv1Encoder::GetCpuSpeed(int width, int height) {
|
||||
// For smaller resolutions, use lower speed setting (get some coding gain at
|
||||
// the cost of increased encoding complexity).
|
||||
switch (encoder_settings_.GetVideoEncoderComplexity()) {
|
||||
case VideoCodecComplexity::kComplexityHigh:
|
||||
if (width * height <= 320 * 180)
|
||||
return 8;
|
||||
else if (width * height <= 640 * 360)
|
||||
return 9;
|
||||
else
|
||||
return 10;
|
||||
case VideoCodecComplexity::kComplexityHigher:
|
||||
if (width * height <= 320 * 180)
|
||||
return 7;
|
||||
else if (width * height <= 640 * 360)
|
||||
return 8;
|
||||
else if (width * height <= 1280 * 720)
|
||||
return 9;
|
||||
else
|
||||
return 10;
|
||||
case VideoCodecComplexity::kComplexityMax:
|
||||
if (width * height <= 320 * 180)
|
||||
return 6;
|
||||
else if (width * height <= 640 * 360)
|
||||
return 7;
|
||||
else if (width * height <= 1280 * 720)
|
||||
return 8;
|
||||
else
|
||||
return 9;
|
||||
default:
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
|
||||
int LibaomAv1Encoder::NumberOfThreads(int width,
|
||||
int height,
|
||||
int number_of_cores) {
|
||||
|
||||
@ -61,7 +61,7 @@ TEST_P(VideoCodecTestAv1, HighBitrate) {
|
||||
std::vector<RateControlThresholds> rc_thresholds = {
|
||||
{12, 1, 0, 1, 0.3, 0.1, 0, 1}};
|
||||
|
||||
std::vector<QualityThresholds> quality_thresholds = {{37, 34, 0.94, 0.915}};
|
||||
std::vector<QualityThresholds> quality_thresholds = {{37, 34, 0.94, 0.91}};
|
||||
|
||||
fixture->RunTest(rate_profiles, &rc_thresholds, &quality_thresholds, nullptr);
|
||||
}
|
||||
@ -78,7 +78,7 @@ TEST_P(VideoCodecTestAv1, VeryLowBitrate) {
|
||||
std::vector<RateControlThresholds> rc_thresholds = {
|
||||
{15, 8, 75, 2, 2, 2, 2, 1}};
|
||||
|
||||
std::vector<QualityThresholds> quality_thresholds = {{28, 25, 0.70, 0.60}};
|
||||
std::vector<QualityThresholds> quality_thresholds = {{28, 24.9, 0.70, 0.55}};
|
||||
|
||||
fixture->RunTest(rate_profiles, &rc_thresholds, &quality_thresholds, nullptr);
|
||||
}
|
||||
@ -99,7 +99,8 @@ TEST_P(VideoCodecTestAv1, Hd) {
|
||||
std::vector<RateControlThresholds> rc_thresholds = {
|
||||
{13, 3, 0, 1, 0.3, 0.1, 0, 1}};
|
||||
|
||||
std::vector<QualityThresholds> quality_thresholds = {{36, 31.6, 0.93, 0.87}};
|
||||
std::vector<QualityThresholds> quality_thresholds = {
|
||||
{36, 31.55, 0.925, 0.865}};
|
||||
|
||||
fixture->RunTest(rate_profiles, &rc_thresholds, &quality_thresholds, nullptr);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user