Refactor: move video segment encoding to dedicated module and detach SceneFileWriter from renderer state - #4976
Open
behackl wants to merge 37 commits into
Open
Conversation
Co-authored-by: nikolajmunk <28557236+nikolajmunk@users.noreply.github.com>
…out-output-plan # Conflicts: # docs/source/guides/deep_dive.rst # tests/test_scene_rendering/opengl/test_cli_flags_opengl.py # tests/test_scene_rendering/test_file_writer.py
| def _abort_encoder(self) -> None: | ||
| try: | ||
| self.encoder.abort() | ||
| except BaseException as exception: |
| try: | ||
| for packet in self._stream.encode(): | ||
| self._container.mux(packet) | ||
| except BaseException as error: |
| first_error = error | ||
| try: | ||
| self._container.close() | ||
| except BaseException as error: |
| self._closed = True | ||
| try: | ||
| self._container.close() | ||
| except BaseException as error: |
| first_error = error | ||
| try: | ||
| self.target.unlink(missing_ok=True) | ||
| except BaseException as error: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stacked on #4969, actual diff: behackl/manim@refactor/media-layout-output-plan...refactor/encoder-writer-detachment
This resolves video-segment encoder settings once per render session, extracts PyAV segment encoding into a dedicated component, and removes
SceneFileWriter's dependencies on renderer internals and mutable global configuration.Each scene now has a frozen
VideoEncoderSpeccovering the segment container, codec, pixel format, geometry, exact frame rate, and codec options.VideoSegmentEncoderowns PyAV stream setup, segment-local timestamps, repeated frames, flushing, cleanup, and contextual errors.SceneFileWritercoordinates these encoders and assembles artifacts from its resolved output plan and writer settings.Renderers now pass concrete top-left-origin, C-contiguous
uint8RGBA arrays across the writer boundary. In particular, OpenGL performs GPU readback in the renderer, and only when file output needs a frame.Encoder configuration
With codec and pixel format set to
auto, Manim retains its current libx264, qtrle, and libvpx-vp9 choices for MP4, MOV, WebM, and GIF output. They can now be overridden with:--video-codec CODEC;--pixel-format FORMAT; and--encoder-option KEY=VALUEarguments.The equivalent configuration is:
If any
--encoder-optionis supplied, the CLI option map replaces the complete[video_encoder.options]map. Invalid containers, codecs, pixel formats, alpha combinations, geometry, frame rates, and conflicting stream options fail during session resolution rather than partway through rendering.The old
[ffmpeg] loglevel/config.ffmpeg_loglevelsetting is replaced by[media] loglevel/config.media_loglevel, reflecting that media operations are handled through PyAV rather than an ffmpeg subprocess.Cache and assembly changes
--flush_cacheandconfig.flush_cacheare removed. Usemanim cache clear FILE SCENE [SCENE ...]to clear concrete scene caches without starting a render.max_files_cached = -1as unlimited.partial_movie_file_list.txtremains as an atomically written diagnostic snapshot of the complete main-scene segment order and is never used as live assembly input.Renderer and file-writer extension APIs
Custom renderers and writer implementations need updates:
renderer.init_scene(scene, session_spec)now also receives the resolved writer settings.SceneFileWriterimplementations are constructed from that settings object instead of receiving a renderer, scene name, and separate output arguments.SceneFileWriter.write_frame(...)now receives a concrete RGBA array andrepeat=count; ownership of the array transfers to the writer because encoding may consume it asynchronously.The writer-settings aggregate is intentionally private. This PR creates a reviewable dependency seam; it does not establish renderer-owned writer construction as a permanent public API.
Out of scope / follow-up work
This does not yet move writer ownership, play ordinals, clocks, cache decisions, or segment lifecycle into
Manager. Renderers still schedule writer calls temporarily. It also does not decompose audio and final artifact assembly, redesign recursive scene-state serialization, or add incremental mobject mutation tracking. Those remain follow-up work for the Manager-owned execution and renderer rework.