mirror of
https://github.com/k4yt3x/video2x.git
synced 2026-02-04 03:22:07 +08:00
feat(*): switched to spdlog for logging and organized headers (#1183)
* feat: updated PKGBUILD description * feat: updated workflow syntax and dependencies * feat: switched logging to spdlog * chore: adjusted library defaults * ci: fixed spdlog format string issues * docs: fixed docs for libvideo2x functions * feat: organized header files * fix: fixed header installation directory * feat: link spdlog statically if compiled from source * feat: adjusted libvideo2x log level enum names * feat: added version.h header Signed-off-by: k4yt3x <i@k4yt3x.com>
This commit is contained in:
20
include/libvideo2x/conversions.h
Normal file
20
include/libvideo2x/conversions.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef CONVERSIONS_H
|
||||
#define CONVERSIONS_H
|
||||
|
||||
extern "C" {
|
||||
#include <libavutil/frame.h>
|
||||
#include <libswscale/swscale.h>
|
||||
}
|
||||
|
||||
#include <mat.h>
|
||||
|
||||
// Convert AVFrame to another pixel format
|
||||
AVFrame *convert_avframe_pix_fmt(AVFrame *src_frame, AVPixelFormat pix_fmt);
|
||||
|
||||
// Convert AVFrame to ncnn::Mat
|
||||
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
|
||||
18
include/libvideo2x/decoder.h
Normal file
18
include/libvideo2x/decoder.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef DECODER_H
|
||||
#define DECODER_H
|
||||
|
||||
extern "C" {
|
||||
#include <libavcodec/avcodec.h>
|
||||
#include <libavformat/avformat.h>
|
||||
}
|
||||
|
||||
int init_decoder(
|
||||
AVHWDeviceType hw_type,
|
||||
AVBufferRef *hw_ctx,
|
||||
const char *input_filename,
|
||||
AVFormatContext **fmt_ctx,
|
||||
AVCodecContext **dec_ctx,
|
||||
int *video_stream_index
|
||||
);
|
||||
|
||||
#endif // DECODER_H
|
||||
33
include/libvideo2x/encoder.h
Normal file
33
include/libvideo2x/encoder.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef ENCODER_H
|
||||
#define ENCODER_H
|
||||
|
||||
extern "C" {
|
||||
#include <libavcodec/avcodec.h>
|
||||
#include <libavformat/avformat.h>
|
||||
#include <libavutil/opt.h>
|
||||
}
|
||||
|
||||
#include "libvideo2x.h"
|
||||
|
||||
int init_encoder(
|
||||
AVBufferRef *hw_ctx,
|
||||
const char *output_filename,
|
||||
AVFormatContext *ifmt_ctx,
|
||||
AVFormatContext **ofmt_ctx,
|
||||
AVCodecContext **enc_ctx,
|
||||
AVCodecContext *dec_ctx,
|
||||
EncoderConfig *encoder_config,
|
||||
int video_stream_index,
|
||||
int **stream_mapping
|
||||
);
|
||||
|
||||
int encode_and_write_frame(
|
||||
AVFrame *frame,
|
||||
AVCodecContext *enc_ctx,
|
||||
AVFormatContext *ofmt_ctx,
|
||||
int video_stream_index
|
||||
);
|
||||
|
||||
int flush_encoder(AVCodecContext *enc_ctx, AVFormatContext *ofmt_ctx);
|
||||
|
||||
#endif // ENCODER_H
|
||||
21
include/libvideo2x/filter.h
Normal file
21
include/libvideo2x/filter.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef FILTER_H
|
||||
#define FILTER_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
extern "C" {
|
||||
#include <libavcodec/avcodec.h>
|
||||
#include <libavfilter/avfilter.h>
|
||||
#include <libavutil/buffer.h>
|
||||
}
|
||||
|
||||
// Abstract base class for filters
|
||||
class Filter {
|
||||
public:
|
||||
virtual ~Filter() {}
|
||||
virtual int init(AVCodecContext *dec_ctx, AVCodecContext *enc_ctx, AVBufferRef *hw_ctx) = 0;
|
||||
virtual int process_frame(AVFrame *input_frame, AVFrame **output_frame) = 0;
|
||||
virtual int flush(std::vector<AVFrame *> &processed_frames) = 0;
|
||||
};
|
||||
|
||||
#endif // FILTER_H
|
||||
12
include/libvideo2x/fsutils.h
Normal file
12
include/libvideo2x/fsutils.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef FSUTILS_H
|
||||
#define FSUTILS_H
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
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);
|
||||
|
||||
#endif // FSUTILS_H
|
||||
22
include/libvideo2x/libplacebo.h
Normal file
22
include/libvideo2x/libplacebo.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#ifndef PLACEBO_H
|
||||
#define PLACEBO_H
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
extern "C" {
|
||||
#include <libavcodec/avcodec.h>
|
||||
#include <libavfilter/avfilter.h>
|
||||
}
|
||||
|
||||
int init_libplacebo(
|
||||
AVBufferRef *hw_ctx,
|
||||
AVFilterGraph **filter_graph,
|
||||
AVFilterContext **buffersrc_ctx,
|
||||
AVFilterContext **buffersink_ctx,
|
||||
AVCodecContext *dec_ctx,
|
||||
int output_width,
|
||||
int output_height,
|
||||
const std::filesystem::path &shader_path
|
||||
);
|
||||
|
||||
#endif // PLACEBO_H
|
||||
42
include/libvideo2x/libplacebo_filter.h
Normal file
42
include/libvideo2x/libplacebo_filter.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#ifndef LIBPLACEBO_FILTER_H
|
||||
#define LIBPLACEBO_FILTER_H
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
extern "C" {
|
||||
#include <libavcodec/avcodec.h>
|
||||
#include <libavfilter/buffersink.h>
|
||||
#include <libavfilter/buffersrc.h>
|
||||
}
|
||||
|
||||
#include "filter.h"
|
||||
|
||||
// LibplaceboFilter class definition
|
||||
class LibplaceboFilter : public Filter {
|
||||
private:
|
||||
AVFilterGraph *filter_graph;
|
||||
AVFilterContext *buffersrc_ctx;
|
||||
AVFilterContext *buffersink_ctx;
|
||||
int output_width;
|
||||
int output_height;
|
||||
const std::filesystem::path shader_path;
|
||||
AVRational output_time_base;
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
LibplaceboFilter(int width, int height, const std::filesystem::path &shader_path);
|
||||
|
||||
// Destructor
|
||||
virtual ~LibplaceboFilter();
|
||||
|
||||
// Initializes the filter with decoder and encoder contexts
|
||||
int init(AVCodecContext *dec_ctx, AVCodecContext *enc_ctx, AVBufferRef *hw_ctx) override;
|
||||
|
||||
// Processes an input frame and returns the processed frame
|
||||
int process_frame(AVFrame *input_frame, AVFrame **output_frame) override;
|
||||
|
||||
// Flushes any remaining frames
|
||||
int flush(std::vector<AVFrame *> &processed_frames) override;
|
||||
};
|
||||
|
||||
#endif // LIBPLACEBO_FILTER_H
|
||||
104
include/libvideo2x/libvideo2x.h
Normal file
104
include/libvideo2x/libvideo2x.h
Normal file
@@ -0,0 +1,104 @@
|
||||
#ifndef LIBVIDEO2X_H
|
||||
#define LIBVIDEO2X_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifdef LIBVIDEO2X_EXPORTS
|
||||
#define LIBVIDEO2X_API __declspec(dllexport)
|
||||
#else
|
||||
#define LIBVIDEO2X_API __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define LIBVIDEO2X_API
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <libavcodec/avcodec.h>
|
||||
#include <libavformat/avformat.h>
|
||||
|
||||
// Enum to specify filter type
|
||||
enum FilterType {
|
||||
FILTER_LIBPLACEBO,
|
||||
FILTER_REALESRGAN
|
||||
};
|
||||
|
||||
// Enum to specify log level
|
||||
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
|
||||
};
|
||||
|
||||
// Configuration for Libplacebo filter
|
||||
struct LibplaceboConfig {
|
||||
int output_width;
|
||||
int output_height;
|
||||
const char *shader_path;
|
||||
};
|
||||
|
||||
// Configuration for RealESRGAN filter
|
||||
struct RealESRGANConfig {
|
||||
int gpuid;
|
||||
bool tta_mode;
|
||||
int scaling_factor;
|
||||
const char *model;
|
||||
};
|
||||
|
||||
// Unified filter configuration
|
||||
struct FilterConfig {
|
||||
enum FilterType filter_type;
|
||||
union {
|
||||
struct LibplaceboConfig libplacebo;
|
||||
struct RealESRGANConfig realesrgan;
|
||||
} config;
|
||||
};
|
||||
|
||||
// Encoder configuration
|
||||
struct EncoderConfig {
|
||||
int output_width;
|
||||
int output_height;
|
||||
bool copy_streams;
|
||||
enum AVCodecID codec;
|
||||
enum AVPixelFormat pix_fmt;
|
||||
const char *preset;
|
||||
int64_t bit_rate;
|
||||
float crf;
|
||||
};
|
||||
|
||||
// Video processing context
|
||||
struct VideoProcessingContext {
|
||||
int64_t processed_frames;
|
||||
int64_t total_frames;
|
||||
time_t start_time;
|
||||
bool pause;
|
||||
bool abort;
|
||||
bool completed;
|
||||
};
|
||||
|
||||
// C-compatible process_video function
|
||||
LIBVIDEO2X_API int process_video(
|
||||
const char *input_filename,
|
||||
const char *output_filename,
|
||||
enum Libvideo2xLogLevel log_level,
|
||||
bool benchmark,
|
||||
enum AVHWDeviceType hw_device_type,
|
||||
const struct FilterConfig *filter_config,
|
||||
struct EncoderConfig *encoder_config,
|
||||
struct VideoProcessingContext *proc_ctx
|
||||
);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // LIBVIDEO2X_H
|
||||
51
include/libvideo2x/realesrgan_filter.h
Normal file
51
include/libvideo2x/realesrgan_filter.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#ifndef REALSRGAN_FILTER_H
|
||||
#define REALSRGAN_FILTER_H
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
extern "C" {
|
||||
#include <libavcodec/avcodec.h>
|
||||
}
|
||||
|
||||
#include "filter.h"
|
||||
#include "realesrgan.h"
|
||||
|
||||
// RealesrganFilter class definition
|
||||
class RealesrganFilter : public Filter {
|
||||
private:
|
||||
RealESRGAN *realesrgan;
|
||||
int gpuid;
|
||||
bool tta_mode;
|
||||
int scaling_factor;
|
||||
const char *model;
|
||||
const std::filesystem::path custom_model_param_path;
|
||||
const std::filesystem::path custom_model_bin_path;
|
||||
AVRational input_time_base;
|
||||
AVRational output_time_base;
|
||||
AVPixelFormat output_pix_fmt;
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
RealesrganFilter(
|
||||
int gpuid = 0,
|
||||
bool tta_mode = false,
|
||||
int scaling_factor = 4,
|
||||
const char *model = "realesr-animevideov3",
|
||||
const std::filesystem::path custom_model_bin_pathmodel_param_path = std::filesystem::path(),
|
||||
const std::filesystem::path custom_model_bin_pathmodel_bin_path = std::filesystem::path()
|
||||
);
|
||||
|
||||
// Destructor
|
||||
virtual ~RealesrganFilter();
|
||||
|
||||
// Initializes the filter with decoder and encoder contexts
|
||||
int init(AVCodecContext *dec_ctx, AVCodecContext *enc_ctx, AVBufferRef *hw_ctx) override;
|
||||
|
||||
// Processes an input frame and returns the processed frame
|
||||
int process_frame(AVFrame *input_frame, AVFrame **output_frame) override;
|
||||
|
||||
// Flushes any remaining frames (if necessary)
|
||||
int flush(std::vector<AVFrame *> &processed_frames) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
6
include/libvideo2x/version.h.in
Normal file
6
include/libvideo2x/version.h.in
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef VERSION_H
|
||||
#define VERSION_H
|
||||
|
||||
#define LIBVIDEO2X_VERSION_STRING "@PROJECT_VERSION@"
|
||||
|
||||
#endif // VERSION_H
|
||||
Reference in New Issue
Block a user