From df176751f7c4f58256d40033ba4cc3ff1f036512 Mon Sep 17 00:00:00 2001 From: vmobilis <75476228+vmobilis@users.noreply.github.com> Date: Fri, 21 Aug 2026 15:18:03 +0300 Subject: [PATCH 1/3] main.cpp: move `format_frame_idx()` before `step_callback()` --- examples/cli/main.cpp | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/examples/cli/main.cpp b/examples/cli/main.cpp index 1cc7a7af4..20be00e07 100644 --- a/examples/cli/main.cpp +++ b/examples/cli/main.cpp @@ -372,6 +372,25 @@ bool load_images_from_dir(const std::string dir, return true; } +std::string format_frame_idx(std::string pattern, int frame_idx) { + std::smatch match; + std::string result = pattern; + while (std::regex_search(result, match, format_specifier_regex)) { + std::string specifier = match.str(1); + char buffer[32]; + snprintf(buffer, sizeof(buffer), specifier.c_str(), frame_idx); + result.replace(match.position(1), match.length(1), buffer); + } + + // Then replace all '%%' with '%' + size_t pos = 0; + while ((pos = result.find("%%", pos)) != std::string::npos) { + result.replace(pos, 2, "%"); + pos += 1; + } + return result; +} + void step_callback(int step, int frame_count, sd_image_t* image, bool is_noisy, void* data) { (void)step; (void)is_noisy; @@ -393,25 +412,6 @@ void step_callback(int step, int frame_count, sd_image_t* image, bool is_noisy, } } -std::string format_frame_idx(std::string pattern, int frame_idx) { - std::smatch match; - std::string result = pattern; - while (std::regex_search(result, match, format_specifier_regex)) { - std::string specifier = match.str(1); - char buffer[32]; - snprintf(buffer, sizeof(buffer), specifier.c_str(), frame_idx); - result.replace(match.position(1), match.length(1), buffer); - } - - // Then replace all '%%' with '%' - size_t pos = 0; - while ((pos = result.find("%%", pos)) != std::string::npos) { - result.replace(pos, 2, "%"); - pos += 1; - } - return result; -} - static fs::path get_video_audio_sidecar_path(const SDCliParams& cli_params) { fs::path out_path = cli_params.output_path; fs::path base_path = out_path; From 6f05c470aff57aaac3b8571d9515b6a340ffa11f Mon Sep 17 00:00:00 2001 From: vmobilis <75476228+vmobilis@users.noreply.github.com> Date: Fri, 21 Aug 2026 15:24:39 +0300 Subject: [PATCH 2/3] main.cpp: handle "%d" --- examples/cli/main.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/examples/cli/main.cpp b/examples/cli/main.cpp index 20be00e07..57e58503c 100644 --- a/examples/cli/main.cpp +++ b/examples/cli/main.cpp @@ -80,7 +80,7 @@ struct SDCliParams { &metadata_format}, {"", "--preview-path", - "path to write preview image to (default: ./preview.png). Multi-frame previews support .avi, .webm, and animated .webp", + "path to write preview image to (default: ./preview.png). For image generation, the filename can have %03d placeholder for sequential numbering. Multi-frame previews support .avi, .webm, and animated .webp", 0, &preview_path}, {"", @@ -391,6 +391,8 @@ std::string format_frame_idx(std::string pattern, int frame_idx) { return result; } +int continuous_preview_counter = 0; + void step_callback(int step, int frame_count, sd_image_t* image, bool is_noisy, void* data) { (void)step; (void)is_noisy; @@ -398,12 +400,20 @@ void step_callback(int step, int frame_count, sd_image_t* image, bool is_noisy, // is_noisy is set to true if the preview corresponds to noisy latents, false if it's denoised latents // unused in this app, it will either be always noisy or always denoised here if (frame_count == 1) { - if (!write_image_to_file(cli_params->preview_path, + std::string name = cli_params->preview_path; + size_t name_pos = name.find_last_of('/') + 1; // skipping %d in path +#ifdef _WIN32 + size_t name_pos2 = name.find_last_of('\\') + 1; + name_pos = std::max(name_pos, name_pos2); +#endif + name = cli_params->preview_path.substr(0, name_pos) + + format_frame_idx(name.substr(name_pos), ++continuous_preview_counter); + if (!write_image_to_file(name, image->data, image->width, image->height, image->channel)) { - LOG_ERROR("save preview image to '%s' failed", cli_params->preview_path.c_str()); + LOG_ERROR("save preview image to '%s' failed", name.c_str()); } } else { if (create_video_from_sd_images(cli_params->preview_path.c_str(), image, frame_count, cli_params->preview_fps) != 0) { From 24194bcb5804c238a87930f8f9dd51738f37efdc Mon Sep 17 00:00:00 2001 From: vmobilis <75476228+vmobilis@users.noreply.github.com> Date: Fri, 21 Aug 2026 19:53:10 +0300 Subject: [PATCH 3/3] main.cpp: simplificatiin --- examples/cli/main.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/examples/cli/main.cpp b/examples/cli/main.cpp index 57e58503c..eea756fd9 100644 --- a/examples/cli/main.cpp +++ b/examples/cli/main.cpp @@ -400,20 +400,15 @@ void step_callback(int step, int frame_count, sd_image_t* image, bool is_noisy, // is_noisy is set to true if the preview corresponds to noisy latents, false if it's denoised latents // unused in this app, it will either be always noisy or always denoised here if (frame_count == 1) { - std::string name = cli_params->preview_path; - size_t name_pos = name.find_last_of('/') + 1; // skipping %d in path -#ifdef _WIN32 - size_t name_pos2 = name.find_last_of('\\') + 1; - name_pos = std::max(name_pos, name_pos2); -#endif - name = cli_params->preview_path.substr(0, name_pos) + - format_frame_idx(name.substr(name_pos), ++continuous_preview_counter); - if (!write_image_to_file(name, + fs::path path = cli_params->preview_path; + std::string new_pathname = fs::path(path).remove_filename().string() + + format_frame_idx(path.filename().string(), ++continuous_preview_counter); + if (!write_image_to_file(new_pathname, image->data, image->width, image->height, image->channel)) { - LOG_ERROR("save preview image to '%s' failed", name.c_str()); + LOG_ERROR("save preview image to '%s' failed", new_pathname.c_str()); } } else { if (create_video_from_sd_images(cli_params->preview_path.c_str(), image, frame_count, cli_params->preview_fps) != 0) {