From 01f281a4a379b04307ae85e8cacd8bfe6efce53e Mon Sep 17 00:00:00 2001 From: Mariotaku Date: Tue, 8 Jul 2025 03:53:40 +0900 Subject: [PATCH] fix(amf): attempt to use level 5.1/5.2 for hevc (#3888) --- src/video.cpp | 19 +++++++++++++++++-- src/video.h | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/video.cpp b/src/video.cpp index b4e3c147..ed263e21 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -765,6 +765,18 @@ namespace video { {"usage"s, &config::video.amd.amd_usage_hevc}, {"vbaq"s, &config::video.amd.amd_vbaq}, {"enforce_hrd"s, &config::video.amd.amd_enforce_hrd}, + {"level"s, [](const config_t &cfg) { + auto size = cfg.width * cfg.height; + // For 4K and below, try to use level 5.1 or 5.2 if possible + if (size <= 8912896) { + if (size * cfg.framerate <= 534773760) { + return "5.1"s; + } else if (size * cfg.framerate <= 1069547520) { + return "5.2"s; + } + } + return "auto"s; + }}, }, {}, // SDR-specific options {}, // HDR-specific options @@ -1639,7 +1651,7 @@ namespace video { ctx->thread_count = ctx->slices; AVDictionary *options {nullptr}; - auto handle_option = [&options](const encoder_t::option_t &option) { + auto handle_option = [&options, &config](const encoder_t::option_t &option) { std::visit( util::overloaded { [&](int v) { @@ -1653,7 +1665,7 @@ namespace video { av_dict_set_int(&options, option.name.c_str(), **v, 0); } }, - [&](std::function v) { + [&](const std::function &v) { av_dict_set_int(&options, option.name.c_str(), v(), 0); }, [&](const std::string &v) { @@ -1663,6 +1675,9 @@ namespace video { if (!v->empty()) { av_dict_set(&options, option.name.c_str(), v->c_str(), 0); } + }, + [&](const std::function &v) { + av_dict_set(&options, option.name.c_str(), v(config).c_str(), 0); } }, option.value diff --git a/src/video.h b/src/video.h index a363a2c2..a966c53e 100644 --- a/src/video.h +++ b/src/video.h @@ -150,7 +150,7 @@ namespace video { option_t(const option_t &) = default; std::string name; - std::variant *, std::function, std::string, std::string *> value; + std::variant *, std::function, std::string, std::string *, std::function> value; option_t(std::string &&name, decltype(value) &&value): name {std::move(name)},