Skip to content

Commit

Permalink
new frame blending plugin & brightness/contrast/saturation
Browse files Browse the repository at this point in the history
also:
better detailed filenames
fixed output audio format
fixed error on inputs with no audio track
  • Loading branch information
f0e committed Jul 10, 2021
1 parent c0be890 commit ca89f17
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 20 deletions.
11 changes: 7 additions & 4 deletions blur/avisynth_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand All @@ -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";
Expand Down
16 changes: 15 additions & 1 deletion blur/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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) {
Expand Down Expand Up @@ -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);

Expand Down
4 changes: 4 additions & 0 deletions blur/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
31 changes: 16 additions & 15 deletions blur/rendering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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";

Expand All @@ -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);
}
}

Expand Down

0 comments on commit ca89f17

Please sign in to comment.