continue-revolution / sd-webui-animatediff

AnimateDiff for AUTOMATIC1111 Stable Diffusion WebUI
Other
3.11k stars 258 forks source link

[Bug]: Wrong exported filenames and metadata seed in .txt files for batch count > 1 #242

Closed drumicube closed 1 year ago

drumicube commented 1 year ago

Is there an existing issue for this?

Have you read FAQ on README?

What happened?

When setting the "batch count" option > 1 to generate multiple animations in a single run:

Steps to reproduce the problem

  1. Go to txt2img.
  2. Set batch count to 2.
  3. Set seed to 666.
  4. Configure AnimateDiff to export gif and txt files.
  5. Click on "generate" to export 2 animations.

In the exported folder (AnimateDiff), we currently have:

Drag&drop 00002-666.txt file in the prompt field then recreate the animation, it will produce 00001-666.gif but not the original 00002-666.gif

What should have happened?

AnimateDiff folder content:

Seed info in 00002-second_seed.txt should contains second_seed, not 666. Importing 00002-second_seed.txt using the prompt field, should recreate the second animation, not the first one.

Commit where the problem happens

webui: v1.6.0 extension: v1.9.4 (2f0e68d08028b0440a899c57dcfaf4972a5f0185)

What browsers do you use to access the UI ?

Mozilla Firefox

Command Line Arguments

--no-half-vae --theme dark --api

Console logs

No error in console.

Additional information

Here is a small patch that fixed the problem for me: Be cautious, my knowledge of Auto1111 and Python is very limited, and more testing should be done (not tested in img2img, options like reverse etc.) Sorry for not submitting a PR, it's just a quick fix, and my workflow is not installed yet.

Subject: [PATCH] Export correct seed for batch_count>1
---
Index: scripts/animatediff_output.py
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/scripts/animatediff_output.py b/scripts/animatediff_output.py
--- a/scripts/animatediff_output.py (revision 2f0e68d08028b0440a899c57dcfaf4972a5f0185)
+++ b/scripts/animatediff_output.py (date 1697987907815)
@@ -27,7 +27,7 @@
             video_list = [image.copy() for image in res.images[i : i + params.video_length]]

             seq = images.get_next_sequence_number(f"{p.outpath_samples}/AnimateDiff", "")
-            filename = f"{seq:05}-{res.seed}"
+            filename = f"{seq:05}-{res.all_seeds[(i-1)]}"
             video_path_prefix = f"{p.outpath_samples}/AnimateDiff/{filename}"

             video_list = self._add_reverse(params, video_list)
@@ -127,7 +127,7 @@
     ):
         video_paths = []
         video_array = [np.array(v) for v in video_list]
-        infotext = res.info
+        infotext = res.infotexts[index]
         use_infotext = shared.opts.enable_pnginfo and infotext is not None
         if "PNG" in params.format and shared.opts.data.get("animatediff_save_to_custom", False):
             Path(video_path_prefix).mkdir(exist_ok=True, parents=True)

Thanks for the great module (I'm loving it) and the time spent on it. Have a nice day. :+1:

zappityzap commented 1 year ago

Thanks, I'll take a look at this but it might be a few days.

zappityzap commented 1 year ago

This worked for me in testing, PR submitted. Thanks again!