mirror of
https://github.com/k4yt3x/video2x.git
synced 2025-01-29 22:18:12 +00:00
style: added platform-dependent type aliases for char and string
Signed-off-by: k4yt3x <i@k4yt3x.com>
This commit is contained in:
parent
851f13bd4d
commit
1d1792d10f
22
include/libvideo2x/char_defs.h
Normal file
22
include/libvideo2x/char_defs.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef CHAR_DEFS_H
|
||||
#define CHAR_DEFS_H
|
||||
|
||||
#ifdef _WIN32
|
||||
typedef wchar_t CharType;
|
||||
#define STR(x) L##x
|
||||
#else
|
||||
typedef char CharType;
|
||||
#define STR(x) x
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <string>
|
||||
|
||||
#ifdef _WIN32
|
||||
typedef std::wstring StringType;
|
||||
#else
|
||||
typedef std::string StringType;
|
||||
#endif
|
||||
|
||||
#endif // __cplusplus
|
||||
#endif // CHAR_DEFS_H
|
@ -2,11 +2,18 @@
|
||||
#define FSUTILS_H
|
||||
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
|
||||
#include "char_defs.h"
|
||||
|
||||
bool filepath_is_readable(const std::filesystem::path &path);
|
||||
|
||||
std::filesystem::path find_resource_file(const std::filesystem::path &path);
|
||||
|
||||
std::string path_to_string(const std::filesystem::path& path);
|
||||
std::string path_to_u8string(const std::filesystem::path &path);
|
||||
|
||||
StringType path_to_string_type(const std::filesystem::path &path);
|
||||
|
||||
StringType to_string_type(int value);
|
||||
|
||||
#endif // FSUTILS_H
|
||||
|
@ -5,6 +5,17 @@
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include <libavcodec/avcodec.h>
|
||||
#include <libavformat/avformat.h>
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#include "char_defs.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifdef LIBVIDEO2X_EXPORTS
|
||||
#define LIBVIDEO2X_API __declspec(dllexport)
|
||||
@ -19,9 +30,6 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <libavcodec/avcodec.h>
|
||||
#include <libavformat/avformat.h>
|
||||
|
||||
// Enum to specify filter type
|
||||
enum FilterType {
|
||||
FILTER_LIBPLACEBO,
|
||||
@ -43,11 +51,7 @@ enum Libvideo2xLogLevel {
|
||||
struct LibplaceboConfig {
|
||||
int out_width;
|
||||
int out_height;
|
||||
#ifdef _WIN32
|
||||
const wchar_t *shader_path;
|
||||
#else
|
||||
const char *shader_path;
|
||||
#endif
|
||||
const CharType *shader_path;
|
||||
};
|
||||
|
||||
// Configuration for RealESRGAN filter
|
||||
@ -55,11 +59,7 @@ struct RealESRGANConfig {
|
||||
int gpuid;
|
||||
bool tta_mode;
|
||||
int scaling_factor;
|
||||
#ifdef _WIN32
|
||||
const wchar_t *model_name;
|
||||
#else
|
||||
const char *model_name;
|
||||
#endif
|
||||
const CharType *model_name;
|
||||
};
|
||||
|
||||
// Unified filter configuration
|
||||
@ -93,15 +93,22 @@ struct VideoProcessingContext {
|
||||
bool completed;
|
||||
};
|
||||
|
||||
// C-compatible process_video function
|
||||
/**
|
||||
* @brief Process a video file using the selected filter and encoder settings.
|
||||
*
|
||||
* @param[in] in_fname Path to the input video file
|
||||
* @param[in] out_fname Path to the output video file
|
||||
* @param[in] log_level Log level
|
||||
* @param[in] benchmark Flag to enable benchmarking mode
|
||||
* @param[in] hw_type Hardware device type
|
||||
* @param[in] filter_config Filter configurations
|
||||
* @param[in] encoder_config Encoder configurations
|
||||
* @param[in,out] proc_ctx Video processing context
|
||||
* @return int 0 on success, non-zero value on error
|
||||
*/
|
||||
LIBVIDEO2X_API int process_video(
|
||||
#ifdef _WIN32
|
||||
const wchar_t *in_fname,
|
||||
const wchar_t *out_fname,
|
||||
#else
|
||||
const char *in_fname,
|
||||
const char *out_fname,
|
||||
#endif
|
||||
const CharType *in_fname,
|
||||
const CharType *out_fname,
|
||||
enum Libvideo2xLogLevel log_level,
|
||||
bool benchmark,
|
||||
enum AVHWDeviceType hw_device_type,
|
||||
|
@ -5,6 +5,7 @@ extern "C" {
|
||||
#include <libavcodec/avcodec.h>
|
||||
}
|
||||
|
||||
#include "char_defs.h"
|
||||
#include "filter.h"
|
||||
#include "realesrgan.h"
|
||||
|
||||
@ -15,11 +16,7 @@ class RealesrganFilter : public Filter {
|
||||
int gpuid;
|
||||
bool tta_mode;
|
||||
int scaling_factor;
|
||||
#ifdef _WIN32
|
||||
const std::wstring model_name;
|
||||
#else
|
||||
const std::string model_name;
|
||||
#endif
|
||||
const StringType model_name;
|
||||
AVRational in_time_base;
|
||||
AVRational out_time_base;
|
||||
AVPixelFormat out_pix_fmt;
|
||||
@ -30,11 +27,7 @@ class RealesrganFilter : public Filter {
|
||||
int gpuid = 0,
|
||||
bool tta_mode = false,
|
||||
int scaling_factor = 4,
|
||||
#ifdef _WIN32
|
||||
const std::wstring model_name = L"realesr-animevideov3"
|
||||
#else
|
||||
const std::string model_name = "realesr-animevideov3"
|
||||
#endif
|
||||
const StringType model_name = STR("realesr-animevideov3")
|
||||
);
|
||||
|
||||
// Destructor
|
||||
|
@ -75,7 +75,7 @@ std::filesystem::path find_resource_file(const std::filesystem::path &path) {
|
||||
return get_executable_directory() / path;
|
||||
}
|
||||
|
||||
std::string path_to_string(const std::filesystem::path &path) {
|
||||
std::string path_to_u8string(const std::filesystem::path &path) {
|
||||
#if _WIN32
|
||||
std::wstring wide_path = path.wstring();
|
||||
int buffer_size =
|
||||
@ -92,3 +92,19 @@ std::string path_to_string(const std::filesystem::path &path) {
|
||||
return path.string();
|
||||
#endif
|
||||
}
|
||||
|
||||
StringType path_to_string_type(const std::filesystem::path &path) {
|
||||
#if _WIN32
|
||||
return path.wstring();
|
||||
#else
|
||||
return path.string();
|
||||
#endif
|
||||
}
|
||||
|
||||
StringType to_string_type(int value) {
|
||||
#if _WIN32
|
||||
return std::to_wstring(value);
|
||||
#else
|
||||
return std::to_string(value);
|
||||
#endif
|
||||
}
|
||||
|
@ -9,8 +9,6 @@ extern "C" {
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include "fsutils.h"
|
||||
|
||||
int init_libplacebo(
|
||||
AVBufferRef *hw_ctx,
|
||||
AVFilterGraph **filter_graph,
|
||||
@ -85,7 +83,7 @@ int init_libplacebo(
|
||||
}
|
||||
|
||||
// Convert the shader path to a string since filter args is const char *
|
||||
std::string shader_path_string = path_to_string(shader_path);
|
||||
std::string shader_path_string = shader_path.u8string();
|
||||
|
||||
#ifdef _WIN32
|
||||
// libplacebo does not recognize the Windows '\\' path separator
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include "char_defs.h"
|
||||
#include "fsutils.h"
|
||||
#include "libplacebo.h"
|
||||
|
||||
@ -43,17 +44,14 @@ int LibplaceboFilter::init(AVCodecContext *dec_ctx, AVCodecContext *enc_ctx, AVB
|
||||
} else {
|
||||
// Construct the fallback path using std::filesystem
|
||||
shader_full_path = find_resource_file(
|
||||
#ifdef _WIN32
|
||||
std::filesystem::path("models") / L"libplacebo" / (shader_path.wstring() + L".glsl")
|
||||
#else
|
||||
std::filesystem::path("models") / "libplacebo" / (shader_path.string() + ".glsl")
|
||||
#endif
|
||||
std::filesystem::path(STR("models")) / STR("libplacebo") /
|
||||
(path_to_string_type(shader_path) + STR(".glsl"))
|
||||
);
|
||||
}
|
||||
|
||||
// Check if the shader file exists
|
||||
if (!std::filesystem::exists(shader_full_path)) {
|
||||
spdlog::error("libplacebo shader file not found: '{}'", shader_path.string());
|
||||
spdlog::error("libplacebo shader file not found: '{}'", shader_path.u8string());
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -17,21 +17,7 @@ extern "C" {
|
||||
#include "libplacebo_filter.h"
|
||||
#include "realesrgan_filter.h"
|
||||
|
||||
/**
|
||||
* @brief Process frames using the selected filter.
|
||||
*
|
||||
* @param[in] encoder_config Encoder configurations
|
||||
* @param[in,out] proc_ctx Struct containing the processing context
|
||||
* @param[in] ifmt_ctx Input format context
|
||||
* @param[in] ofmt_ctx Output format context
|
||||
* @param[in] dec_ctx Decoder context
|
||||
* @param[in] enc_ctx Encoder context
|
||||
* @param[in] filter Filter instance
|
||||
* @param[in] vstream_idx Index of the video stream in the input format context
|
||||
* @param[in] stream_map Array mapping input stream indexes to output stream indexes
|
||||
* @param[in] benchmark Flag to enable benchmarking mode
|
||||
* @return int 0 on success, negative value on error
|
||||
*/
|
||||
// Process frames using the selected filter.
|
||||
static int process_frames(
|
||||
EncoderConfig *encoder_config,
|
||||
VideoProcessingContext *proc_ctx,
|
||||
@ -252,27 +238,9 @@ static int process_frames(
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Process a video file using the selected filter and encoder settings.
|
||||
*
|
||||
* @param[in] in_fname Path to the input video file
|
||||
* @param[in] out_fname Path to the output video file
|
||||
* @param[in] log_level Log level
|
||||
* @param[in] benchmark Flag to enable benchmarking mode
|
||||
* @param[in] hw_type Hardware device type
|
||||
* @param[in] filter_config Filter configurations
|
||||
* @param[in] encoder_config Encoder configurations
|
||||
* @param[in,out] proc_ctx Video processing context
|
||||
* @return int 0 on success, non-zero value on error
|
||||
*/
|
||||
extern "C" int process_video(
|
||||
#ifdef _WIN32
|
||||
const wchar_t *in_fname,
|
||||
const wchar_t *out_fname,
|
||||
#else
|
||||
const char *in_fname,
|
||||
const char *out_fname,
|
||||
#endif
|
||||
const CharType *in_fname,
|
||||
const CharType *out_fname,
|
||||
Libvideo2xLogLevel log_level,
|
||||
bool benchmark,
|
||||
AVHWDeviceType hw_type,
|
||||
|
@ -14,18 +14,13 @@ RealesrganFilter::RealesrganFilter(
|
||||
int gpuid,
|
||||
bool tta_mode,
|
||||
int scaling_factor,
|
||||
#ifdef _WIN32
|
||||
const std::wstring model_name
|
||||
#else
|
||||
const std::string model_name
|
||||
#endif
|
||||
const StringType model_name
|
||||
)
|
||||
: realesrgan(nullptr),
|
||||
gpuid(gpuid),
|
||||
tta_mode(tta_mode),
|
||||
scaling_factor(scaling_factor),
|
||||
model_name(std::move(model_name)) {
|
||||
}
|
||||
model_name(std::move(model_name)) {}
|
||||
|
||||
RealesrganFilter::~RealesrganFilter() {
|
||||
if (realesrgan) {
|
||||
@ -39,17 +34,14 @@ int RealesrganFilter::init(AVCodecContext *dec_ctx, AVCodecContext *enc_ctx, AVB
|
||||
std::filesystem::path model_param_path;
|
||||
std::filesystem::path model_bin_path;
|
||||
|
||||
#ifdef _WIN32
|
||||
std::wstring param_file_name = model_name + L"-x" + std::to_wstring(scaling_factor) + L".param";
|
||||
std::wstring bin_file_name = model_name + L"-x" + std::to_wstring(scaling_factor) + L".bin";
|
||||
#else
|
||||
std::string param_file_name = model_name + "-x" + std::to_string(scaling_factor) + ".param";
|
||||
std::string bin_file_name = model_name + "-x" + std::to_string(scaling_factor) + ".bin";
|
||||
#endif
|
||||
StringType param_file_name =
|
||||
model_name + STR("-x") + to_string_type(scaling_factor) + STR(".param");
|
||||
StringType bin_file_name =
|
||||
model_name + STR("-x") + to_string_type(scaling_factor) + STR(".bin");
|
||||
|
||||
// Find the model paths by model name if provided
|
||||
model_param_path = std::filesystem::path("models") / "realesrgan" / param_file_name;
|
||||
model_bin_path = std::filesystem::path("models") / "realesrgan" / bin_file_name;
|
||||
model_param_path = std::filesystem::path(STR("models")) / STR("realesrgan") / param_file_name;
|
||||
model_bin_path = std::filesystem::path(STR("models")) / STR("realesrgan") / bin_file_name;
|
||||
|
||||
// Get the full paths using a function that possibly modifies or validates the path
|
||||
std::filesystem::path model_param_full_path = find_resource_file(model_param_path);
|
||||
@ -57,11 +49,11 @@ int RealesrganFilter::init(AVCodecContext *dec_ctx, AVCodecContext *enc_ctx, AVB
|
||||
|
||||
// Check if the model files exist
|
||||
if (!std::filesystem::exists(model_param_full_path)) {
|
||||
spdlog::error("RealESRGAN model param file not found: {}", model_param_path.string());
|
||||
spdlog::error("RealESRGAN model param file not found: {}", model_param_path.u8string());
|
||||
return -1;
|
||||
}
|
||||
if (!std::filesystem::exists(model_bin_full_path)) {
|
||||
spdlog::error("RealESRGAN model bin file not found: {}", model_bin_path.string());
|
||||
spdlog::error("RealESRGAN model bin file not found: {}", model_bin_path.u8string());
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
221
src/video2x.cpp
221
src/video2x.cpp
@ -36,10 +36,14 @@ extern "C" {
|
||||
|
||||
#ifdef _WIN32
|
||||
#define BOOST_PROGRAM_OPTIONS_WCHAR_T
|
||||
#define PO_STR_VALUE po::wvalue
|
||||
#else
|
||||
#define PO_STR_VALUE po::value
|
||||
#endif
|
||||
#include <boost/program_options.hpp>
|
||||
namespace po = boost::program_options;
|
||||
|
||||
#include "libvideo2x/char_defs.h"
|
||||
#include "libvideo2x/timer.h"
|
||||
|
||||
// Indicate if a newline needs to be printed before the next output
|
||||
@ -48,31 +52,19 @@ std::atomic<bool> newline_required = false;
|
||||
// Structure to hold parsed arguments
|
||||
struct Arguments {
|
||||
// General options
|
||||
#ifdef _WIN32
|
||||
std::wstring loglevel = L"info";
|
||||
std::wstring filter_type;
|
||||
std::wstring hwaccel = L"none";
|
||||
#else
|
||||
std::string loglevel = "info";
|
||||
std::string filter_type;
|
||||
std::string hwaccel = "none";
|
||||
#endif
|
||||
bool noprogress = false;
|
||||
std::filesystem::path in_fname;
|
||||
std::filesystem::path out_fname;
|
||||
StringType filter_type;
|
||||
StringType hwaccel = STR("none");
|
||||
bool nocopystreams = false;
|
||||
bool benchmark = false;
|
||||
StringType loglevel = STR("info");
|
||||
bool noprogress = false;
|
||||
|
||||
// Encoder options
|
||||
#ifdef _WIN32
|
||||
std::wstring codec = L"libx264";
|
||||
std::wstring pix_fmt;
|
||||
std::wstring preset = L"slow";
|
||||
#else
|
||||
std::string codec = "libx264";
|
||||
std::string pix_fmt;
|
||||
std::string preset = "slow";
|
||||
#endif
|
||||
StringType codec = STR("libx264");
|
||||
StringType preset = STR("slow");
|
||||
StringType pix_fmt;
|
||||
int64_t bitrate = 0;
|
||||
float crf = 20.0f;
|
||||
|
||||
@ -82,12 +74,8 @@ struct Arguments {
|
||||
int out_height = 0;
|
||||
|
||||
// RealESRGAN options
|
||||
#ifdef _WIN32
|
||||
std::wstring model_name;
|
||||
#else
|
||||
std::string model_name;
|
||||
#endif
|
||||
int gpuid = 0;
|
||||
StringType model_name;
|
||||
int scaling_factor = 0;
|
||||
};
|
||||
|
||||
@ -145,27 +133,27 @@ void newline_safe_ffmpeg_log_callback(void *ptr, int level, const char *fmt, va_
|
||||
av_log_default_callback(ptr, level, fmt, vl);
|
||||
}
|
||||
|
||||
bool is_valid_realesrgan_model(const std::string &model) {
|
||||
static const std::unordered_set<std::string> valid_realesrgan_models = {
|
||||
"realesrgan-plus", "realesrgan-plus-anime", "realesr-animevideov3"
|
||||
bool is_valid_realesrgan_model(const StringType &model) {
|
||||
static const std::unordered_set<StringType> valid_realesrgan_models = {
|
||||
STR("realesrgan-plus"), STR("realesrgan-plus-anime"), STR("realesr-animevideov3")
|
||||
};
|
||||
return valid_realesrgan_models.count(model) > 0;
|
||||
}
|
||||
|
||||
enum Libvideo2xLogLevel parse_log_level(const std::string &level_name) {
|
||||
if (level_name == "trace") {
|
||||
enum Libvideo2xLogLevel parse_log_level(const StringType &level_name) {
|
||||
if (level_name == STR("trace")) {
|
||||
return LIBVIDEO2X_LOG_LEVEL_TRACE;
|
||||
} else if (level_name == "debug") {
|
||||
} else if (level_name == STR("debug")) {
|
||||
return LIBVIDEO2X_LOG_LEVEL_DEBUG;
|
||||
} else if (level_name == "info") {
|
||||
} else if (level_name == STR("info")) {
|
||||
return LIBVIDEO2X_LOG_LEVEL_INFO;
|
||||
} else if (level_name == "warning" || level_name == "warn") {
|
||||
} else if (level_name == STR("warning") || level_name == STR("warn")) {
|
||||
return LIBVIDEO2X_LOG_LEVEL_WARNING;
|
||||
} else if (level_name == "error") {
|
||||
} else if (level_name == STR("error")) {
|
||||
return LIBVIDEO2X_LOG_LEVEL_ERROR;
|
||||
} else if (level_name == "critical") {
|
||||
} else if (level_name == STR("critical")) {
|
||||
return LIBVIDEO2X_LOG_LEVEL_CRITICAL;
|
||||
} else if (level_name == "off" || level_name == "none") {
|
||||
} else if (level_name == STR("off") || level_name == STR("none")) {
|
||||
return LIBVIDEO2X_LOG_LEVEL_OFF;
|
||||
} else {
|
||||
spdlog::warn("Invalid log level specified. Defaulting to 'info'.");
|
||||
@ -185,16 +173,22 @@ void process_video_thread(
|
||||
EncoderConfig *encoder_config,
|
||||
VideoProcessingContext *proc_ctx
|
||||
) {
|
||||
enum Libvideo2xLogLevel log_level = parse_log_level(wstring_to_utf8(arguments->loglevel));
|
||||
enum Libvideo2xLogLevel log_level = parse_log_level(arguments->loglevel);
|
||||
|
||||
StringType in_fname_string;
|
||||
StringType out_fname_string;
|
||||
|
||||
#ifdef _WIN32
|
||||
const wchar_t *in_fname = arguments->in_fname.c_str();
|
||||
const wchar_t *out_fname = arguments->out_fname.c_str();
|
||||
in_fname_string = StringType(arguments->in_fname.wstring());
|
||||
out_fname_string = StringType(arguments->out_fname.wstring());
|
||||
#else
|
||||
const char *in_fname = arguments->in_fname.c_str();
|
||||
const char *out_fname = arguments->out_fname.c_str();
|
||||
in_fname_string = StringType(arguments->in_fname.string());
|
||||
out_fname_string = StringType(arguments->out_fname.string());
|
||||
#endif
|
||||
|
||||
const CharType *in_fname = in_fname_string.c_str();
|
||||
const CharType *out_fname = out_fname_string.c_str();
|
||||
|
||||
*proc_ret = process_video(
|
||||
in_fname,
|
||||
out_fname,
|
||||
@ -225,71 +219,37 @@ int main(int argc, char **argv) {
|
||||
try {
|
||||
po::options_description desc("Allowed options");
|
||||
|
||||
#ifdef _WIN32
|
||||
desc.add_options()
|
||||
("help", "Display this help page")
|
||||
("version,v", "Print program version")
|
||||
("loglevel", po::wvalue<std::wstring>(&arguments.loglevel), "Set log level (trace, debug, info, warn, error, critical, none)")
|
||||
("loglevel", PO_STR_VALUE<StringType>(&arguments.loglevel)->default_value(STR("info"), "info"), "Set log level (trace, debug, info, warn, error, critical, none)")
|
||||
("noprogress", po::bool_switch(&arguments.noprogress), "Do not display the progress bar")
|
||||
|
||||
// General Processing Options
|
||||
("input,i", po::wvalue<std::wstring>(), "Input video file path")
|
||||
("output,o", po::wvalue<std::wstring>(), "Output video file path")
|
||||
("filter,f", po::wvalue<std::wstring>(&arguments.filter_type), "Filter to use: 'libplacebo' or 'realesrgan'")
|
||||
("hwaccel,a", po::wvalue<std::wstring>(&arguments.hwaccel), "Hardware acceleration method (default: none)")
|
||||
("input,i", PO_STR_VALUE<StringType>(), "Input video file path")
|
||||
("output,o", PO_STR_VALUE<StringType>(), "Output video file path")
|
||||
("filter,f", PO_STR_VALUE<StringType>(&arguments.filter_type), "Filter to use: 'libplacebo' or 'realesrgan'")
|
||||
("hwaccel,a", PO_STR_VALUE<StringType>(&arguments.hwaccel)->default_value(STR("none"), "none"), "Hardware acceleration method (default: none)")
|
||||
("nocopystreams", po::bool_switch(&arguments.nocopystreams), "Do not copy audio and subtitle streams")
|
||||
("benchmark", po::bool_switch(&arguments.benchmark), "Discard processed frames and calculate average FPS")
|
||||
|
||||
// Encoder options
|
||||
("codec,c", po::wvalue<std::wstring>(&arguments.codec), "Output codec (default: libx264)")
|
||||
("preset,p", po::wvalue<std::wstring>(&arguments.preset), "Encoder preset (default: slow)")
|
||||
("pixfmt,x", po::wvalue<std::wstring>(&arguments.pix_fmt), "Output pixel format (default: auto)")
|
||||
("codec,c", PO_STR_VALUE<StringType>(&arguments.codec)->default_value(STR("libx264"), "libx264"), "Output codec (default: libx264)")
|
||||
("preset,p", PO_STR_VALUE<StringType>(&arguments.preset)->default_value(STR("slow"), "slow"), "Encoder preset (default: slow)")
|
||||
("pixfmt,x", PO_STR_VALUE<StringType>(&arguments.pix_fmt), "Output pixel format (default: auto)")
|
||||
("bitrate,b", po::value<int64_t>(&arguments.bitrate)->default_value(0), "Bitrate in bits per second (default: 0 (VBR))")
|
||||
("crf,q", po::value<float>(&arguments.crf)->default_value(20.0f), "Constant Rate Factor (default: 20.0)")
|
||||
|
||||
// libplacebo options
|
||||
("shader,s", po::wvalue<std::wstring>(), "Name or path of the GLSL shader file to use")
|
||||
("shader,s", PO_STR_VALUE<StringType>(), "Name or path of the GLSL shader file to use")
|
||||
("width,w", po::value<int>(&arguments.out_width), "Output width")
|
||||
("height,h", po::value<int>(&arguments.out_height), "Output height")
|
||||
|
||||
// RealESRGAN options
|
||||
("gpuid,g", po::value<int>(&arguments.gpuid)->default_value(0), "Vulkan GPU ID (default: 0)")
|
||||
("model,m", po::wvalue<std::wstring>(&arguments.model_name), "Name of the model to use")
|
||||
("model,m", PO_STR_VALUE<StringType>(&arguments.model_name), "Name of the model to use")
|
||||
("scale,r", po::value<int>(&arguments.scaling_factor), "Scaling factor (2, 3, or 4)")
|
||||
;
|
||||
#else
|
||||
desc.add_options()
|
||||
("help", "Display this help page")
|
||||
("version,v", "Print program version")
|
||||
("loglevel", po::value<std::string>(&arguments.loglevel)->default_value("info"), "Set log level (trace, debug, info, warn, error, critical, none)")
|
||||
("noprogress", po::bool_switch(&arguments.noprogress), "Do not display the progress bar")
|
||||
|
||||
// General Processing Options
|
||||
("input,i", po::value<std::string>(), "Input video file path")
|
||||
("output,o", po::value<std::string>(), "Output video file path")
|
||||
("filter,f", po::value<std::string>(&arguments.filter_type), "Filter to use: 'libplacebo' or 'realesrgan'")
|
||||
("hwaccel,a", po::value<std::string>(&arguments.hwaccel)->default_value("none"), "Hardware acceleration method (default: none)")
|
||||
("nocopystreams", po::bool_switch(&arguments.nocopystreams), "Do not copy audio and subtitle streams")
|
||||
("benchmark", po::bool_switch(&arguments.benchmark), "Discard processed frames and calculate average FPS")
|
||||
|
||||
// Encoder options
|
||||
("codec,c", po::value<std::string>(&arguments.codec)->default_value("libx264"), "Output codec (default: libx264)")
|
||||
("preset,p", po::value<std::string>(&arguments.preset)->default_value("slow"), "Encoder preset (default: slow)")
|
||||
("pixfmt,x", po::value<std::string>(&arguments.pix_fmt), "Output pixel format (default: auto)")
|
||||
("bitrate,b", po::value<int64_t>(&arguments.bitrate)->default_value(0), "Bitrate in bits per second (default: 0 (VBR))")
|
||||
("crf,q", po::value<float>(&arguments.crf)->default_value(20.0f), "Constant Rate Factor (default: 20.0)")
|
||||
|
||||
// libplacebo options
|
||||
("shader,s", po::value<std::string>(), "Name or path of the GLSL shader file to use (built-in: 'anime4k-a', 'anime4k-b', 'anime4k-c', 'anime4k-a+a', 'anime4k-b+b', 'anime4k-c+a')")
|
||||
("width,w", po::value<int>(&arguments.out_width), "Output width")
|
||||
("height,h", po::value<int>(&arguments.out_height), "Output height")
|
||||
|
||||
// RealESRGAN options
|
||||
("gpuid,g", po::value<int>(&arguments.gpuid)->default_value(0), "Vulkan GPU ID (default: 0)")
|
||||
("model,m", po::value<std::string>(&arguments.model_name), "Name of the model to use")
|
||||
("scale,r", po::value<int>(&arguments.scaling_factor), "Scaling factor (2, 3, or 4)")
|
||||
;
|
||||
#endif
|
||||
|
||||
// Positional arguments
|
||||
po::positional_options_description p;
|
||||
@ -304,22 +264,6 @@ int main(int argc, char **argv) {
|
||||
#endif
|
||||
po::notify(vm);
|
||||
|
||||
// Set default values for optional arguments
|
||||
#ifdef _WIN32
|
||||
if (!vm.count("loglevel")) {
|
||||
arguments.loglevel = L"info";
|
||||
}
|
||||
if (!vm.count("hwaccel")) {
|
||||
arguments.hwaccel = L"none";
|
||||
}
|
||||
if (!vm.count("codec")) {
|
||||
arguments.codec = L"libx264";
|
||||
}
|
||||
if (!vm.count("preset")) {
|
||||
arguments.preset = L"slow";
|
||||
}
|
||||
#endif
|
||||
|
||||
if (vm.count("help")) {
|
||||
std::cout << desc << std::endl;
|
||||
return 0;
|
||||
@ -332,22 +276,14 @@ int main(int argc, char **argv) {
|
||||
|
||||
// Assign positional arguments
|
||||
if (vm.count("input")) {
|
||||
#ifdef _WIN32
|
||||
arguments.in_fname = std::filesystem::path(vm["input"].as<std::wstring>());
|
||||
#else
|
||||
arguments.in_fname = std::filesystem::path(vm["input"].as<std::string>());
|
||||
#endif
|
||||
arguments.in_fname = std::filesystem::path(vm["input"].as<StringType>());
|
||||
} else {
|
||||
spdlog::error("Error: Input file path is required.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (vm.count("output")) {
|
||||
#ifdef _WIN32
|
||||
arguments.out_fname = std::filesystem::path(vm["output"].as<std::wstring>());
|
||||
#else
|
||||
arguments.out_fname = std::filesystem::path(vm["output"].as<std::string>());
|
||||
#endif
|
||||
arguments.out_fname = std::filesystem::path(vm["output"].as<StringType>());
|
||||
} else if (!arguments.benchmark) {
|
||||
spdlog::error("Error: Output file path is required.");
|
||||
return 1;
|
||||
@ -359,21 +295,11 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
if (vm.count("shader")) {
|
||||
#ifdef _WIN32
|
||||
arguments.shader_path = std::filesystem::path(vm["shader"].as<std::wstring>());
|
||||
#else
|
||||
arguments.shader_path = std::filesystem::path(vm["shader"].as<std::string>());
|
||||
#endif
|
||||
arguments.shader_path = std::filesystem::path(vm["shader"].as<StringType>());
|
||||
}
|
||||
|
||||
if (vm.count("model")) {
|
||||
#ifdef _WIN32
|
||||
bool is_valid_model =
|
||||
is_valid_realesrgan_model(wstring_to_utf8(vm["model"].as<std::wstring>()));
|
||||
#else
|
||||
bool is_valid_model = is_valid_realesrgan_model(vm["model"].as<std::string>());
|
||||
#endif
|
||||
if (!is_valid_model) {
|
||||
if (!is_valid_realesrgan_model(vm["model"].as<StringType>())) {
|
||||
spdlog::error(
|
||||
"Error: Invalid model specified. Must be 'realesrgan-plus', "
|
||||
"'realesrgan-plus-anime', or 'realesr-animevideov3'."
|
||||
@ -389,12 +315,8 @@ int main(int argc, char **argv) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Additional validations
|
||||
#ifdef _WIN32
|
||||
if (arguments.filter_type == L"libplacebo") {
|
||||
#else
|
||||
if (arguments.filter_type == "libplacebo") {
|
||||
#endif
|
||||
// Additional validations
|
||||
if (arguments.filter_type == STR("libplacebo")) {
|
||||
if (arguments.shader_path.empty() || arguments.out_width == 0 ||
|
||||
arguments.out_height == 0) {
|
||||
spdlog::error(
|
||||
@ -403,11 +325,7 @@ int main(int argc, char **argv) {
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
} else if (arguments.filter_type == L"realesrgan") {
|
||||
#else
|
||||
} else if (arguments.filter_type == "realesrgan") {
|
||||
#endif
|
||||
} else if (arguments.filter_type == STR("realesrgan")) {
|
||||
if (arguments.scaling_factor == 0 || arguments.model_name.empty()) {
|
||||
spdlog::error("Error: For realesrgan, scaling factor (-r) and model (-m) are required."
|
||||
);
|
||||
@ -454,7 +372,7 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
// Set spdlog log level
|
||||
auto log_level = parse_log_level(wstring_to_utf8(arguments.loglevel));
|
||||
auto log_level = parse_log_level(arguments.loglevel);
|
||||
switch (log_level) {
|
||||
case LIBVIDEO2X_LOG_LEVEL_TRACE:
|
||||
spdlog::set_level(spdlog::level::trace);
|
||||
@ -482,38 +400,27 @@ int main(int argc, char **argv) {
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
std::wstring shader_path_str = arguments.shader_path.wstring();
|
||||
#else
|
||||
std::string shader_path_str = arguments.shader_path.string();
|
||||
#endif
|
||||
|
||||
// Setup filter configurations based on the parsed arguments
|
||||
FilterConfig filter_config;
|
||||
#ifdef _WIN32
|
||||
if (arguments.filter_type == L"libplacebo") {
|
||||
#else
|
||||
if (arguments.filter_type == "libplacebo") {
|
||||
#endif
|
||||
if (arguments.filter_type == STR("libplacebo")) {
|
||||
filter_config.filter_type = FILTER_LIBPLACEBO;
|
||||
filter_config.config.libplacebo.out_width = arguments.out_width;
|
||||
filter_config.config.libplacebo.out_height = arguments.out_height;
|
||||
#ifdef _WIN32
|
||||
filter_config.config.libplacebo.shader_path = arguments.shader_path.c_str();
|
||||
#else
|
||||
filter_config.config.libplacebo.shader_path = arguments.shader_path.c_str();
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
} else if (arguments.filter_type == L"realesrgan") {
|
||||
#else
|
||||
} else if (arguments.filter_type == "realesrgan") {
|
||||
#endif
|
||||
filter_config.config.libplacebo.shader_path = shader_path_str.c_str();
|
||||
} else if (arguments.filter_type == STR("realesrgan")) {
|
||||
filter_config.filter_type = FILTER_REALESRGAN;
|
||||
filter_config.config.realesrgan.gpuid = arguments.gpuid;
|
||||
filter_config.config.realesrgan.tta_mode = false;
|
||||
filter_config.config.realesrgan.scaling_factor = arguments.scaling_factor;
|
||||
#ifdef _WIN32
|
||||
filter_config.config.realesrgan.model_name = arguments.model_name.c_str();
|
||||
#else
|
||||
filter_config.config.realesrgan.model_name = arguments.model_name.c_str();
|
||||
#endif
|
||||
}
|
||||
|
||||
// Convert arguments to UTF-8 encoded strings
|
||||
std::string preset_str = wstring_to_utf8(arguments.preset);
|
||||
|
||||
// Setup encoder configuration
|
||||
@ -529,11 +436,7 @@ int main(int argc, char **argv) {
|
||||
|
||||
// Parse hardware acceleration method
|
||||
enum AVHWDeviceType hw_device_type = AV_HWDEVICE_TYPE_NONE;
|
||||
#ifdef _WIN32
|
||||
if (arguments.hwaccel != L"none") {
|
||||
#else
|
||||
if (arguments.hwaccel != "none") {
|
||||
#endif
|
||||
if (arguments.hwaccel != STR("none")) {
|
||||
hw_device_type = av_hwdevice_find_type_by_name(wstring_to_utf8(arguments.hwaccel).c_str());
|
||||
if (hw_device_type == AV_HWDEVICE_TYPE_NONE) {
|
||||
spdlog::error(
|
||||
|
Loading…
Reference in New Issue
Block a user