Skip to content

Commit 6c9a2e4

Browse files
committed
attempt to use L5.1/5.2 for AMF HEVC encoder
1 parent 9c08c75 commit 6c9a2e4

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/video.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,18 @@ namespace video {
765765
{"usage"s, &config::video.amd.amd_usage_hevc},
766766
{"vbaq"s, &config::video.amd.amd_vbaq},
767767
{"enforce_hrd"s, &config::video.amd.amd_enforce_hrd},
768+
{"level"s, [](const config_t &cfg) {
769+
auto size = cfg.width * cfg.height;
770+
// For 4K and below, try to use level 5.1 or 5.2 if possible
771+
if (size <= 8912896) {
772+
if (size * cfg.framerate <= 534773760) {
773+
return "5.1"s;
774+
} else if (size * cfg.framerate <= 1069547520) {
775+
return "5.2"s;
776+
}
777+
}
778+
return "auto"s;
779+
}},
768780
},
769781
{}, // SDR-specific options
770782
{}, // HDR-specific options
@@ -1639,7 +1651,7 @@ namespace video {
16391651
ctx->thread_count = ctx->slices;
16401652

16411653
AVDictionary *options {nullptr};
1642-
auto handle_option = [&options](const encoder_t::option_t &option) {
1654+
auto handle_option = [&options, &config](const encoder_t::option_t &option) {
16431655
std::visit(
16441656
util::overloaded {
16451657
[&](int v) {
@@ -1653,7 +1665,7 @@ namespace video {
16531665
av_dict_set_int(&options, option.name.c_str(), **v, 0);
16541666
}
16551667
},
1656-
[&](std::function<int()> v) {
1668+
[&](const std::function<int()>& v) {
16571669
av_dict_set_int(&options, option.name.c_str(), v(), 0);
16581670
},
16591671
[&](const std::string &v) {
@@ -1663,6 +1675,9 @@ namespace video {
16631675
if (!v->empty()) {
16641676
av_dict_set(&options, option.name.c_str(), v->c_str(), 0);
16651677
}
1678+
},
1679+
[&](const std::function<const std::string(const config_t &cfg)>& v) {
1680+
av_dict_set(&options, option.name.c_str(), v(config).c_str(), 0);
16661681
}
16671682
},
16681683
option.value

src/video.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ namespace video {
150150
option_t(const option_t &) = default;
151151

152152
std::string name;
153-
std::variant<int, int *, std::optional<int> *, std::function<int()>, std::string, std::string *> value;
153+
std::variant<int, int *, std::optional<int> *, std::function<int()>, std::string, std::string *, std::function<const std::string(const config_t&)>> value;
154154

155155
option_t(std::string &&name, decltype(value) &&value):
156156
name {std::move(name)},

0 commit comments

Comments
 (0)