@@ -765,6 +765,18 @@ namespace video {
765
765
{" usage" s, &config::video.amd .amd_usage_hevc },
766
766
{" vbaq" s, &config::video.amd .amd_vbaq },
767
767
{" 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
+ }},
768
780
},
769
781
{}, // SDR-specific options
770
782
{}, // HDR-specific options
@@ -1639,7 +1651,7 @@ namespace video {
1639
1651
ctx->thread_count = ctx->slices ;
1640
1652
1641
1653
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) {
1643
1655
std::visit (
1644
1656
util::overloaded {
1645
1657
[&](int v) {
@@ -1653,7 +1665,7 @@ namespace video {
1653
1665
av_dict_set_int (&options, option.name .c_str (), **v, 0 );
1654
1666
}
1655
1667
},
1656
- [&](std::function<int ()> v) {
1668
+ [&](const std::function<int ()>& v) {
1657
1669
av_dict_set_int (&options, option.name .c_str (), v (), 0 );
1658
1670
},
1659
1671
[&](const std::string &v) {
@@ -1663,6 +1675,9 @@ namespace video {
1663
1675
if (!v->empty ()) {
1664
1676
av_dict_set (&options, option.name .c_str (), v->c_str (), 0 );
1665
1677
}
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 );
1666
1681
}
1667
1682
},
1668
1683
option.value
0 commit comments