fix(encoder): fix a bug that causes the wrong encoder to be selected
Some checks are pending
Build / ubuntu (push) Waiting to run
Build / windows (push) Waiting to run
Build / container (push) Waiting to run
Build / appimage (push) Waiting to run

Signed-off-by: k4yt3x <i@k4yt3x.com>
This commit is contained in:
k4yt3x 2025-01-20 00:00:00 +00:00
parent eae89cea4b
commit 947788225e
No known key found for this signature in database
4 changed files with 19 additions and 20 deletions

View File

@ -17,6 +17,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Improve the CMake optimization flags and option names.
### Fixed
- A bug that causes the wrong encoder to be selected.
## [6.3.1] - 2024-12-21
### Fixed

View File

@ -10,15 +10,13 @@ extern "C" {
#include <libavutil/pixdesc.h>
}
#include "fsutils.h"
namespace video2x {
namespace encoder {
// Encoder configurations
struct EncoderConfig {
// Non-AVCodecContext options
AVCodecID codec = AV_CODEC_ID_NONE;
std::string codec = "libx264";
bool copy_streams = true;
// Basic video options
@ -45,7 +43,7 @@ struct EncoderConfig {
int delay = -1;
// Extra AVOptions
std::vector<std::pair<fsutils::StringType, fsutils::StringType>> extra_opts;
std::vector<std::pair<std::string, std::string>> extra_opts;
};
class Encoder {

View File

@ -53,11 +53,9 @@ int Encoder::init(
}
// Find the encoder
const AVCodec* encoder = avcodec_find_encoder(enc_cfg.codec);
const AVCodec* encoder = avcodec_find_encoder_by_name(enc_cfg.codec.c_str());
if (!encoder) {
logger()->error(
"Required video encoder not found for codec {}", avcodec_get_name(enc_cfg.codec)
);
logger()->error("Could not find encoder '{}'", enc_cfg.codec);
return AVERROR_ENCODER_NOT_FOUND;
}
@ -151,8 +149,8 @@ int Encoder::init(
// Set extra AVOptions
for (const auto& [opt_name, opt_value] : enc_cfg.extra_opts) {
std::string opt_name_str = fsutils::wstring_to_u8string(opt_name);
std::string opt_value_str = fsutils::wstring_to_u8string(opt_value);
std::string opt_name_str = opt_name;
std::string opt_value_str = opt_value;
logger()->debug("Setting encoder option '{}' to '{}'", opt_name_str, opt_value_str);
ret = av_opt_set(enc_ctx_->priv_data, opt_name_str.c_str(), opt_value_str.c_str(), 0);

View File

@ -307,18 +307,15 @@ int parse_args(
}
// Parse codec to AVCodec
enc_cfg.codec = AV_CODEC_ID_H264;
enc_cfg.codec = "libx264";
if (vm.count("codec")) {
video2x::fsutils::StringType codec_str = vm["codec"].as<video2x::fsutils::StringType>();
const AVCodec* codec =
avcodec_find_encoder_by_name(wstring_to_u8string(codec_str).c_str());
if (codec == nullptr) {
video2x::logger()->critical(
"Codec '{}' not found.", wstring_to_u8string(codec_str)
);
std::string codec_str =
wstring_to_u8string(vm["codec"].as<video2x::fsutils::StringType>());
if (avcodec_find_encoder_by_name(codec_str.c_str()) == nullptr) {
video2x::logger()->critical("Invalid encoder '{}'.", codec_str);
return -1;
}
enc_cfg.codec = codec->id;
enc_cfg.codec = codec_str;
}
// Parse copy streams flag
@ -348,7 +345,9 @@ int parse_args(
if (eq_pos != video2x::fsutils::StringType::npos) {
video2x::fsutils::StringType key = opt.substr(0, eq_pos);
video2x::fsutils::StringType value = opt.substr(eq_pos + 1);
enc_cfg.extra_opts.push_back(std::make_pair(key, value));
enc_cfg.extra_opts.push_back(
std::make_pair(wstring_to_u8string(key), wstring_to_u8string(value))
);
} else {
video2x::logger()->critical(
"Invalid extra AVOption format: {}", wstring_to_u8string(opt)