Image

class scenepic.Image

A ScenePic Image type

property data: bytes

The binary image data.

property ext

The extension of the image (e.g. JPG, PNG)

Type:

str

from_numpy(array, format_str='png')

Loads the image object from raw RGB values provided as a numpy array.

Parameters:
  • self (Image) – self reference

  • array (np.ndarray) – The raw pixel RGB as either 0-255 bytes or 0-1 floats.

  • format_str (str, optional) – The format to use when compressing the image. Defaults to “png”.

property image_id

A unique identifier for the image

Type:

str

load()

Load an image file from the disk

Parameters:

path (str) – the path to the image file

load_from_buffer(data, ext)

Load an image from a pre-existing data buffer and extension.

Parameters:
  • self (Image) – self reference

  • data (bytes) – the binary data for the image

  • ext (str) – the format of the image data [e.g. “gif”, “jpg”, “png”]

AudioTrack

class scenepic.AudioTrack

A ScenePic AudioTrack type

property audio_id

A unique identifier for the audio track

Type:

str

property data

The binary audio data.

load()

Load an audio file from the disk

Parameters:

path (str) – the path to the audio file

load_from_buffer(data, ext)

Load audio from a pre-existing data buffer and extension.

Parameters:
  • self (AudioTrack) – self reference

  • data (bytes) – the binary data for the audio

  • ext (str) – the file extension (e.g. mp3, ogg, wav)

Video

class scenepic.Video

A ScenePic Video type

property data: bytes

The binary video data.

load()

Load a video file from the disk

Parameters:

path (str) – the path to the video file

load_from_buffer(data, ext)

Load video from a pre-existing data buffer and extension.

Parameters:
  • data (bytes) – the binary data for the video

  • ext (str) – the file extension (e.g. mp4, mkv)

property video_id

A unique identifier for the video

Type:

str

VideoWriter

class scenepic.VideoWriter(output_path, frame_size, quality=None, ffmpeg_path='ffmpeg', background_color=(0, 0, 0), rgb=False, audio_path=None, codec='libx264', framerate=30, text='', text_color=(1, 1, 0), font_scale=1)

The VideoWriter class.

Description:

Provides a straightforward means of producing videos by providing a lightweight wrapper around the commonly used FFMPEG command-line tool. Is best used as a context manager as shown in the example below.

Example

Provided the ffmpeg executable is installed on the system, the user can create a video in the following way:

import cv2
import numpy as np
from scenepic import VideoWriter

with VideoWriter("example_video.mp4", (256, 256)) as video:
    angles = np.linspace(0, 2 * np.pi, 60, endpoint=False)
    for angle in angles:
        x = int(np.cos(angle) * 64 + 128)
        y = int(np.sin(angle) * 64 + 128)
        video.clear_frame()
        cv2.circle(video.frame, (x, y), 16, (0, 0, 255), -1)
        video.write_frame()

This will result in the following video:

_images/example_video.gif
clear_frame()

Clears the frame buffer, setting all pixels to the background color.

property frame: ndarray

Returns the frame buffer as a (H, W, 3) uint8 numpy array.

start()

Starts the video writing process.

No need to call this method manually if using VideoWriter as a context manager.

stop()

Stops the video writing process and closes the video file.

No need to call this method manually if using VideoWriter as a context manager.

property text: str

Text to burn into the frame.

property text_color: ndarray

The color of the burned text.

write_frame()

Write the frame buffer to the video.