mirror of
https://github.com/k4yt3x/video2x.git
synced 2026-02-15 17:54:49 +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:
@@ -169,9 +169,8 @@ float get_frame_diff(AVFrame *frame1, AVFrame *frame2) {
|
||||
uint8_t *ptr1 = rgb_frame1->data[0] + y * rgb_frame1->linesize[0];
|
||||
uint8_t *ptr2 = rgb_frame2->data[0] + y * rgb_frame2->linesize[0];
|
||||
for (int x = 0; x < width * 3; x++) {
|
||||
sum_diff += static_cast<uint64_t>(
|
||||
std::abs(static_cast<int>(ptr1[x]) - static_cast<int>(ptr2[x]))
|
||||
);
|
||||
sum_diff +=
|
||||
static_cast<uint64_t>(ptr1[x] > ptr2[x] ? ptr1[x] - ptr2[x] : ptr2[x] - ptr1[x]);
|
||||
max_diff += 255;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,8 @@ int Encoder::init(
|
||||
AVFormatContext *ifmt_ctx,
|
||||
AVCodecContext *dec_ctx,
|
||||
EncoderConfig &enc_cfg,
|
||||
int width,
|
||||
int height,
|
||||
int in_vstream_idx
|
||||
) {
|
||||
int ret;
|
||||
@@ -84,8 +86,8 @@ int Encoder::init(
|
||||
enc_ctx_->sample_aspect_ratio = dec_ctx->sample_aspect_ratio;
|
||||
|
||||
// Set basic video options
|
||||
enc_ctx_->width = enc_cfg.width;
|
||||
enc_ctx_->height = enc_cfg.height;
|
||||
enc_ctx_->width = width;
|
||||
enc_ctx_->height = height;
|
||||
|
||||
// Set rate control and compression options
|
||||
enc_ctx_->bit_rate = enc_cfg.bit_rate;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "fsutils.h"
|
||||
|
||||
#if _WIN32
|
||||
#include <windows.h>
|
||||
#include <Windows.h>
|
||||
#include <cwchar>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -14,13 +14,18 @@ extern "C" {
|
||||
#include "processor_factory.h"
|
||||
|
||||
VideoProcessor::VideoProcessor(
|
||||
const HardwareConfig hw_cfg,
|
||||
const ProcessorConfig proc_cfg,
|
||||
const EncoderConfig enc_cfg,
|
||||
Video2xLogLevel log_level,
|
||||
bool benchmark
|
||||
const uint32_t vk_device_index,
|
||||
const AVHWDeviceType hw_device_type,
|
||||
const Video2xLogLevel log_level,
|
||||
const bool benchmark
|
||||
)
|
||||
: hw_cfg_(hw_cfg), proc_cfg_(proc_cfg), enc_cfg_(enc_cfg), benchmark_(benchmark) {
|
||||
: proc_cfg_(proc_cfg),
|
||||
enc_cfg_(enc_cfg),
|
||||
vk_device_index_(vk_device_index),
|
||||
hw_device_type_(hw_device_type),
|
||||
benchmark_(benchmark) {
|
||||
set_log_level(log_level);
|
||||
}
|
||||
|
||||
@@ -37,9 +42,9 @@ int VideoProcessor::process(
|
||||
);
|
||||
|
||||
// Initialize hardware device context
|
||||
if (hw_cfg_.hw_device_type != AV_HWDEVICE_TYPE_NONE) {
|
||||
if (hw_device_type_ != AV_HWDEVICE_TYPE_NONE) {
|
||||
AVBufferRef *tmp_hw_ctx = nullptr;
|
||||
ret = av_hwdevice_ctx_create(&tmp_hw_ctx, hw_cfg_.hw_device_type, NULL, NULL, 0);
|
||||
ret = av_hwdevice_ctx_create(&tmp_hw_ctx, hw_device_type_, NULL, NULL, 0);
|
||||
if (ret < 0) {
|
||||
av_strerror(ret, errbuf, sizeof(errbuf));
|
||||
spdlog::critical("Error initializing hardware device context: {}", errbuf);
|
||||
@@ -50,7 +55,7 @@ int VideoProcessor::process(
|
||||
|
||||
// Initialize input decoder
|
||||
Decoder decoder;
|
||||
ret = decoder.init(hw_cfg_.hw_device_type, hw_ctx.get(), in_fname);
|
||||
ret = decoder.init(hw_device_type_, hw_ctx.get(), in_fname);
|
||||
if (ret < 0) {
|
||||
av_strerror(ret, errbuf, sizeof(errbuf));
|
||||
spdlog::critical("Failed to initialize decoder: {}", errbuf);
|
||||
@@ -63,7 +68,7 @@ int VideoProcessor::process(
|
||||
|
||||
// Create and initialize the appropriate filter
|
||||
std::unique_ptr<Processor> processor(
|
||||
ProcessorFactory::instance().create_processor(proc_cfg_, hw_cfg_.vk_device_index)
|
||||
ProcessorFactory::instance().create_processor(proc_cfg_, vk_device_index_)
|
||||
);
|
||||
if (processor == nullptr) {
|
||||
spdlog::critical("Failed to create filter instance");
|
||||
@@ -80,16 +85,21 @@ int VideoProcessor::process(
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Update encoder output dimensions
|
||||
enc_cfg_.width = output_width;
|
||||
enc_cfg_.height = output_height;
|
||||
|
||||
// Update encoder frame rate multiplier
|
||||
enc_cfg_.frm_rate_mul = proc_cfg_.frm_rate_mul;
|
||||
|
||||
// Initialize the encoder
|
||||
Encoder encoder;
|
||||
ret = encoder.init(hw_ctx.get(), out_fname, ifmt_ctx, dec_ctx, enc_cfg_, in_vstream_idx);
|
||||
ret = encoder.init(
|
||||
hw_ctx.get(),
|
||||
out_fname,
|
||||
ifmt_ctx,
|
||||
dec_ctx,
|
||||
enc_cfg_,
|
||||
output_width,
|
||||
output_height,
|
||||
in_vstream_idx
|
||||
);
|
||||
if (ret < 0) {
|
||||
av_strerror(ret, errbuf, sizeof(errbuf));
|
||||
spdlog::critical("Failed to initialize encoder: {}", errbuf);
|
||||
|
||||
Reference in New Issue
Block a user