mirror of
https://github.com/k4yt3x/video2x.git
synced 2026-02-04 03:22:07 +08:00
feat(ns): improve optimization flags and add namespaces (#1261)
Signed-off-by: k4yt3x <i@k4yt3x.com>
This commit is contained in:
@@ -4,6 +4,9 @@ extern "C" {
|
||||
#include <libavformat/avformat.h>
|
||||
}
|
||||
|
||||
namespace video2x {
|
||||
namespace avutils {
|
||||
|
||||
AVRational get_video_frame_rate(AVFormatContext *ifmt_ctx, int in_vstream_idx);
|
||||
|
||||
int64_t get_video_frame_count(AVFormatContext *ifmt_ctx, int in_vstream_idx);
|
||||
@@ -17,3 +20,6 @@ void av_bufferref_deleter(AVBufferRef *bufferref);
|
||||
void av_frame_deleter(AVFrame *frame);
|
||||
|
||||
void av_packet_deleter(AVPacket *packet);
|
||||
|
||||
} // namespace avutils
|
||||
} // namespace video2x
|
||||
|
||||
@@ -7,6 +7,9 @@ extern "C" {
|
||||
|
||||
#include <mat.h>
|
||||
|
||||
namespace video2x {
|
||||
namespace conversions {
|
||||
|
||||
// Convert AVFrame to another pixel format
|
||||
AVFrame *convert_avframe_pix_fmt(AVFrame *src_frame, AVPixelFormat pix_fmt);
|
||||
|
||||
@@ -15,3 +18,6 @@ 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);
|
||||
|
||||
} // namespace conversions
|
||||
} // namespace video2x
|
||||
|
||||
@@ -7,6 +7,9 @@ extern "C" {
|
||||
#include <libavformat/avformat.h>
|
||||
}
|
||||
|
||||
namespace video2x {
|
||||
namespace decoder {
|
||||
|
||||
class Decoder {
|
||||
public:
|
||||
Decoder();
|
||||
@@ -26,3 +29,6 @@ class Decoder {
|
||||
AVCodecContext *dec_ctx_;
|
||||
int in_vstream_idx_;
|
||||
};
|
||||
|
||||
} // namespace decoder
|
||||
} // namespace video2x
|
||||
|
||||
@@ -12,6 +12,9 @@ extern "C" {
|
||||
|
||||
#include "fsutils.h"
|
||||
|
||||
namespace video2x {
|
||||
namespace encoder {
|
||||
|
||||
// Encoder configurations
|
||||
struct EncoderConfig {
|
||||
// Non-AVCodecContext options
|
||||
@@ -42,7 +45,7 @@ struct EncoderConfig {
|
||||
int delay = -1;
|
||||
|
||||
// Extra AVOptions
|
||||
std::vector<std::pair<StringType, StringType>> extra_opts;
|
||||
std::vector<std::pair<fsutils::StringType, fsutils::StringType>> extra_opts;
|
||||
};
|
||||
|
||||
class Encoder {
|
||||
@@ -76,3 +79,6 @@ class Encoder {
|
||||
int out_vstream_idx_;
|
||||
int *stream_map_;
|
||||
};
|
||||
|
||||
} // namespace encoder
|
||||
} // namespace video2x
|
||||
|
||||
@@ -10,6 +10,9 @@ extern "C" {
|
||||
|
||||
#include "processor.h"
|
||||
|
||||
namespace video2x {
|
||||
namespace processors {
|
||||
|
||||
// FilterLibplacebo class definition
|
||||
class FilterLibplacebo : public Filter {
|
||||
public:
|
||||
@@ -56,3 +59,6 @@ class FilterLibplacebo : public Filter {
|
||||
AVRational in_time_base_;
|
||||
AVRational out_time_base_;
|
||||
};
|
||||
|
||||
} // namespace processors
|
||||
} // namespace video2x
|
||||
|
||||
@@ -7,6 +7,9 @@ extern "C" {
|
||||
#include "processor.h"
|
||||
#include "realesrgan.h"
|
||||
|
||||
namespace video2x {
|
||||
namespace processors {
|
||||
|
||||
// FilterRealesrgan class definition
|
||||
class FilterRealesrgan : public Filter {
|
||||
public:
|
||||
@@ -15,7 +18,7 @@ class FilterRealesrgan : public Filter {
|
||||
int gpuid = 0,
|
||||
bool tta_mode = false,
|
||||
int scaling_factor = 4,
|
||||
const StringType model_name = STR("realesr-animevideov3")
|
||||
const fsutils::StringType model_name = STR("realesr-animevideov3")
|
||||
);
|
||||
|
||||
// Destructor
|
||||
@@ -44,8 +47,11 @@ class FilterRealesrgan : public Filter {
|
||||
int gpuid_;
|
||||
bool tta_mode_;
|
||||
int scaling_factor_;
|
||||
const StringType model_name_;
|
||||
const fsutils::StringType model_name_;
|
||||
AVRational in_time_base_;
|
||||
AVRational out_time_base_;
|
||||
AVPixelFormat out_pix_fmt_;
|
||||
};
|
||||
|
||||
} // namespace processors
|
||||
} // namespace video2x
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
|
||||
namespace video2x {
|
||||
namespace fsutils {
|
||||
|
||||
#ifdef _WIN32
|
||||
typedef wchar_t CharType;
|
||||
#define STR(x) L##x
|
||||
@@ -23,8 +26,11 @@ std::filesystem::path find_resource_file(const std::filesystem::path &path);
|
||||
|
||||
std::string path_to_u8string(const std::filesystem::path &path);
|
||||
|
||||
std::string wstring_to_u8string(const StringType &wstr);
|
||||
std::string wstring_to_u8string(const fsutils::StringType &wstr);
|
||||
|
||||
StringType path_to_string_type(const std::filesystem::path &path);
|
||||
fsutils::StringType path_to_string_type(const std::filesystem::path &path);
|
||||
|
||||
StringType to_string_type(int value);
|
||||
fsutils::StringType to_string_type(int value);
|
||||
|
||||
} // namespace fsutils
|
||||
} // namespace video2x
|
||||
|
||||
@@ -7,6 +7,9 @@ extern "C" {
|
||||
#include "processor.h"
|
||||
#include "rife.h"
|
||||
|
||||
namespace video2x {
|
||||
namespace processors {
|
||||
|
||||
// InterpolatorRIFE class definition
|
||||
class InterpolatorRIFE : public Interpolator {
|
||||
public:
|
||||
@@ -17,7 +20,7 @@ class InterpolatorRIFE : public Interpolator {
|
||||
bool tta_temporal_mode = false,
|
||||
bool uhd_mode = false,
|
||||
int num_threads = 1,
|
||||
const StringType model_name = STR("rife-v4.6")
|
||||
const fsutils::StringType model_name = STR("rife-v4.6")
|
||||
);
|
||||
|
||||
// Destructor
|
||||
@@ -49,8 +52,11 @@ class InterpolatorRIFE : public Interpolator {
|
||||
bool tta_temporal_mode_;
|
||||
bool uhd_mode_;
|
||||
int num_threads_;
|
||||
const StringType model_name_;
|
||||
const fsutils::StringType model_name_;
|
||||
AVRational in_time_base_;
|
||||
AVRational out_time_base_;
|
||||
AVPixelFormat out_pix_fmt_;
|
||||
};
|
||||
|
||||
} // namespace processors
|
||||
} // namespace video2x
|
||||
|
||||
@@ -7,6 +7,9 @@ extern "C" {
|
||||
#include <libavfilter/avfilter.h>
|
||||
}
|
||||
|
||||
namespace video2x {
|
||||
namespace processors {
|
||||
|
||||
int init_libplacebo(
|
||||
AVFilterGraph **filter_graph,
|
||||
AVFilterContext **buffersrc_ctx,
|
||||
@@ -17,3 +20,6 @@ int init_libplacebo(
|
||||
uint32_t vk_device_index,
|
||||
const std::filesystem::path &shader_path
|
||||
);
|
||||
|
||||
} // namespace processors
|
||||
} // namespace video2x
|
||||
|
||||
@@ -12,7 +12,7 @@ extern "C" {
|
||||
#include "avutils.h"
|
||||
#include "decoder.h"
|
||||
#include "encoder.h"
|
||||
#include "logging.h"
|
||||
#include "logutils.h"
|
||||
#include "processor.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
@@ -25,6 +25,8 @@ extern "C" {
|
||||
#define LIBVIDEO2X_API
|
||||
#endif
|
||||
|
||||
namespace video2x {
|
||||
|
||||
enum class VideoProcessorState {
|
||||
Idle,
|
||||
Running,
|
||||
@@ -37,11 +39,11 @@ enum class VideoProcessorState {
|
||||
class LIBVIDEO2X_API VideoProcessor {
|
||||
public:
|
||||
VideoProcessor(
|
||||
const ProcessorConfig proc_cfg,
|
||||
const EncoderConfig enc_cfg,
|
||||
const processors::ProcessorConfig proc_cfg,
|
||||
const encoder::EncoderConfig enc_cfg,
|
||||
const uint32_t vk_device_idx = 0,
|
||||
const AVHWDeviceType hw_device_type = AV_HWDEVICE_TYPE_NONE,
|
||||
const Video2xLogLevel = Video2xLogLevel::Info,
|
||||
const logutils::Video2xLogLevel = logutils::Video2xLogLevel::Info,
|
||||
const bool benchmark = false
|
||||
);
|
||||
|
||||
@@ -59,10 +61,13 @@ class LIBVIDEO2X_API VideoProcessor {
|
||||
int64_t get_total_frames() const { return total_frames_.load(); }
|
||||
|
||||
private:
|
||||
[[nodiscard]] int
|
||||
process_frames(Decoder &decoder, Encoder &encoder, std::unique_ptr<Processor> &processor);
|
||||
[[nodiscard]] int process_frames(
|
||||
decoder::Decoder &decoder,
|
||||
encoder::Encoder &encoder,
|
||||
std::unique_ptr<processors::Processor> &processor
|
||||
);
|
||||
|
||||
[[nodiscard]] int write_frame(AVFrame *frame, Encoder &encoder);
|
||||
[[nodiscard]] int write_frame(AVFrame *frame, encoder::Encoder &encoder);
|
||||
|
||||
[[nodiscard]] inline int write_raw_packet(
|
||||
AVPacket *packet,
|
||||
@@ -72,22 +77,22 @@ class LIBVIDEO2X_API VideoProcessor {
|
||||
);
|
||||
|
||||
[[nodiscard]] inline int process_filtering(
|
||||
std::unique_ptr<Processor> &processor,
|
||||
Encoder &encoder,
|
||||
std::unique_ptr<processors::Processor> &processor,
|
||||
encoder::Encoder &encoder,
|
||||
AVFrame *frame,
|
||||
AVFrame *proc_frame
|
||||
);
|
||||
|
||||
[[nodiscard]] inline int process_interpolation(
|
||||
std::unique_ptr<Processor> &processor,
|
||||
Encoder &encoder,
|
||||
std::unique_ptr<AVFrame, decltype(&av_frame_deleter)> &prev_frame,
|
||||
std::unique_ptr<processors::Processor> &processor,
|
||||
encoder::Encoder &encoder,
|
||||
std::unique_ptr<AVFrame, decltype(&avutils::av_frame_deleter)> &prev_frame,
|
||||
AVFrame *frame,
|
||||
AVFrame *proc_frame
|
||||
);
|
||||
|
||||
ProcessorConfig proc_cfg_;
|
||||
EncoderConfig enc_cfg_;
|
||||
processors::ProcessorConfig proc_cfg_;
|
||||
encoder::EncoderConfig enc_cfg_;
|
||||
uint32_t vk_device_idx_ = 0;
|
||||
AVHWDeviceType hw_device_type_ = AV_HWDEVICE_TYPE_NONE;
|
||||
bool benchmark_ = false;
|
||||
@@ -96,3 +101,5 @@ class LIBVIDEO2X_API VideoProcessor {
|
||||
std::atomic<int64_t> frame_idx_ = 0;
|
||||
std::atomic<int64_t> total_frames_ = 0;
|
||||
};
|
||||
|
||||
} // namespace video2x
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
|
||||
#include "fsutils.h"
|
||||
|
||||
namespace video2x {
|
||||
namespace logutils {
|
||||
|
||||
enum class Video2xLogLevel {
|
||||
Unknown,
|
||||
Trace,
|
||||
@@ -17,4 +20,9 @@ enum class Video2xLogLevel {
|
||||
|
||||
void set_log_level(Video2xLogLevel log_level);
|
||||
|
||||
std::optional<Video2xLogLevel> find_log_level_by_name(const StringType &log_level_name);
|
||||
std::optional<Video2xLogLevel> find_log_level_by_name(
|
||||
const fsutils::StringType &log_level_name
|
||||
);
|
||||
|
||||
} // namespace logutils
|
||||
} // namespace video2x
|
||||
@@ -11,6 +11,9 @@ extern "C" {
|
||||
|
||||
#include "fsutils.h"
|
||||
|
||||
namespace video2x {
|
||||
namespace processors {
|
||||
|
||||
enum class ProcessingMode {
|
||||
Filter,
|
||||
Interpolate,
|
||||
@@ -24,12 +27,12 @@ enum class ProcessorType {
|
||||
};
|
||||
|
||||
struct LibplaceboConfig {
|
||||
StringType shader_path;
|
||||
fsutils::StringType shader_path;
|
||||
};
|
||||
|
||||
struct RealESRGANConfig {
|
||||
bool tta_mode = false;
|
||||
StringType model_name;
|
||||
fsutils::StringType model_name;
|
||||
};
|
||||
|
||||
struct RIFEConfig {
|
||||
@@ -37,7 +40,7 @@ struct RIFEConfig {
|
||||
bool tta_temporal_mode = false;
|
||||
bool uhd_mode = false;
|
||||
int num_threads = 0;
|
||||
StringType model_name;
|
||||
fsutils::StringType model_name;
|
||||
};
|
||||
|
||||
// Unified filter configuration
|
||||
@@ -81,3 +84,6 @@ class Interpolator : public Processor {
|
||||
virtual int
|
||||
interpolate(AVFrame *prev_frame, AVFrame *in_frame, AVFrame **out_frame, float time_step) = 0;
|
||||
};
|
||||
|
||||
} // namespace processors
|
||||
} // namespace video2x
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
|
||||
#include "processor.h"
|
||||
|
||||
namespace video2x {
|
||||
namespace processors {
|
||||
|
||||
// Processor Factory Class
|
||||
class ProcessorFactory {
|
||||
public:
|
||||
@@ -31,3 +34,6 @@ class ProcessorFactory {
|
||||
// Static initializer for default processors
|
||||
static void init_default_processors(ProcessorFactory &factory);
|
||||
};
|
||||
|
||||
} // namespace processors
|
||||
} // namespace video2x
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
namespace video2x {
|
||||
|
||||
#define LIBVIDEO2X_VERSION_STRING "@PROJECT_VERSION@"
|
||||
|
||||
} // namespace video2x
|
||||
|
||||
Reference in New Issue
Block a user