sitcom_simulator.video.integrations.ffmpeg

Functions

concatenate_clips(filenames, output_filename)

Combines the given video clips into a single video file and returns the path to the concatenated video file.

render_clip(clip[, width, height, speed, ...])

Renders a video clip from the given clip object and returns the path to the rendered video file.

render_video(script[, output_path, width, ...])

Renders a video from the given script and returns the path to the rendered video file.

Classes

BoxSettings([color, alpha, border_width])

Settings for boxes in a video.

CaptionSettings([font, max_width, ...])

Settings for captions in a video.

ClipSettings([clip_buffer_seconds, ...])

Settings for rendering video clips.

ShadowSettings([color, alpha, x, y])

Settings for shadows in a video.

class sitcom_simulator.video.integrations.ffmpeg.ShadowSettings(color='black', alpha=0.7, x=5, y=5)

Settings for shadows in a video.

Parameters:
  • color (str) – The color of the shadow

  • alpha (float) – The alpha of the shadow

  • x (int) – The x offset of the shadow

  • y (int) – The y offset of the shadow

color: str = 'black'
alpha: float = 0.7
x: int = 5
y: int = 5
to_dict()

Returns a dictionary representation of the shadow settings for use in an FFmpeg filter.

__init__(color='black', alpha=0.7, x=5, y=5)
Parameters:
  • color (str)

  • alpha (float)

  • x (int)

  • y (int)

Return type:

None

class sitcom_simulator.video.integrations.ffmpeg.BoxSettings(color='black', alpha=0.5, border_width=10)

Settings for boxes in a video.

Parameters:
  • color (str) – The color of the box

  • alpha (float) – The alpha of the box

  • border_width (int) – The width of the box border

color: str = 'black'
alpha: float = 0.5
border_width: int = 10
to_dict()

Returns a dictionary representation of the box settings for use in an FFmpeg filter.

__init__(color='black', alpha=0.5, border_width=10)
Parameters:
  • color (str)

  • alpha (float)

  • border_width (int)

Return type:

None

class sitcom_simulator.video.integrations.ffmpeg.CaptionSettings(font='Arial', max_width=30, y_ratio_from_bottom=0.25)

Settings for captions in a video.

Parameters:
  • font (str) – The path to the font file to use for the captions

  • max_width (int) – The maximum width of the captions, in characters

  • y_ratio_from_bottom (float) – The y ratio from the bottom of the screen to place the captions

font: str = 'Arial'
max_width: int = 30
y_ratio_from_bottom: float = 0.25
formatted_caption(text)

Renders a caption with the given text and returns the caption string.

Parameters:
  • text (str) – The text of the caption

  • width – The width of the video

  • height – The height of the video

__init__(font='Arial', max_width=30, y_ratio_from_bottom=0.25)
Parameters:
  • font (str)

  • max_width (int)

  • y_ratio_from_bottom (float)

Return type:

None

class sitcom_simulator.video.integrations.ffmpeg.ClipSettings(clip_buffer_seconds=0.15, min_clip_seconds=1.5, speaking_delay_seconds=0.12, max_zoom_factor=1.3, min_zoom_factor=1.05, max_pan_speed=6)

Settings for rendering video clips.

Parameters:
  • clip_buffer_seconds (float) – How much time to wait after characters finish talking

  • min_clip_seconds (float) – The minimum time to hold on a clip

  • speaking_delay_seconds (float) – Delay before the audio kicks in

  • max_zoom_factor (float) – The maximum zoom factor for the pan and zoom effect

  • min_zoom_factor (float) – The minimum zoom factor for the pan and zoom effect. At least some zoom is necessary for panning.

  • max_pan_speed (float) – The maximum speed of the pan and zoom effect

clip_buffer_seconds: float = 0.15
min_clip_seconds: float = 1.5
speaking_delay_seconds: float = 0.12
max_zoom_factor: float = 1.3
min_zoom_factor: float = 1.05
max_pan_speed: float = 6
__init__(clip_buffer_seconds=0.15, min_clip_seconds=1.5, speaking_delay_seconds=0.12, max_zoom_factor=1.3, min_zoom_factor=1.05, max_pan_speed=6)
Parameters:
  • clip_buffer_seconds (float)

  • min_clip_seconds (float)

  • speaking_delay_seconds (float)

  • max_zoom_factor (float)

  • min_zoom_factor (float)

  • max_pan_speed (float)

Return type:

None

sitcom_simulator.video.integrations.ffmpeg.render_clip(clip, width=720, height=1280, speed=1.0, pan_and_zoom=True, clip_settings=ClipSettings(clip_buffer_seconds=0.15, min_clip_seconds=1.5, speaking_delay_seconds=0.12, max_zoom_factor=1.3, min_zoom_factor=1.05, max_pan_speed=6), caption_settings=CaptionSettings(font='Arial', max_width=30, y_ratio_from_bottom=0.25), caption_bg_settings=BoxSettings(color='black', alpha=0.5, border_width=10), audio_codec='mp3')

Renders a video clip from the given clip object and returns the path to the rendered video file.

Parameters:
  • clip (Clip) – The clip to render

  • width (int) – The width of the video

  • height (int) – The height of the video

  • speed (float) – The speed of the final video. 1.0 is normal speed

  • pan_and_zoom (bool) – If True, the pan and zoom effect on images will be enabled

  • clip_settings (ClipSettings) – The settings for rendering the video clip

  • caption_settings (CaptionSettings) – The settings for the captions

  • caption_bg_settings (BoxSettings | ShadowSettings) – The settings for the caption background

  • audio_codec (Literal['mp3', 'aac']) – The audio codec to use for the output video

sitcom_simulator.video.integrations.ffmpeg.concatenate_clips(filenames, output_filename, background_music=None, bgm_volume=-24, audio_codec='mp3')

Combines the given video clips into a single video file and returns the path to the concatenated video file.

Parameters:
  • filenames (List[str]) – The list of video file paths to combine

  • output_filename (str) – The name of the output file

  • background_music (str | None) – The path to the background music file

  • bgm_volume (float) – The volume of the background music, between 0 and 1

  • audio_codec (Literal['mp3', 'aac']) – The audio codec to use for the output video

sitcom_simulator.video.integrations.ffmpeg.render_video(script, output_path='output.mp4', width=720, height=1280, speed=1.0, pan_and_zoom=True, clip_settings=ClipSettings(clip_buffer_seconds=0.15, min_clip_seconds=1.5, speaking_delay_seconds=0.12, max_zoom_factor=1.3, min_zoom_factor=1.05, max_pan_speed=6), caption_settings=CaptionSettings(font='Arial', max_width=30, y_ratio_from_bottom=0.25), caption_bg_settings=BoxSettings(color='black', alpha=0.5, border_width=10), bgm_volume=-24, audio_codec='mp3')

Renders a video from the given script and returns the path to the rendered video file.

At present, only 9:16 aspect ratio is supported, but 16:9 and 1:1 will be supported in the future.

Parameters:
  • script (Script) – The script to render

  • output_path (str) – The path to save the rendered video

  • width (int) – The width of the video

  • height (int) – The height of the video

  • speed (float) – The speed of the final video. 1.0 is normal speed

  • pan_and_zoom (bool) – If True, the pan and zoom effect on images will be enabled

  • clip_settings (ClipSettings) – The settings for rendering the video clip

  • caption_settings (CaptionSettings) – The settings for the captions

  • caption_bg_settings (BoxSettings | ShadowSettings) – The settings for the caption background

  • bgm_volume (float) – The volume of the background music, good values are between -24 and -16

  • audio_codec (Literal['mp3', 'aac']) – The audio codec to use for the output video