movie

Movie generation subpackage.

Important: requires an FFMPEG executable to work.

It provides a wrapper around FFPMEG command line tool to generate movies from a list of already rendered images.

To make a movie, frames must be rendered separately. This subpackage includes helpers to select the frames to render based on movie specifications.

movie

class Movie(frames_pattern: str, fps: float, resolution: Resolution | None = None, bitrate: int | None = None, encoder: str | None = None, pixel_format: str | None = 'yuv420p', ffmpeg_executable: str = 'ffmpeg')

Bases: object

Holds all the necessary information to generate a movie.

Movies are generated using FFMPEG executable, this class only generates the command line and runs it. Customm FFMPEG executable can be specified if it cannot be found in the system PATH.

Frames are selected using a filename pattern. This one depends on the naming used for the export. The frame index is specified in the pattern using the C printf format (~%d). See FFMPEG input command line (-i) for more details.

Encoder settings are chosen by FFMPEG if not specified except for pixel format which is chosen for maximum compatibility with players.

All the frames selected are used to generate the movie so its duration will be frame_count / FPS.

Parameters:
  • frames_pattern (str) – Frames filename pattern.

  • fps (float) – Movie FPS, should be the same as for export.

  • resolution (Resolution | None, optional) – Movie resolution, defaults to frames resolution.

  • bitrate (int | None, optional) – Encoding bitrate, defaults to FFMPEG choice.

  • encoder (str | None, optional) – Encoder name, defaults to deduced from output file.

  • pixel_format (str | None, optional) – Pixel format name, defaults to ‘yuv420p’.

  • ffmpeg_executable (str, optional) – FFMPEG executable path, defaults to ‘ffmpeg’.

bitrate: int | None = None
encoder: str | None = None
ffmpeg_executable: str = 'ffmpeg'
fps: float
frames_pattern: str
get_command_line(path: str) list[str]

Generate FFMPEG command line from members and given path.

Parameters:

path (str) – Path to save the movie.

Returns:

FFMPEG command line.

Return type:

list[str]

pixel_format: str | None = 'yuv420p'
resolution: Resolution | None = None
save(path: str) str

Save the movie under the given path.

Simply run get_command_line(path).

Parameters:

path (str) – Movie output path.

Returns:

FFMPEG logs for debugging.

Return type:

str

exception MovieError(reason: str, code: int = 0, logs: str = '')

Bases: Error

Exception raised if an error occurs when making a movie.

Parameters:
  • reason (str) – Description of what happened.

  • code (int) – Error code (FFMPEG output code).

  • logs (str) – FFMPEG logs if any.

code: int = 0
logs: str = ''
reason: str

movie_frames

class MovieFrames(fps: float = 25.0, slowing_factor: float = 1.0, start_frame: int = 0, end_frame: int = -1)

Bases: object

Helper class to generate frame indices.

Use the movie specification (FPS, slow motion, frame range) to generate the indices of the simulation frames which needs to be rendered.

Slowing factor is compared to real time (2 = twice slower).

Start and end frames are clamped to the simulation limits and are threated like Python indices (i.e. -1 is simulation.end_frame).

The index step is computed as simulation_fps / fps / slowing_factor. If it is smaller than 1, then some frames will be duplicated to match the target FPS.

Parameters:
  • fps (float) – Movie FPS.

  • slowing_factor (float) – Slowing factor.

  • start_frame (int) – First frame of the movie.

  • end_frame (int) – Last frame of the movie.

end_frame: int = -1
fps: float = 25.0
get_indices(simulation: Simulation) list[int]
slowing_factor: float = 1.0
start_frame: int = 0