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 render option to use x265 with lossless settings #4170

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

swenson
Copy link

@swenson swenson commented Feb 17, 2025

Overview: What does this pull request change?

Adds an option to allow the mp4 format to use x265 as an output codec with lossless settings, so that the output is an exact rendering of the animation. This roughly doubles the final output file size by roughly double, though possibly requires fewer resources to render.

Motivation and Explanation: Why and how do your changes improve the library?

By default we use x264 when rendering to the mp4 format with crf set to 23.

x265 (hevc) has a
lossless mode, where the encoder is configured such that the output is an exact copy of the input.

Since manim scenes consist of text and shapes, the lossless mode works well for us, and ensures that the output videos will be the highest quality when desired. This means that users can safely do an editing pass without risking losing further quality.

Anecdotally, I've noticed slightly better performance than x264 with about 2.5x the file size.

Before:

Before (1,436,872 bytes):

$ time venv/bin/manim -pqm quad.py Fermat
...
venv/bin/manim -pqm quad.py Fermat  59.41s user 144.46s system 253% cpu 1:20.44 total

After (3,494,923 bytes):

$ time venv/bin/manim -pqm quad.py Fermat --lossless
...
venv/bin/manim -pqm quad.py Fermat --lossless  144.52s user 12.46s system 274% cpu 57.276 total

So, I added this as an option (for mp4 containers).

Links to added or changed documentation pages

N/A

Further Information and Comments

N/A

Reviewer Checklist

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

By default we use x264 when rendering to the `mp4` format with `crf` set
to 23.

x265 (hevc) has a
[lossless](https://x265.readthedocs.io/en/stable/lossless.html)
mode, where the encoder is configured such that the output is an exact
copy of the input.

Since `manim` scenes consist of text and shapes, the lossless mode works
well for us, and ensures that the output videos will be the highest
quality when desired. This means that users can safely do an editing
pass without risking losing further quality.

Anecdotally, I've noticed slightly better performance than x264 with about
2.5x the file size.

Before:

Before (1,436,872 bytes):

```shell
$ time venv/bin/manim -pqm quad.py Fermat
...
venv/bin/manim -pqm quad.py Fermat  59.41s user 144.46s system 253% cpu 1:20.44 total
```

After (3,494,923 bytes):

```shell
$ time venv/bin/manim -pqm quad.py Fermat --lossless
...
venv/bin/manim -pqm quad.py Fermat --lossless  144.52s user 12.46s system 274% cpu 57.276 total
```

So, I added this as an option (for `mp4` containers).
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.

1 participant