writer

class janim.render.writer.VideoWriter(built: BuiltTimeline, *, ctx: Context | None = None)

Bases: object

Generate video from timeline animation and output to file

You can directly call VideoWriter.writes(MyTimeline().build()) to output

The main process is in write_all():

  • First call ffmpeg, which is used here to generate video (initially output to _temp file)

  • Then iterate through each frame of the animation, render it, and pass the pixel data to ffmpeg

  • Finally end the ffmpeg call and complete the output of the _temp file

  • Rename the _temp file, remove the _temp suffix, and complete video output

static writes(built: BuiltTimeline, file_path: str, *, quiet=False, use_pbo=True, hwaccel=False) None
write_all(file_path: str, in_point: float | None = None, out_point: float | None = None, *, quiet=False, use_pbo=True, hwaccel=False, _keep_temp=False) None

Output timeline animation to file

  • If quiet=True is specified, prompt messages before and after will not be output, but the progress bar will still be shown

open_video_pipe(file_path: str, hwaccel: bool) None
static ext_specific_flags(ffmpeg_bin: str, ext: str, hwaccel: bool) list[str]

Generate different FFMPEG arguments for different formats

static find_h264_encoder(ffmpeg_bin: str, hwaccel: bool) str

Find encoder, if hwaccel=True, prioritize using hardware encoder

static test_encoder_usability(ffmpeg_bin: str, potential: str) bool
static encoder_flags(encoder: str) list[str]
static find_encoder_device() str | None

Return the first working VA-API render node, or None.

close_video_pipe(_keep_temp: bool) None
static handle_ffmpeg_not_found()
class janim.render.writer.AudioWriter(built: BuiltTimeline)

Bases: object

static writes(built: BuiltTimeline, file_path: str, *, quiet=False) None
write_all(file_path: str, *, quiet=False, _keep_temp=False) None
open_audio_pipe(file_path: str) None
close_audio_pipe(_keep_temp: bool) None
janim.render.writer.merge_video_and_audio(ffmpeg_bin: str, video_path: str, audio_path: str, result_path: str, remove: bool = True, *, quiet: bool = False) None
class janim.render.writer.SRTWriter

Bases: object

static writes(built: BuiltTimeline, file_path: str) None
static t_to_srt_time(t: float)

Convert seconds to SRT time format: HH:MM:SS,mmm