feat(libvideo2x): add optimization for scene detection

Signed-off-by: k4yt3x <i@k4yt3x.com>
This commit is contained in:
k4yt3x
2024-12-12 00:00:00 +00:00
parent 0e00aca401
commit ca5044f09c
4 changed files with 8 additions and 9 deletions

View File

@@ -35,6 +35,7 @@ int Encoder::init(
EncoderConfig &enc_cfg,
int width,
int height,
int frm_rate_mul,
int in_vstream_idx
) {
int ret;
@@ -123,9 +124,9 @@ int Encoder::init(
spdlog::debug("Auto-selected pixel format: {}", av_get_pix_fmt_name(enc_ctx_->pix_fmt));
}
if (enc_cfg.frm_rate_mul > 0) {
if (frm_rate_mul > 0) {
AVRational in_frame_rate = get_video_frame_rate(ifmt_ctx, in_vstream_idx);
enc_ctx_->framerate = {in_frame_rate.num * enc_cfg.frm_rate_mul, in_frame_rate.den};
enc_ctx_->framerate = {in_frame_rate.num * frm_rate_mul, in_frame_rate.den};
enc_ctx_->time_base = av_inv_q(enc_ctx_->framerate);
} else {
// Set the output video's time base

View File

@@ -93,9 +93,6 @@ int VideoProcessor::process(
return handle_error(-1, "Failed to determine the output dimensions");
}
// Update encoder frame rate multiplier
enc_cfg_.frm_rate_mul = proc_cfg_.frm_rate_mul;
// Initialize the encoder
Encoder encoder;
ret = encoder.init(
@@ -106,6 +103,7 @@ int VideoProcessor::process(
enc_cfg_,
output_width,
output_height,
proc_cfg_.frm_rate_mul,
in_vstream_idx
);
if (ret < 0) {
@@ -389,7 +387,7 @@ int VideoProcessor::process_interpolation(
// Check if a scene change is detected
bool skip_frame = false;
if (prev_frame.get() != nullptr) {
if (proc_cfg_.scn_det_thresh < 100.0 && prev_frame.get() != nullptr) {
float frame_diff = get_frame_diff(prev_frame.get(), frame);
if (frame_diff > proc_cfg_.scn_det_thresh) {
spdlog::debug(