USM (Sofdec 2) Video Codecs

class PyCriCodecsEx.usm.FFmpegCodec(stream: str | bytes)[source]

Bases: object

Base codec for FFMpeg-based Video streams

__init__(stream: str | bytes)[source]

Initialize FFmpegCodec with a media stream, gathering metadata and frame info.

Parameters:

stream (str | bytes) – The media stream to process.

Note

A temp file maybe created for probing only. Which will be deleted after use.

frames()[source]

Generator of [frame data, frame dict, is keyframe, duration]

save(filepath: str)[source]

Saves the underlying video stream to a file.

property avg_framerate

Average framerate

property framerate

Running framerate (max frame rate)

class PyCriCodecsEx.usm.H264Codec(filename: str | bytes)[source]

Bases: FFmpegCodec

H264 Video stream codec.

Only streams with .h264 containers are supported.

__init__(filename: str | bytes)[source]

Initialize FFmpegCodec with a media stream, gathering metadata and frame info.

Parameters:

stream (str | bytes) – The media stream to process.

Note

A temp file maybe created for probing only. Which will be deleted after use.

class PyCriCodecsEx.usm.MPEG1Codec(stream: str | bytes)[source]

Bases: FFmpegCodec

MPEG1 Video stream codec.

Only streams with .mpeg1 containers are supported.

__init__(stream: str | bytes)[source]

Initialize FFmpegCodec with a media stream, gathering metadata and frame info.

Parameters:

stream (str | bytes) – The media stream to process.

Note

A temp file maybe created for probing only. Which will be deleted after use.

class PyCriCodecsEx.usm.USM(filename: str | BinaryIO, key: str | int = None)[source]

Bases: USMCrypt

Use this class to extract infromation and data from a USM file.

__init__(filename: str | BinaryIO, key: str | int = None)[source]

Loads a USM file into memory and prepares it for processing.

Parameters:
  • filename (str) – The path to the USM file.

  • key (str, optional) – The decryption key. Either int64 or a hex string. Defaults to None.

get_audios() List[ADXCodec | HCACodec][source]

Create a list of audio codecs from the available streams.

get_video() VP9Codec | H264Codec | MPEG1Codec[source]

Create a video codec from the available streams.

NOTE: A temporary file may be created with this process to determine the stream information.

property streams

Generator of Tuple[Stream Type (“@SFV”, “@SFA”), File name, Raw stream data]

class PyCriCodecsEx.usm.USMBuilder(key=None, encrypt_audio=False)[source]

Bases: USMCrypt

Use this class to build USM files.

__init__(key=None, encrypt_audio=False) None[source]

Initialize the USMBuilder from set source files.

Parameters:
  • key (str | int, optional) – The encryption key. Either int64 or a hex string. Defaults to None.

  • encrypt_audio (bool, optional) – Whether to also encrypt the audio. Defaults to False.

add_audio(audio: ADXCodec | HCACodec)[source]

Append the audio stream(s) from the specified audio file(s).

Parameters:

audio (ADXCodec | HCACodec) – The path(s) to the audio file(s).

add_video(video: str | H264Codec | VP9Codec | MPEG1Codec)[source]

Sets the video stream from the specified video file.

USMs only support one video stream. Consecutive calls to this method will replace the existing video stream.

When video is str - it will be treated as a file path. The video source format will be used to map accordingly to the ones Sofdec use.
  • MPEG1 (with M1V container): MPEG1 Codec (Sofdec Prime)

  • H264 (with H264 container): H264 Codec

  • VP9 (with IVF container): VP9 Codec

Parameters:

video (str | FFmpegCodec) – The path to the video file or an FFmpegCodec instance.

build() bytes[source]

Build the USM payload

class PyCriCodecsEx.usm.USMCrypt[source]

Bases: object

USM related crypto functions

class PyCriCodecsEx.usm.VP9Codec(filename: str | bytes)[source]

Bases: FFmpegCodec

VP9 Video stream codec.

Only streams with .ivf containers are supported.

__init__(filename: str | bytes)[source]

Initialize FFmpegCodec with a media stream, gathering metadata and frame info.

Parameters:

stream (str | bytes) – The media stream to process.

Note

A temp file maybe created for probing only. Which will be deleted after use.