mirror of
https://github.com/k4yt3x/video2x.git
synced 2026-02-04 03:22:07 +08:00
refactor(video2x): split the CLI into multiple files; improve CLI args validation (#1247)
Signed-off-by: k4yt3x <i@k4yt3x.com>
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
#ifndef AVUTILS_H
|
||||
#define AVUTILS_H
|
||||
#pragma once
|
||||
|
||||
extern "C" {
|
||||
#include <libavformat/avformat.h>
|
||||
@@ -18,5 +17,3 @@ void av_bufferref_deleter(AVBufferRef *bufferref);
|
||||
void av_frame_deleter(AVFrame *frame);
|
||||
|
||||
void av_packet_deleter(AVPacket *packet);
|
||||
|
||||
#endif // AVUTILS_H
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef CONVERSIONS_H
|
||||
#define CONVERSIONS_H
|
||||
#pragma once
|
||||
|
||||
extern "C" {
|
||||
#include <libavutil/frame.h>
|
||||
@@ -16,5 +15,3 @@ ncnn::Mat avframe_to_ncnn_mat(AVFrame *frame);
|
||||
|
||||
// Convert ncnn::Mat to AVFrame
|
||||
AVFrame *ncnn_mat_to_avframe(const ncnn::Mat &mat, AVPixelFormat pix_fmt);
|
||||
|
||||
#endif // CONVERSIONS_H
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef DECODER_H
|
||||
#define DECODER_H
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
@@ -27,5 +26,3 @@ class Decoder {
|
||||
AVCodecContext *dec_ctx_;
|
||||
int in_vstream_idx_;
|
||||
};
|
||||
|
||||
#endif // DECODER_H
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef ENCODER_H
|
||||
#define ENCODER_H
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
@@ -16,34 +15,32 @@ extern "C" {
|
||||
// Encoder configurations
|
||||
struct EncoderConfig {
|
||||
// Non-AVCodecContext options
|
||||
AVCodecID codec;
|
||||
bool copy_streams;
|
||||
AVCodecID codec = AV_CODEC_ID_NONE;
|
||||
bool copy_streams = true;
|
||||
|
||||
// Basic video options
|
||||
int width;
|
||||
int height;
|
||||
int frm_rate_mul;
|
||||
AVPixelFormat pix_fmt;
|
||||
int frm_rate_mul = 0;
|
||||
AVPixelFormat pix_fmt = AV_PIX_FMT_NONE;
|
||||
|
||||
// Rate control and compression
|
||||
int64_t bit_rate;
|
||||
int rc_buffer_size;
|
||||
int rc_min_rate;
|
||||
int rc_max_rate;
|
||||
int qmin;
|
||||
int qmax;
|
||||
int64_t bit_rate = 0;
|
||||
int rc_buffer_size = 0;
|
||||
int rc_min_rate = 0;
|
||||
int rc_max_rate = 0;
|
||||
int qmin = -1;
|
||||
int qmax = -1;
|
||||
|
||||
// GOP and frame structure
|
||||
int gop_size;
|
||||
int max_b_frames;
|
||||
int keyint_min;
|
||||
int refs;
|
||||
int gop_size = -1;
|
||||
int max_b_frames = -1;
|
||||
int keyint_min = -1;
|
||||
int refs = -1;
|
||||
|
||||
// Performance and threading
|
||||
int thread_count;
|
||||
int thread_count = 0;
|
||||
|
||||
// Latency and buffering
|
||||
int delay;
|
||||
int delay = -1;
|
||||
|
||||
// Extra AVOptions
|
||||
std::vector<std::pair<StringType, StringType>> extra_opts;
|
||||
@@ -60,6 +57,8 @@ class Encoder {
|
||||
AVFormatContext *ifmt_ctx,
|
||||
AVCodecContext *dec_ctx,
|
||||
EncoderConfig &enc_cfg,
|
||||
int width,
|
||||
int height,
|
||||
int in_vstream_idx
|
||||
);
|
||||
|
||||
@@ -77,5 +76,3 @@ class Encoder {
|
||||
int out_vstream_idx_;
|
||||
int *stream_map_;
|
||||
};
|
||||
|
||||
#endif // ENCODER_H
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef FILTER_LIBPLACEBO_H
|
||||
#define FILTER_LIBPLACEBO_H
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
@@ -57,5 +56,3 @@ class FilterLibplacebo : public Filter {
|
||||
AVRational in_time_base_;
|
||||
AVRational out_time_base_;
|
||||
};
|
||||
|
||||
#endif // FILTER_LIBPLACEBO_H
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef FILTER_REALESRGAN_H
|
||||
#define FILTER_REALESRGAN_H
|
||||
#pragma once
|
||||
|
||||
extern "C" {
|
||||
#include <libavcodec/avcodec.h>
|
||||
@@ -50,5 +49,3 @@ class FilterRealesrgan : public Filter {
|
||||
AVRational out_time_base_;
|
||||
AVPixelFormat out_pix_fmt_;
|
||||
};
|
||||
|
||||
#endif // FILTER_REALESRGAN_H
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef FSUTILS_H
|
||||
#define FSUTILS_H
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
@@ -29,5 +28,3 @@ std::string wstring_to_u8string(const StringType &wstr);
|
||||
StringType path_to_string_type(const std::filesystem::path &path);
|
||||
|
||||
StringType to_string_type(int value);
|
||||
|
||||
#endif // FSUTILS_H
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef INTERPOLATOR_RIFE_H
|
||||
#define INTERPOLATOR_RIFE_H
|
||||
#pragma once
|
||||
|
||||
extern "C" {
|
||||
#include <libavcodec/avcodec.h>
|
||||
@@ -55,5 +54,3 @@ class InterpolatorRIFE : public Interpolator {
|
||||
AVRational out_time_base_;
|
||||
AVPixelFormat out_pix_fmt_;
|
||||
};
|
||||
|
||||
#endif // INTERPOLATOR_RIFE_H
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef PLACEBO_H
|
||||
#define PLACEBO_H
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
@@ -18,5 +17,3 @@ int init_libplacebo(
|
||||
uint32_t vk_device_index,
|
||||
const std::filesystem::path &shader_path
|
||||
);
|
||||
|
||||
#endif // PLACEBO_H
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef LIBVIDEO2X_H
|
||||
#define LIBVIDEO2X_H
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
@@ -26,19 +25,15 @@ extern "C" {
|
||||
#define LIBVIDEO2X_API
|
||||
#endif
|
||||
|
||||
struct HardwareConfig {
|
||||
uint32_t vk_device_index;
|
||||
AVHWDeviceType hw_device_type;
|
||||
};
|
||||
|
||||
class LIBVIDEO2X_API VideoProcessor {
|
||||
public:
|
||||
VideoProcessor(
|
||||
const HardwareConfig hw_cfg,
|
||||
const ProcessorConfig proc_cfg,
|
||||
EncoderConfig enc_cfg,
|
||||
Video2xLogLevel = Video2xLogLevel::Info,
|
||||
bool benchmark = false
|
||||
const EncoderConfig enc_cfg,
|
||||
const uint32_t vk_device_index = 0,
|
||||
const AVHWDeviceType hw_device_type = AV_HWDEVICE_TYPE_NONE,
|
||||
const Video2xLogLevel = Video2xLogLevel::Info,
|
||||
const bool benchmark = false
|
||||
);
|
||||
|
||||
virtual ~VideoProcessor() = default;
|
||||
@@ -85,9 +80,10 @@ class LIBVIDEO2X_API VideoProcessor {
|
||||
AVFrame *proc_frame
|
||||
);
|
||||
|
||||
HardwareConfig hw_cfg_;
|
||||
ProcessorConfig proc_cfg_;
|
||||
EncoderConfig enc_cfg_;
|
||||
uint32_t vk_device_index_ = 0;
|
||||
AVHWDeviceType hw_device_type_ = AV_HWDEVICE_TYPE_NONE;
|
||||
bool benchmark_ = false;
|
||||
|
||||
std::atomic<int64_t> frame_index_ = 0;
|
||||
@@ -96,5 +92,3 @@ class LIBVIDEO2X_API VideoProcessor {
|
||||
std::atomic<bool> aborted_ = false;
|
||||
std::atomic<bool> completed_ = false;
|
||||
};
|
||||
|
||||
#endif // LIBVIDEO2X_H
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef LOGGING_H
|
||||
#define LOGGING_H
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
|
||||
@@ -19,5 +18,3 @@ enum class Video2xLogLevel {
|
||||
void set_log_level(Video2xLogLevel log_level);
|
||||
|
||||
std::optional<Video2xLogLevel> find_log_level_by_name(const StringType &log_level_name);
|
||||
|
||||
#endif // LOGGING_H
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef PROCESSOR_H
|
||||
#define PROCESSOR_H
|
||||
#pragma once
|
||||
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
@@ -18,6 +17,7 @@ enum class ProcessingMode {
|
||||
};
|
||||
|
||||
enum class ProcessorType {
|
||||
None,
|
||||
Libplacebo,
|
||||
RealESRGAN,
|
||||
RIFE,
|
||||
@@ -28,26 +28,26 @@ struct LibplaceboConfig {
|
||||
};
|
||||
|
||||
struct RealESRGANConfig {
|
||||
bool tta_mode;
|
||||
bool tta_mode = false;
|
||||
StringType model_name;
|
||||
};
|
||||
|
||||
struct RIFEConfig {
|
||||
bool tta_mode;
|
||||
bool tta_temporal_mode;
|
||||
bool uhd_mode;
|
||||
int num_threads;
|
||||
bool tta_mode = false;
|
||||
bool tta_temporal_mode = false;
|
||||
bool uhd_mode = false;
|
||||
int num_threads = 0;
|
||||
StringType model_name;
|
||||
};
|
||||
|
||||
// Unified filter configuration
|
||||
struct ProcessorConfig {
|
||||
ProcessorType processor_type;
|
||||
int width;
|
||||
int height;
|
||||
int scaling_factor;
|
||||
int frm_rate_mul;
|
||||
float scn_det_thresh;
|
||||
ProcessorType processor_type = ProcessorType::None;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
int scaling_factor = 0;
|
||||
int frm_rate_mul = 0;
|
||||
float scn_det_thresh = 0.0f;
|
||||
std::variant<LibplaceboConfig, RealESRGANConfig, RIFEConfig> config;
|
||||
};
|
||||
|
||||
@@ -81,5 +81,3 @@ class Interpolator : public Processor {
|
||||
virtual int
|
||||
interpolate(AVFrame *prev_frame, AVFrame *in_frame, AVFrame **out_frame, float time_step) = 0;
|
||||
};
|
||||
|
||||
#endif // PROCESSOR_H
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef PROCESSOR_FACTORY_H
|
||||
#define PROCESSOR_FACTORY_H
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
@@ -32,5 +31,3 @@ class ProcessorFactory {
|
||||
// Static initializer for default processors
|
||||
static void init_default_processors(ProcessorFactory &factory);
|
||||
};
|
||||
|
||||
#endif // PROCESSOR_FACTORY_H
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
#ifndef VERSION_H
|
||||
#define VERSION_H
|
||||
#pragma once
|
||||
|
||||
#define LIBVIDEO2X_VERSION_STRING "@PROJECT_VERSION@"
|
||||
|
||||
#endif // VERSION_H
|
||||
|
||||
Reference in New Issue
Block a user