ManimCommunity / ManimCommunity/manim

High level interface for merging scenes

Open
#2,999 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

new feature
Dominant language
Python
Stars
40.9k
Forks
3.1k
Avg merge
3d 12h
Merged PRs (30d)
25

Description

## Description of proposed feature

Discord user Roma [has previously asked](https://discord.com/channels/581738731934056449/1028764135464374372/1028764135464374372):

> As to my knowledge, there are few tools to concatenate two scenes in one video file internally, most people render all scenes distinctively and then edit them with other software. I find this impractical and I came up with the following method: you create a number of external methods, each corresponding to one of your scenes. Then you create a single scene and in the construct() method apply the external methods one after one. Like this:
>
> ```python
> def FirstScene (scene : Scene):
> # animate stuff with scene.play
> def SecondScene (scene : Scene):
> # animate stuff with scene.play
> class Main (Scene):
> def construct (self):
> FirstScene(self)
> SecondScene(self)
> ```

I've seen the same method being used by many. One disadvantage is that the merged scene has to be rendered from scratch — even if the parts are cached, this is still slower than a simple concatenation with ffmpeg. When the scenes are long enough, this often becomes impractical (especially since I have to use --disable_caching for adding sounds/voiceovers)

I already have shell scripts that use ffmpeg and which account for videos with voiceover, and was thinking that we could bake that functionality into Manim itself.

I propose a new interface called `Composition` for merging the video files directly, instead of the programmatic way people have been using until now.

## How can the new feature be used?

Usage-wise `Composition` would look like a stripped down version of `Scene`:

```python
def FirstScene (Scene):
# animate stuff with self.play
def SecondScene (Scene):
# animate stuff with self.play
def Final(Composition):
def construct(self):
self.add_sound("soundtrack.mp3")
self.play(FirstScene)
self.play(SecondScene)
```

Internally, it would be look for `FirstScene.mp4` and `SecondScene.mp4`, and merge them using ffmpeg, in contrast to rendering a new scene from scratch. Being able to add soundtracks with `add_sound()` is another nice-to-have.

The interface is made to look like Scene intentionally, for simplicity and not having to learn something new.

## Additional comments

Open questions:

- Should there be any caching/change detection? `Composition` would need to tell whether the a scene has already been rendered. Should it be agnostic of changes to a scene and just use an existing rendering, or should it track changes?
- This proposal currently includes merging videos and adding sound—what other features could we add?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the existing Scene interface and the proposed Composition API, including construct(), play(), and add_sound(). Compare the requested behavior with the existing rendering and caching flow and the stated ffmpeg shell scripts. Done means the scope, caching or change-detection behavior, scene merging, and soundtrack support are specified clearly enough to implement and test.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.