From ca89f17c6616d4e233b4aa9da6065cebe1fe9c79 Mon Sep 17 00:00:00 2001 From: f0e <7321764+f0e@users.noreply.github.com> Date: Sun, 11 Jul 2021 07:48:36 +1000 Subject: [PATCH] new frame blending plugin & brightness/contrast/saturation also: better detailed filenames fixed output audio format fixed error on inputs with no audio track --- blur/avisynth_handler.cpp | 11 +++++++---- blur/config.cpp | 16 +++++++++++++++- blur/config.h | 4 ++++ blur/rendering.cpp | 31 ++++++++++++++++--------------- 4 files changed, 42 insertions(+), 20 deletions(-) diff --git a/blur/avisynth_handler.cpp b/blur/avisynth_handler.cpp index f1fae53..6222161 100644 --- a/blur/avisynth_handler.cpp +++ b/blur/avisynth_handler.cpp @@ -9,6 +9,7 @@ void c_script_handler::create(const std::string& temp_path, const std::string& v { video_script << "from vapoursynth import core" << "\n"; video_script << "import havsfunc as haf" << "\n"; + video_script << "import adjust" << "\n"; // load video std::string chungus = video_path; @@ -35,6 +36,10 @@ void c_script_handler::create(const std::string& temp_path, const std::string& v // output timescale video_script << fmt::format("video = core.std.AssumeFPS(video, fpsnum=(video.fps * {}))", settings.output_timescale) << "\n"; + // brightness + video_script << fmt::format("video = adjust.Tweak(video, bright={}, cont={}, sat={})", settings.brightness - 1.f, settings.contrast, settings.saturation) << "\n"; + + // blurring if (settings.blur) { video_script << fmt::format("frame_gap = int(video.fps / {})", settings.blur_output_fps) << "\n"; @@ -47,10 +52,8 @@ void c_script_handler::create(const std::string& temp_path, const std::string& v // todo: remove weighting limit // todo: gaussian weighting option - // todo: is this wasteful? if you're blending together the surrounding frames for every single frame, then just - // selecting every nth one afterwards is that unneccessarily blending a ton of extra frames that are just going - // to be deleted anyway? i don't know how vapoursynth handles this. look into it. BIG SPEED GAIN IF ITS REAL... - video_script << " video = core.misc.AverageFrames(video, [1] * radius)" << "\n"; + // video_script << " video = core.misc.AverageFrames(video, [1] * radius)" << "\n"; + video_script << fmt::format(" video = core.frameblender.FrameBlend(video, [1] * radius)") << "\n"; video_script << "if frame_gap > 0:" << "\n"; video_script << " video = core.std.SelectEvery(video, cycle=frame_gap, offsets=0)" << "\n"; diff --git a/blur/config.cpp b/blur/config.cpp index 3cc3888..97360d7 100644 --- a/blur/config.cpp +++ b/blur/config.cpp @@ -23,7 +23,17 @@ void c_config::create(const std::string& filepath, s_blur_settings current_setti output << "detailed filenames: " << (current_settings.detailed_filenames ? "true" : "false") << "\n"; output << "\n"; + output << "quality: " << current_settings.quality << "\n"; + + output << "\n"; + + output << "brightness: " << current_settings.brightness << "\n"; + output << "saturation: " << current_settings.saturation << "\n"; + output << "contrast: " << current_settings.contrast << "\n"; + + output << "\n"; + output << "multithreading: " << (current_settings.multithreading ? "true" : "false") << "\n"; output << "gpu: " << (current_settings.gpu ? "true" : "false") << "\n"; output << "gpu type (nvidia/amd/intel): " << current_settings.gpu_type << "\n"; @@ -32,7 +42,7 @@ void c_config::create(const std::string& filepath, s_blur_settings current_setti output << "interpolation speed: " << current_settings.interpolation_speed << "\n"; output << "interpolation tuning: " << current_settings.interpolation_tuning << "\n"; - output << "interpolation algorithm: " << current_settings.interpolation_algorithm << "\n"; + output << "interpolation algorithm: " << current_settings.interpolation_algorithm; } std::string c_config::get_config_filename(const std::string& video_folder) { @@ -105,6 +115,10 @@ s_blur_settings c_config::parse(const std::string& config_filepath, bool& first_ config_get("quality", settings.quality); + config_get("brightness", settings.brightness); + config_get("saturation", settings.saturation); + config_get("contrast", settings.contrast); + config_get("preview", settings.preview); config_get("detailed filenames", settings.detailed_filenames); diff --git a/blur/config.h b/blur/config.h index 6e3f3ea..089acb8 100644 --- a/blur/config.h +++ b/blur/config.h @@ -15,6 +15,10 @@ struct s_blur_settings { int quality = 18; + float brightness = 1.f; + float saturation = 1.f; + float contrast = 1.f; + bool preview = true; bool detailed_filenames = false; diff --git a/blur/rendering.cpp b/blur/rendering.cpp index 8478659..09c562c 100644 --- a/blur/rendering.cpp +++ b/blur/rendering.cpp @@ -82,19 +82,23 @@ void c_render::build_output_filename() { if (this->settings.detailed_filenames) { std::string extra_details; - if (this->settings.interpolate) { - extra_details += fmt::format("»{}fps", this->settings.interpolated_fps); - } - + // stupid if (this->settings.blur) { - if (extra_details != "") - extra_details += " "; - - extra_details += fmt::format("»{}fps ({})", this->settings.blur_output_fps, this->settings.blur_amount); + if (this->settings.interpolate) { + extra_details = fmt::format("{}fps ({}, {})", this->settings.blur_output_fps, this->settings.interpolated_fps, this->settings.blur_amount); + } + else { + extra_details = fmt::format("{}fps ({})", this->settings.blur_output_fps, this->settings.blur_amount); + } + } + else { + if (this->settings.interpolate) { + extra_details = fmt::format("{}fps", this->settings.interpolated_fps); + } } if (extra_details != "") { - this->output_filename += " " + extra_details; + this->output_filename += " ~ " + extra_details; } } @@ -187,7 +191,7 @@ std::string c_render::build_ffmpeg_command() { // input ffmpeg_command += " -i -"; // piped output from video script ffmpeg_command += fmt::format(" -i \"{}\"", video_path); // original video (for audio) - ffmpeg_command += " -map 0:v -map 1:a"; // copy video from first input, copy audio from second + ffmpeg_command += " -map 0:v -map 1:a?"; // copy video from first input, copy audio from second // video format if (settings.gpu) { @@ -206,9 +210,6 @@ std::string c_render::build_ffmpeg_command() { if (settings.input_timescale != 1.f || settings.output_timescale != 1.f) ffmpeg_command += fmt::format(" -af \"asetrate=44100*{}\"", (1 / settings.input_timescale) * settings.output_timescale); - // audio format - ffmpeg_command += " -c:a libopus -b:a 320k"; - // extra ffmpeg_command += " -movflags +faststart"; @@ -217,8 +218,8 @@ std::string c_render::build_ffmpeg_command() { // extra output for preview. generate low-quality preview images. if (settings.preview) { - ffmpeg_command += " -map 0:v"; // copy video from first input, copy audio from second - ffmpeg_command += fmt::format(" -q:v 5 -update 1 -atomic_writing 1 -y \"{}\"", preview_filename); + ffmpeg_command += " -map 0:v"; // copy video from first input + ffmpeg_command += fmt::format(" -q:v 3 -update 1 -atomic_writing 1 -y \"{}\"", preview_filename); } }