Code Monkey home page Code Monkey logo

Comments (1)

Antonoko avatar Antonoko commented on July 24, 2024 1

refer to this issue #27, I modified the save_videos_grid method in animatediff\utils\util.py with this. It will place each frame of the generation in "frames" directory.

def save_videos_grid(videos: torch.Tensor, path: str, rescale=False, n_rows=6, fps=8):

    # make frames dir
    frame_dir = os.path.join(os.path.dirname(path), 'frames') 
    os.makedirs(frame_dir, exist_ok=True)

    videos = rearrange(videos, "b c t h w -> t b c h w")
    os.makedirs(os.path.dirname(path), exist_ok=True)
    video_output = path.replace(".gif", ".mp4")
    writer = imageio.get_writer(video_output, fps=fps)
    outputs = []

    for i, x in enumerate(videos):
        x = torchvision.utils.make_grid(x, nrow=n_rows)
        x = x.transpose(0, 1).transpose(1, 2).squeeze(-1)
        if rescale:
            x = (x + 1.0) / 2.0  
        x = (x * 255).numpy().astype(np.uint8)
        
        # saved frames as PNG
        img_path = os.path.join(frame_dir, '%06d.png' % i) 
        imageio.imwrite(img_path, x)
        
        outputs.append(x)
        writer.append_data(x)

    imageio.mimsave(path, outputs, fps=fps)
    writer.close()

had to run:
pip install imageio[ffmpeg]
afterwards

from animatediff.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.