ManimCommunity / ManimCommunity/manim
GIF Support for ImageMobject
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 40.9k
- Forks
- 3.1k
- Avg merge
- 3d 12h
- Merged PRs (30d)
- 25
Description
## Description of proposed feature
Perhaps this is out of scope for Manim, but it would be nice to have support for GIFs to be embedded as an ImageMobject. Perhaps they can use an internal updater to change each frame in a loop so they are always animating with each frame of the render, including with `self.wait()`.
## How can the new feature be used?
Manim was always meant to be a visual aid for presentations with a mathematical, scientific, or LaTex motivation. It already has support for images with `ImageMobject`, and it would make sense to support GIF, WebM, and small looped video formats. It would also require less video editing after rendering.
I borrowed some code from @Turgibot in https://github.com/3b1b/manim/issues/760#issuecomment-925659697 and wrapped it up in a utility function. I think there's further opportunity to encapsulate this into an `ImageMobject` or a video variant of it.
## Additional comments
```python
from manim import *
import cv2, wget
def animate_gif(scene,
file_name,
wait_time=.07,
repetitions=1,
modify = lambda img: img):
for i in range(0,repetitions):
cap = cv2.VideoCapture(file_name)
flag = True
while flag :
flag, frame = cap.read()
if flag:
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
frame_img = ImageMobject(frame)
modify(frame_img)
scene.add(frame_img)
scene.wait(.07)
scene.remove(frame_img)
cap.release()
class MyScene(Scene):
def construct(self):
wget.download("https://media3.giphy.com/media/VbnUQpnihPSIgIXuZv/giphy.gif")
animate_gif(self, "giphy.gif",
modify = lambda frm: frm.to_corner(UR)
)
```
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing ImageMobject and the proposed animate_gif utility in the issue. Determine how GIF frames should be advanced during rendering and self.wait(), and whether support is limited to GIFs or also includes WebM and other looped video formats. Done means the chosen image or video entry point can embed and animate the requested format reliably.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- opencv, python
- Domain
- computer-graphics
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100