Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add output format options #54

Conversation

zappityzap
Copy link
Collaborator

  • Add checkbox to save individual frames
  • Add checkbox to save GIF
  • Add checkbox to save MP4
  • Move location of saved frames to dated folders under AnimateDiff instead of regular txt2img folder
  • Don't save frames by default
  • Save GIF by default

Saving as WEBP and WEBM would be nice, but I couldn't get it working.

The UI was rearranged slightly as well. Here it is before:
feature-output-formats-before

And here it is after:
feature-output-formats-after

@zappityzap
Copy link
Collaborator Author

  • Adds text output format with generation parameters, disabled by default, closes [Feature]: Add an option to generate a text file next to each gif, containing the generations parameters  #55
  • Adds option to optimize GIFs with gifsicle, disabled by default
    • To use optimize GIF: apt install gifsicle, then activate the venv, pip install pygifsicle
    • Optimized GIFs are smaller and more compatible, but may have less quality.
  • Saves to GIF, MP4 and PNG by default
  • Uses mm_sd_v14.ckpt by default
  • Saves each output format to separate sub-directory
  • Fixes UI for various size screens
    image

@christopherwolfsaal
Copy link

When can this PR be merged? I need the mp4 output

@zappityzap
Copy link
Collaborator Author

Maintainer is busy with real life stuff. You can install it from my fork on the feature-output-formats branch.

I'll be submitting similar PRs to this newer fork: https://github.com/JaredTherriault/sd-webui-animatediff

@continue-revolution
Copy link
Owner

continue-revolution commented Sep 12, 2023

I will merge, but will do this after some other update in this extension and some fucking real life stuff

@FizzleDorf
Copy link

I think it should be rekitted to create a .bat with the commands, place it in the folder, and run it so the user can switch framerates and add filters after the fact. You can even include the missing formats using ffmpeg instead

@zappityzap
Copy link
Collaborator Author

That's a bit out-of-scope for the extension, and it would need to support Linux as well. Saving PNG frames should allow for a user to create their own script.

@continue-revolution Please feel free to pick and choose anything out of this PR and then close it, no worries.

@christopherwolfsaal
Copy link

christopherwolfsaal commented Sep 15, 2023

I already implemented a local mp4 processing and making the frames smooth with interpolate..maybe you want to integrate that

def postprocess(self, p: StableDiffusionProcessing, res: Processed, enable_animatediff=False, loop_number=0, video_length=16, fps=8, model="mm_sd_v15.ckpt"):
    if enable_animatediff:
        self.restore_ddim_alpha(p)
        self.remove_motion_modules(p)
        video_paths = []
        self.logger.info("Merging images into MP4.")
        from pathlib import Path
        Path(f"{p.outpath_samples}/AnimateDiff").mkdir(exist_ok=True, parents=True)                   
        dirname=f"{p.outpath_samples}/AnimateDiff"                              
        for i in range(res.index_of_first_image, len(res.images), video_length):  
            video_list = res.images[i:i+video_length]
            seq = images.get_next_sequence_number(dirname, "")
            filename = f"{seq:05}-{res.seed}"
            mp4_path = os.path.join(p.outpath_samples, "..", "mp4", dirname)
            os.makedirs(mp4_path, exist_ok=True)                
            video_pathtemp = os.path.join(mp4_path, f"{filename}_tmp.mp4")
            video_path = os.path.join(mp4_path, f"{filename}.mp4")
            video_paths.append(video_path)
            imageio.mimsave(video_pathtemp, video_list, fps=fps)      

            ffmpeg_command = [
                'ffmpeg',
                '-y',
                '-i',
                video_pathtemp,
                '-crf',
                '10',
                '-vf',
                'minterpolate=fps=60:mi_mode=mci:mc_mode=aobmc:me_mode=bidir:vsbmc=1,setpts=2.5*PTS',
                '-map',
                '0',
                '-crf',
                '10',
                '-an',
                '-f',
                'mp4',
                video_path
            ]
            
            # Execute the ffmpeg command
            try:
                subprocess.run(ffmpeg_command, check=True)
                print("FFmpeg command executed successfully")
            except subprocess.CalledProcessError as e:
                print("Error executing FFmpeg command:", e)               
          
        res.images = video_paths
        self.logger.info("AnimateDiff process end.")

@continue-revolution continue-revolution mentioned this pull request Sep 15, 2023
Merged
2 tasks
@continue-revolution continue-revolution changed the base branch from master to format September 16, 2023 01:44
@continue-revolution continue-revolution merged commit 2812561 into continue-revolution:format Sep 16, 2023
@zappityzap zappityzap deleted the feature-output-formats branch September 16, 2023 03:54
continue-revolution added a commit that referenced this pull request Sep 16, 2023
refactor postprocessing

Co-authored-by: zappityzap <128872140+zappityzap@users.noreply.github.com>
continue-revolution added a commit that referenced this pull request Sep 17, 2023
* i2v first attempt

* refactor code

* refactor code

* add reverse frame, and UI Parts (#84) (#90)

Co-authored-by: toretate <toretatenee@gmail.com>

* Add output format options (#54) (#91)

refactor postprocessing

Co-authored-by: zappityzap <128872140+zappityzap@users.noreply.github.com>

* refactor

* refactor

* use black

* finish

* readme

* Update README.md

---------

Co-authored-by: toretate <toretatenee@gmail.com>
Co-authored-by: zappityzap <128872140+zappityzap@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants