mirror of
https://github.com/k4yt3x/video2x.git
synced 2025-01-28 21:38:41 +00:00
fix(encoder): fix a bug that causes the wrong encoder to be selected
Signed-off-by: k4yt3x <i@k4yt3x.com>
This commit is contained in:
parent
eae89cea4b
commit
947788225e
@ -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.
|
- 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
|
## [6.3.1] - 2024-12-21
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
@ -10,15 +10,13 @@ extern "C" {
|
|||||||
#include <libavutil/pixdesc.h>
|
#include <libavutil/pixdesc.h>
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "fsutils.h"
|
|
||||||
|
|
||||||
namespace video2x {
|
namespace video2x {
|
||||||
namespace encoder {
|
namespace encoder {
|
||||||
|
|
||||||
// Encoder configurations
|
// Encoder configurations
|
||||||
struct EncoderConfig {
|
struct EncoderConfig {
|
||||||
// Non-AVCodecContext options
|
// Non-AVCodecContext options
|
||||||
AVCodecID codec = AV_CODEC_ID_NONE;
|
std::string codec = "libx264";
|
||||||
bool copy_streams = true;
|
bool copy_streams = true;
|
||||||
|
|
||||||
// Basic video options
|
// Basic video options
|
||||||
@ -45,7 +43,7 @@ struct EncoderConfig {
|
|||||||
int delay = -1;
|
int delay = -1;
|
||||||
|
|
||||||
// Extra AVOptions
|
// Extra AVOptions
|
||||||
std::vector<std::pair<fsutils::StringType, fsutils::StringType>> extra_opts;
|
std::vector<std::pair<std::string, std::string>> extra_opts;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Encoder {
|
class Encoder {
|
||||||
|
@ -53,11 +53,9 @@ int Encoder::init(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Find the encoder
|
// 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) {
|
if (!encoder) {
|
||||||
logger()->error(
|
logger()->error("Could not find encoder '{}'", enc_cfg.codec);
|
||||||
"Required video encoder not found for codec {}", avcodec_get_name(enc_cfg.codec)
|
|
||||||
);
|
|
||||||
return AVERROR_ENCODER_NOT_FOUND;
|
return AVERROR_ENCODER_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,8 +149,8 @@ int Encoder::init(
|
|||||||
|
|
||||||
// Set extra AVOptions
|
// Set extra AVOptions
|
||||||
for (const auto& [opt_name, opt_value] : enc_cfg.extra_opts) {
|
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_name_str = opt_name;
|
||||||
std::string opt_value_str = fsutils::wstring_to_u8string(opt_value);
|
std::string opt_value_str = opt_value;
|
||||||
logger()->debug("Setting encoder option '{}' to '{}'", opt_name_str, opt_value_str);
|
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);
|
ret = av_opt_set(enc_ctx_->priv_data, opt_name_str.c_str(), opt_value_str.c_str(), 0);
|
||||||
|
@ -307,18 +307,15 @@ int parse_args(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse codec to AVCodec
|
// Parse codec to AVCodec
|
||||||
enc_cfg.codec = AV_CODEC_ID_H264;
|
enc_cfg.codec = "libx264";
|
||||||
if (vm.count("codec")) {
|
if (vm.count("codec")) {
|
||||||
video2x::fsutils::StringType codec_str = vm["codec"].as<video2x::fsutils::StringType>();
|
std::string codec_str =
|
||||||
const AVCodec* codec =
|
wstring_to_u8string(vm["codec"].as<video2x::fsutils::StringType>());
|
||||||
avcodec_find_encoder_by_name(wstring_to_u8string(codec_str).c_str());
|
if (avcodec_find_encoder_by_name(codec_str.c_str()) == nullptr) {
|
||||||
if (codec == nullptr) {
|
video2x::logger()->critical("Invalid encoder '{}'.", codec_str);
|
||||||
video2x::logger()->critical(
|
|
||||||
"Codec '{}' not found.", wstring_to_u8string(codec_str)
|
|
||||||
);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
enc_cfg.codec = codec->id;
|
enc_cfg.codec = codec_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse copy streams flag
|
// Parse copy streams flag
|
||||||
@ -348,7 +345,9 @@ int parse_args(
|
|||||||
if (eq_pos != video2x::fsutils::StringType::npos) {
|
if (eq_pos != video2x::fsutils::StringType::npos) {
|
||||||
video2x::fsutils::StringType key = opt.substr(0, eq_pos);
|
video2x::fsutils::StringType key = opt.substr(0, eq_pos);
|
||||||
video2x::fsutils::StringType value = opt.substr(eq_pos + 1);
|
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 {
|
} else {
|
||||||
video2x::logger()->critical(
|
video2x::logger()->critical(
|
||||||
"Invalid extra AVOption format: {}", wstring_to_u8string(opt)
|
"Invalid extra AVOption format: {}", wstring_to_u8string(opt)
|
||||||
|
Loading…
Reference in New Issue
Block a user