ffmpeg: Fix print_av_option_string2 printing wrong names

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2021-10-17 11:03:33 +02:00
parent b122785bd1
commit 6a6929105a
1 changed files with 17 additions and 8 deletions

View File

@ -369,24 +369,33 @@ void tools::print_av_option_string2(AVCodecContext* ctx_codec, void* ctx_option,
std::string name = "<Unknown>"; std::string name = "<Unknown>";
// Find the unit for the option. // Find the unit for the option.
auto* unitopt = av_opt_find(ctx_option, option.data(), nullptr, 0, AV_OPT_SEARCH_CHILDREN); auto* opt = av_opt_find(ctx_option, option.data(), nullptr, 0, AV_OPT_SEARCH_CHILDREN);
if (unitopt && unitopt->unit) { if (opt && opt->unit) {
std::string_view optname; for (auto* opt_test = opt; (opt_test = av_opt_next(ctx_option, opt_test)) != nullptr;) {
for (auto* opt = unitopt; (opt = av_opt_next(ctx_option, opt)) != nullptr;) { // Skip this entry if the unit doesn't match.
if (opt->unit && (strcmp(unitopt->unit, opt->unit) != 0)) if ((opt_test->unit == nullptr) || (strcmp(opt_test->unit, opt->unit) != 0)) {
continue; continue;
}
if (opt->default_val.i64 == v) // Assign correct name if we found one.
optname = opt->name; if (opt_test->default_val.i64 == v) {
name = opt_test->name;
break;
}
} }
if (decoder) { if (decoder) {
name = decoder(v, optname); name = decoder(v, name);
} }
DLOG_INFO("[%s] %s: %s%s", ctx_codec->codec->name, text.data(), name.c_str(), DLOG_INFO("[%s] %s: %s%s", ctx_codec->codec->name, text.data(), name.c_str(),
av_opt_is_set_to_default_by_name(ctx_option, option.data(), AV_OPT_SEARCH_CHILDREN) > 0 av_opt_is_set_to_default_by_name(ctx_option, option.data(), AV_OPT_SEARCH_CHILDREN) > 0
? " <Default>" ? " <Default>"
: ""); : "");
} else {
DLOG_INFO("[%s] %s: %" PRId64 "%s", ctx_codec->codec->name, text.data(), v,
av_opt_is_set_to_default_by_name(ctx_option, option.data(), AV_OPT_SEARCH_CHILDREN) > 0
? " <Default>"
: "");
} }
} }
} }