Solved Any linux program to breakdown animation to separate frames?

Solved issue

rado84

Well-Known Member
Joined
Feb 25, 2019
Messages
1,094
Reaction score
937
Credits
8,433
This isn't about "video" exactly but I wasn't sure where else to ask my question.

Years ago, when I was still a Windows user, there was this program "Easy GIF Animator" which, among other things like turning a bunch of pictures into an animated GIF, was capable of the opposite - breaking a GIF down to its "components" frame by frame and each frame could be saved as either JPG or PNG, depending on the user's preference.
But that program doesn't work well with Wine (probably bc it's too old) + for some reason it doesn't seem able to detect animated GIFs made with modern tools, such as GIFCurry, let alone animated WEBP.

So, do you know of such programs but for LINUX that can break down a webp or a gif to separate frames? The program I mentioned above detected how many frames per second the GIF had and that was the number of files (frames) it would create from the GIF. So I'm looking for a program with the same abilities/functions or at least close to. But it has to be an offline program - not websites.
 


I don't know of any GUI applications that would do what you want, but if you're not opposed to the command line, imagemagick can do exactly this.

apt install imagemagick (Debian based) or dnf install ImageMagick (Red Hat based)

Then it's as simple as:
Code:
convert -coalesce animated.webp output.png
or
convert -coalesce animated.gif output.png

(swap jpg for png to change the output filetype)

You may or may not need "-coalesce", depending on what animation technique the gif/webp was created with. More than likely you will need this option.

I don't know which distro you're running, so you might pull v7 of imagemagick, in which case use the command "magick" instead of "convert" (for v6 and below).

And that's about all I've got. I'm far from an expert with imagemagick. But it should be able to handle almost any image conversion needs you have.
 
I don't know of any GUI applications that would do what you want, but if you're not opposed to the command line
I'm not opposed to cli and since no one answered, I did some digging and wrote my own scripts: GIF-Breaker and GIF-Maker using Python. But the initial editions didn't properly enumerate the output files, so I had to ask an AI for help with that. The AI added the "while true" block in gif-breaker.py:

Code:
#!/usr/bin/env python3

from PIL import Image
import sys, os

gif = sys.argv[1]

# Взимаме името без разширение
basename = os.path.splitext(os.path.basename(gif))[0]
outdir = basename

os.makedirs(outdir, exist_ok=True)

im = Image.open(gif)

frame = 0
try:
    while True:
        im.seek(frame)
        outpath = os.path.join(outdir, f"frame_{frame+1:03d}.webp")
        im.save(outpath, "WEBP", quality=95)
        frame += 1
except EOFError:
    pass

print(f"Extracted {frame} frames into '{outdir}/'")

Then the AI suggested it could write a gif-maker for me which hadn't occured to me at all, so I agreed and now I have two ultra fast tools that do what "Easy GIF Animator" used to do in Windows 7 many years ago.

GIF-Maker:

Code:
#!/usr/bin/env python3

import os
import sys
import subprocess

if len(sys.argv) < 3:
    print("Usage: gif-maker.py <directory> <fps>")
    sys.exit(1)

indir = sys.argv[1].rstrip("/")
fps = int(sys.argv[2])

# delay в стотни от секундата
delay = round(100 / fps)

# взимаме всички изображения
frames = sorted(
    f for f in os.listdir(indir)
    if f.lower().endswith((".png", ".webp", ".jpg"))
)

if not frames:
    print("No frames found.")
    sys.exit(1)

# изходният GIF е вътре в директорията
dirname = os.path.basename(os.path.abspath(indir))
outgif = os.path.join(indir, f"{dirname}.gif")

# сглобяване с ImageMagick
cmd = [
    "magick",
    "-delay", str(delay),
    "-loop", "0",
] + [os.path.join(indir, f) for f in frames] + [outgif]

subprocess.run(cmd)

print(f"Created {outgif} at {fps} FPS (delay={delay})")

#Отваря генерирания GIF с Nomacs
subprocess.Popen([
    "/home/rado/Nomacs-QT5/nomacs.sh",
    outgif
])

Both are started with the relevant bash script which contains

Code:
python3 gif-maker.sh (or gif-breaker.sh)

and those two make it extremely easy to put them in a case file for faster call.
 
Off-topic, be sure to check the email that you used when signing up at UHost.
 
Cool. @rado84 , if you consider this solved, don't forget to mark it as such.

Cheers

Wizard
 
I skimmed your post so I'm not sure whether they entirely fit your use case, but with frame by frame editing I found Avidemux to be useful, it has a GUI. I used to use VirtualDub on Windows, it may work through WINE, IDK. It also has a GUI. You can search for tutorials online, I know VirtualDub has/had a ton. Good luck with whatever you find/choose.
 


Follow Linux.org

Members online


Latest posts

Top