SceneFileWriter#
Qualified name: manim.scene.scene\_file\_writer.SceneFileWriter
- class SceneFileWriter(renderer, scene_name, **kwargs)[source]#
Bases:
object
SceneFileWriter is the object that actually writes the animations played, into video files, using FFMPEG. This is mostly for Manim’s internal use. You will rarely, if ever, have to use the methods for this class, unless tinkering with the very fabric of Manim’s reality.
- sections_output_dir#
where are section videos stored
- Type
pathlib.Path
- output_name#
name of movie without extension and basis for section video names
- Type
str
- Some useful attributes are:
- “write_to_movie” (bool=False)
Whether or not to write the animations into a video file.
- “movie_file_extension” (str=”.mp4”)
The file-type extension of the outputted video.
- “partial_movie_files”
List of all the partial-movie files.
Methods
This method adds an audio segment from an AudioSegment type object and suitable parameters.
Adds a new partial movie file path to scene.partial_movie_files and current section from a hash.
This method adds an audio segment from a sound file.
Used internally by manim to stream the animation to FFMPEG for displaying or writing to a file.
Will clean the cache by removing the oldest partial_movie_files.
Used internally by Manim to gracefully stop writing to FFMPEG's input buffer
combine_files
Used 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.
Internally used by Manim to stop streaming to FFMPEG gracefully.
Finishes writing to the FFMPEG buffer or writing images to output directory.
Delete current section if it is empty.
Delete all the cached partial movie files
Get the name of the resolution directory directly containing the video file.
Preps the writer for adding audio to the movie.
Initialise output directories.
Will check if a file named with hash_invocation exists.
Create segmentation cut here.
Used internally by Manim to initialise FFMPEG and begin writing to FFMPEG's input buffer.
output_image
output_image_from_array
Prints the "File Ready" message to STDOUT.
The name is a misnomer.
Used internally by Manim to write a frame to the FFMPEG input buffer.
write_opengl_frame
Writes the subcaption file.
Attributes
force_output_as_scene_name
- 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.
- add_partial_movie_file(hash_animation)[source]#
Adds a new partial movie file path to scene.partial_movie_files and current section from a hash. This method will compute the path from the hash. In addition to that it adds the new animation to the current section.
- Parameters
hash_animation (str) – Hash of the animation.
- add_sound(sound_file, time=None, gain=None, **kwargs)[source]#
This method adds an audio segment from a sound file.
- Parameters
sound_file (str) – 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 – This method uses add_audio_segment, so any keyword arguments used there can be referenced here.
- begin_animation(allow_write=False, file_path=None)[source]#
Used internally by manim to stream the animation to FFMPEG for displaying or writing to a file.
- Parameters
allow_write (bool) – Whether or not to write to a video file.
- close_movie_pipe()[source]#
Used internally by Manim to gracefully stop writing to FFMPEG’s input buffer
- 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.
- combine_to_section_videos()[source]#
Concatenate partial movie files for each section.
- Return type
None
- end_animation(allow_write=False)[source]#
Internally used by Manim to stop streaming to FFMPEG gracefully.
- Parameters
allow_write (bool) – Whether or not to write to a video file.
- finish()[source]#
Finishes writing to the FFMPEG buffer or writing images to output directory. Combines the partial movie files into the whole scene. If save_last_frame is True, saves the last frame in the default image directory.
- get_resolution_directory()[source]#
Get the name of the resolution directory directly containing the video file.
This method gets the name of the directory that immediately contains the video file. This name is
<height_in_pixels_of_video>p<frame_rate>
. For example, if you are rendering an 854x480 px animation at 15fps, the name of the directory that immediately contains the video, file will be480p15
.The file structure should look something like:
MEDIA_DIR |--Tex |--texts |--videos |--<name_of_file_containing_scene> |--<height_in_pixels_of_video>p<frame_rate> |--<scene_name>.mp4
- Returns
The name of the directory.
- Return type
str
- init_output_directories(scene_name)[source]#
Initialise output directories.
Notes
The directories are read from
config
, for exampleconfig['media_dir']
. If the target directories don’t already exist, they will be created.
- 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
- next_section(name, type, skip_animations)[source]#
Create segmentation cut here.
- Parameters
name (str) –
type (str) –
skip_animations (bool) –
- Return type
None
- open_movie_pipe(file_path=None)[source]#
Used internally by Manim to initialise FFMPEG and begin writing to FFMPEG’s input buffer.
- save_final_image(image)[source]#
The name is a misnomer. This method saves the image passed to it as an in the default image directory.
- Parameters
image (ndarray) – The pixel array of the image to save.
- write_frame(frame_or_renderer)[source]#
Used internally by Manim to write a frame to the FFMPEG input buffer.
- Parameters
frame_or_renderer (np.ndarray | OpenGLRenderer) – Pixel array of the frame.
Writes the subcaption file.