SceneFileWriter¶
Qualified name: manim.scene.scene\_file\_writer.SceneFileWriter
- class SceneFileWriter(settings)[source]¶
Bases:
objectCoordinate segment jobs and assemble one scene’s media artifacts.
The writer receives immutable resolved settings and concrete top-left-origin RGBA arrays. Ownership of each array passed to
write_frame()transfers to the writer; callers must not mutate or reuse it afterward. For video output the writer coordinates queuedVideoSegmentEncoderjobs, then assembles their silent cached segments with optional audio, sections, and subcaptions. It also writes still images and PNG sequences described by the output plan.- Parameters:
settings (_SceneFileWriterSettings) – Resolved output, encoding, pool, cache, and asset-search settings.
- sections¶
Ordered section metadata for the scene.
- partial_movie_files¶
Segment paths in animation order, including
Nonefor skipped plays.
Methods
Discard the current segment and drain completed encode jobs.
This method adds an audio segment from an AudioSegment type object and suitable parameters.
Append a planned segment path to the writer and current section.
This method adds an audio segment from a sound file.
Start a segment job for one animation when video writing is enabled.
Seal the current segment and enforce the in-flight job limit.
combine_filesUsed internally by Manim to combine the separate partial movie files that make up a Scene into a single video file for that Scene.
Concatenate partial movie files for each section.
Creates an empty, silent, Audio Segment.
Seal the current segment job when video writing is enabled.
Drain segment jobs and assemble the configured time-based output.
Delete current section if it is empty.
Preps the writer for adding audio to the movie.
Will check if a file named with hash_invocation exists.
Join every in-flight encode job, re-raising the first failure.
Create segmentation cut here.
Create a queued encoder job for one planned video segment.
output_imageRecord and report a completed primary artifact.
Save one RGBA frame to the planned still-image path.
Take ownership of one top-left C-contiguous
uint8RGBA frame.Writes the subcaption file next to the primary video artifact.
Attributes
Return the planned GIF artifact path.
Return the planned still or video-fallback image path.
Return the planned PNG-sequence directory.
Return the planned primary video artifact path.
Return the planned logical output stem as a compatibility view.
Return the planned silent-segment cache directory.
Return the planned sections directory, or the legacy empty path.
- static _concat_manifest_bytes(input_files)[source]¶
Return a complete FFmpeg concat manifest for
input_files.- Parameters:
input_files (list[str])
- Return type:
bytes
- _join_job(job)[source]¶
Remove and join an in-flight partial movie encode job.
- Parameters:
job (_PartialMovieEncodeJob)
- Return type:
None
- _join_job_and_drain_on_failure(job)[source]¶
Join one job, draining all remaining jobs if it fails.
- Parameters:
job (_PartialMovieEncodeJob)
- Return type:
None
- _write_concat_manifest(input_files)[source]¶
Atomically persist the complete scene segment order for diagnostics.
- Parameters:
input_files (list[str])
- Return type:
None
- abort_encode_jobs(reraise_encoder_failures=False)[source]¶
Discard the current segment and drain completed encode jobs.
When
reraise_encoder_failuresis true, the first encoder failure is propagated. Otherwise failures are logged so an active render exception remains primary.- Parameters:
reraise_encoder_failures (bool)
- Return type:
None
- add_audio_segment(new_segment, time=None, gain_to_background=None)[source]¶
This method adds an audio segment from an AudioSegment type object and suitable parameters.
- Parameters:
new_segment (AudioSegment) – The audio segment to add
time (float | None) – the timestamp at which the sound should be added.
gain_to_background (float | None) – The gain of the segment from the background.
- Return type:
None
- add_partial_movie_file(hash_animation)[source]¶
Append a planned segment path to the writer and current section.
The list retains one entry per animation so explicit animation indices select the corresponding segment.
- Parameters:
hash_animation (str | None) – Hash of the animation.
- Return type:
None
- add_sound(sound_file, time=None, gain=None, **kwargs)[source]¶
This method adds an audio segment from a sound file.
- Parameters:
sound_file (StrPath) – The path to the sound file.
time (float | None) – The timestamp at which the audio should be added.
gain (float | None) – The gain of the given audio segment.
**kwargs (Any) – This method uses add_audio_segment, so any keyword arguments used there can be referenced here.
- Return type:
None
- begin_animation(allow_write=False, *, animation_index, file_path=None)[source]¶
Start a segment job for one animation when video writing is enabled.
- Parameters:
allow_write (bool) – Whether this animation needs a new segment.
animation_index (int) – Scene-local animation index used to select and label the segment.
file_path (TypeAliasForwardRef('~manim.typing.StrPath') | None) – Explicit segment target, or
Noneto use the planned cache path.
- Return type:
None
- close_partial_movie_stream()[source]¶
Seal the current segment and enforce the in-flight job limit.
- Return type:
None
- combine_to_movie()[source]¶
Used internally by Manim to combine the separate partial movie files that make up a Scene into a single video file for that Scene.
- Return type:
None
- combine_to_section_videos()[source]¶
Concatenate partial movie files for each section.
- Return type:
None
- end_animation(allow_write=False)[source]¶
Seal the current segment job when video writing is enabled.
- Parameters:
allow_write (bool) – Whether the current animation has an open segment job.
- Return type:
None
- finish()[source]¶
Drain segment jobs and assemble the configured time-based output.
- Return type:
None
- property gif_file_path: Path¶
Return the planned GIF artifact path.
- property image_file_path: Path¶
Return the planned still or video-fallback image path.
- property image_sequence_directory: Path¶
Return the planned PNG-sequence directory.
- is_already_cached(hash_invocation)[source]¶
Will check if a file named with hash_invocation exists.
- Parameters:
hash_invocation (str) – The hash corresponding to an invocation to either scene.play or scene.wait.
- Returns:
Whether the file exists.
- Return type:
bool
- join_all_encode_jobs()[source]¶
Join every in-flight encode job, re-raising the first failure.
- Return type:
None
- property movie_file_path: Path¶
Return the planned primary video artifact path.
- next_section(name, type_, skip_animations)[source]¶
Create segmentation cut here.
- Parameters:
name (str)
type_ (str)
skip_animations (bool)
- Return type:
None
- open_partial_movie_stream(*, animation_index, file_path=None)[source]¶
Create a queued encoder job for one planned video segment.
- Parameters:
animation_index (int)
file_path (TypeAliasForwardRef('~manim.typing.StrPath') | None)
- Return type:
None
- property output_name: Path¶
Return the planned logical output stem as a compatibility view.
- property partial_movie_directory: Path¶
Return the planned silent-segment cache directory.
- print_file_ready_message(file_path)[source]¶
Record and report a completed primary artifact.
- Parameters:
file_path (StrPath)
- Return type:
None
- save_image(pixels)[source]¶
Save one RGBA frame to the planned still-image path.
- Parameters:
pixels (RGBAPixelArray)
- Return type:
None
- property sections_output_dir: Path¶
Return the planned sections directory, or the legacy empty path.
- write_frame(pixels, *, repeat=1)[source]¶
Take ownership of one top-left C-contiguous
uint8RGBA frame.The caller must not mutate or reuse
pixelsafter this method returns because video encoding can consume the array asynchronously.- Parameters:
pixels (RGBAPixelArray)
repeat (int)
- Return type:
None