mirror of
https://github.com/k4yt3x/video2x.git
synced 2026-02-04 03:22:07 +08:00
feat(libvideo2x): use OpenCV to retrieve total frame count (#1194)
This commit is contained in:
@@ -9,10 +9,10 @@ extern "C" {
|
||||
int init_decoder(
|
||||
AVHWDeviceType hw_type,
|
||||
AVBufferRef *hw_ctx,
|
||||
const char *input_filename,
|
||||
const char *in_fname,
|
||||
AVFormatContext **fmt_ctx,
|
||||
AVCodecContext **dec_ctx,
|
||||
int *video_stream_index
|
||||
int *vstream_idx
|
||||
);
|
||||
|
||||
#endif // DECODER_H
|
||||
|
||||
@@ -11,21 +11,21 @@ extern "C" {
|
||||
|
||||
int init_encoder(
|
||||
AVBufferRef *hw_ctx,
|
||||
const char *output_filename,
|
||||
const char *out_fname,
|
||||
AVFormatContext *ifmt_ctx,
|
||||
AVFormatContext **ofmt_ctx,
|
||||
AVCodecContext **enc_ctx,
|
||||
AVCodecContext *dec_ctx,
|
||||
EncoderConfig *encoder_config,
|
||||
int video_stream_index,
|
||||
int **stream_mapping
|
||||
int vstream_idx,
|
||||
int **stream_map
|
||||
);
|
||||
|
||||
int encode_and_write_frame(
|
||||
AVFrame *frame,
|
||||
AVCodecContext *enc_ctx,
|
||||
AVFormatContext *ofmt_ctx,
|
||||
int video_stream_index
|
||||
int vstream_idx
|
||||
);
|
||||
|
||||
int flush_encoder(AVCodecContext *enc_ctx, AVFormatContext *ofmt_ctx);
|
||||
|
||||
@@ -12,10 +12,10 @@ extern "C" {
|
||||
// Abstract base class for filters
|
||||
class Filter {
|
||||
public:
|
||||
virtual ~Filter() {}
|
||||
virtual ~Filter() = default;
|
||||
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;
|
||||
virtual int process_frame(AVFrame *in_frame, AVFrame **out_frame) = 0;
|
||||
virtual int flush(std::vector<AVFrame *> &flushed_frames) { return 0; }
|
||||
};
|
||||
|
||||
#endif // FILTER_H
|
||||
|
||||
@@ -14,8 +14,8 @@ int init_libplacebo(
|
||||
AVFilterContext **buffersrc_ctx,
|
||||
AVFilterContext **buffersink_ctx,
|
||||
AVCodecContext *dec_ctx,
|
||||
int output_width,
|
||||
int output_height,
|
||||
int out_width,
|
||||
int out_height,
|
||||
const std::filesystem::path &shader_path
|
||||
);
|
||||
|
||||
|
||||
@@ -17,10 +17,11 @@ class LibplaceboFilter : public Filter {
|
||||
AVFilterGraph *filter_graph;
|
||||
AVFilterContext *buffersrc_ctx;
|
||||
AVFilterContext *buffersink_ctx;
|
||||
int output_width;
|
||||
int output_height;
|
||||
int out_width;
|
||||
int out_height;
|
||||
const std::filesystem::path shader_path;
|
||||
AVRational output_time_base;
|
||||
AVRational in_time_base;
|
||||
AVRational out_time_base;
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
@@ -33,10 +34,10 @@ class LibplaceboFilter : public Filter {
|
||||
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;
|
||||
int process_frame(AVFrame *in_frame, AVFrame **out_frame) override;
|
||||
|
||||
// Flushes any remaining frames
|
||||
int flush(std::vector<AVFrame *> &processed_frames) override;
|
||||
int flush(std::vector<AVFrame *> &flushed_frames) override;
|
||||
};
|
||||
|
||||
#endif // LIBPLACEBO_FILTER_H
|
||||
|
||||
@@ -41,8 +41,8 @@ enum Libvideo2xLogLevel {
|
||||
|
||||
// Configuration for Libplacebo filter
|
||||
struct LibplaceboConfig {
|
||||
int output_width;
|
||||
int output_height;
|
||||
int out_width;
|
||||
int out_height;
|
||||
const char *shader_path;
|
||||
};
|
||||
|
||||
@@ -65,8 +65,8 @@ struct FilterConfig {
|
||||
|
||||
// Encoder configuration
|
||||
struct EncoderConfig {
|
||||
int output_width;
|
||||
int output_height;
|
||||
int out_width;
|
||||
int out_height;
|
||||
bool copy_streams;
|
||||
enum AVCodecID codec;
|
||||
enum AVPixelFormat pix_fmt;
|
||||
@@ -87,8 +87,8 @@ struct VideoProcessingContext {
|
||||
|
||||
// C-compatible process_video function
|
||||
LIBVIDEO2X_API int process_video(
|
||||
const char *input_filename,
|
||||
const char *output_filename,
|
||||
const char *in_fname,
|
||||
const char *out_fname,
|
||||
enum Libvideo2xLogLevel log_level,
|
||||
bool benchmark,
|
||||
enum AVHWDeviceType hw_device_type,
|
||||
|
||||
@@ -20,9 +20,9 @@ class RealesrganFilter : public Filter {
|
||||
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;
|
||||
AVRational in_time_base;
|
||||
AVRational out_time_base;
|
||||
AVPixelFormat out_pix_fmt;
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
@@ -31,8 +31,8 @@ class RealesrganFilter : public Filter {
|
||||
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()
|
||||
const std::filesystem::path custom_model_param_path = std::filesystem::path(),
|
||||
const std::filesystem::path custom_model_bin_path = std::filesystem::path()
|
||||
);
|
||||
|
||||
// Destructor
|
||||
@@ -42,10 +42,7 @@ class RealesrganFilter : public Filter {
|
||||
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;
|
||||
int process_frame(AVFrame *in_frame, AVFrame **out_frame) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user