mirror of
https://github.com/k4yt3x/video2x.git
synced 2026-05-20 02:47:31 +08:00
chore(libvideo2x)!: replace the C API with C++ API (#1245)
* chore(libvideo2x)!: replace the C API with C++ API * fix: convert wide string to u8 for av_opt_set * style: removed unnecessary enum and struct specifiers Signed-off-by: k4yt3x <i@k4yt3x.com>
This commit is contained in:
@@ -1,20 +1,17 @@
|
||||
#ifndef LIBVIDEO2X_H
|
||||
#define LIBVIDEO2X_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
#include <filesystem>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include <libavcodec/avcodec.h>
|
||||
#include <libavformat/avformat.h>
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#include "char_defs.h"
|
||||
#include "fsutils.h"
|
||||
#include "logging.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifdef LIBVIDEO2X_EXPORTS
|
||||
@@ -26,38 +23,24 @@ extern "C" {
|
||||
#define LIBVIDEO2X_API
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum ProcessingMode {
|
||||
PROCESSING_MODE_FILTER,
|
||||
PROCESSING_MODE_INTERPOLATE,
|
||||
enum class ProcessingMode {
|
||||
Filter,
|
||||
Interpolate,
|
||||
};
|
||||
|
||||
enum ProcessorType {
|
||||
PROCESSOR_LIBPLACEBO,
|
||||
PROCESSOR_REALESRGAN,
|
||||
PROCESSOR_RIFE,
|
||||
};
|
||||
|
||||
enum Libvideo2xLogLevel {
|
||||
LIBVIDEO2X_LOG_LEVEL_TRACE,
|
||||
LIBVIDEO2X_LOG_LEVEL_DEBUG,
|
||||
LIBVIDEO2X_LOG_LEVEL_INFO,
|
||||
LIBVIDEO2X_LOG_LEVEL_WARNING,
|
||||
LIBVIDEO2X_LOG_LEVEL_ERROR,
|
||||
LIBVIDEO2X_LOG_LEVEL_CRITICAL,
|
||||
LIBVIDEO2X_LOG_LEVEL_OFF
|
||||
enum class ProcessorType {
|
||||
Libplacebo,
|
||||
RealESRGAN,
|
||||
RIFE,
|
||||
};
|
||||
|
||||
struct LibplaceboConfig {
|
||||
const CharType *shader_path;
|
||||
StringType shader_path;
|
||||
};
|
||||
|
||||
struct RealESRGANConfig {
|
||||
bool tta_mode;
|
||||
const CharType *model_name;
|
||||
StringType model_name;
|
||||
};
|
||||
|
||||
struct RIFEConfig {
|
||||
@@ -65,34 +48,30 @@ struct RIFEConfig {
|
||||
bool tta_temporal_mode;
|
||||
bool uhd_mode;
|
||||
int num_threads;
|
||||
const CharType *model_name;
|
||||
StringType model_name;
|
||||
};
|
||||
|
||||
// Unified filter configuration
|
||||
struct ProcessorConfig {
|
||||
enum ProcessorType processor_type;
|
||||
ProcessorType processor_type;
|
||||
int width;
|
||||
int height;
|
||||
int scaling_factor;
|
||||
int frm_rate_mul;
|
||||
float scn_det_thresh;
|
||||
union {
|
||||
struct LibplaceboConfig libplacebo;
|
||||
struct RealESRGANConfig realesrgan;
|
||||
struct RIFEConfig rife;
|
||||
} config;
|
||||
std::variant<LibplaceboConfig, RealESRGANConfig, RIFEConfig> config;
|
||||
};
|
||||
|
||||
// Encoder configurations
|
||||
struct EncoderConfig {
|
||||
// Non-AVCodecContext options
|
||||
enum AVCodecID codec;
|
||||
AVCodecID codec;
|
||||
bool copy_streams;
|
||||
|
||||
// Basic video options
|
||||
int width;
|
||||
int height;
|
||||
enum AVPixelFormat pix_fmt;
|
||||
AVPixelFormat pix_fmt;
|
||||
|
||||
// Rate control and compression
|
||||
int64_t bit_rate;
|
||||
@@ -115,51 +94,34 @@ struct EncoderConfig {
|
||||
int delay;
|
||||
|
||||
// Extra AVOptions
|
||||
struct {
|
||||
const char *key;
|
||||
const char *value;
|
||||
} *extra_options;
|
||||
size_t nb_extra_options;
|
||||
std::vector<std::pair<StringType, StringType>> extra_opts;
|
||||
};
|
||||
|
||||
struct HardwareConfig {
|
||||
uint32_t vk_device_index;
|
||||
AVHWDeviceType hw_device_type;
|
||||
};
|
||||
|
||||
// Video processing context
|
||||
struct VideoProcessingContext {
|
||||
int64_t processed_frames;
|
||||
int64_t total_frames;
|
||||
time_t start_time;
|
||||
std::time_t start_time;
|
||||
bool pause;
|
||||
bool abort;
|
||||
bool completed;
|
||||
};
|
||||
|
||||
/**
|
||||
* @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] vk_device_index Vulkan device index
|
||||
* @param[in] hw_device_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(
|
||||
const CharType *in_fname,
|
||||
const CharType *out_fname,
|
||||
enum Libvideo2xLogLevel log_level,
|
||||
bool benchmark,
|
||||
uint32_t vk_device_index,
|
||||
enum AVHWDeviceType hw_device_type,
|
||||
const struct ProcessorConfig *filter_config,
|
||||
struct EncoderConfig *encoder_config,
|
||||
struct VideoProcessingContext *proc_ctx
|
||||
// Process a video file using the specified configurations
|
||||
[[nodiscard]] LIBVIDEO2X_API int process_video(
|
||||
const std::filesystem::path in_fname,
|
||||
const std::filesystem::path out_fname,
|
||||
const HardwareConfig hw_cfg,
|
||||
const ProcessorConfig proc_cfg,
|
||||
EncoderConfig enc_cfg,
|
||||
VideoProcessingContext *proc_ctx,
|
||||
Libvideo2xLogLevel log_level,
|
||||
bool benchmark
|
||||
);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // LIBVIDEO2X_H
|
||||
|
||||
Reference in New Issue
Block a user