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 USM decryption key. Either int64 or a hex string. Defaults to None.

get_audios(hca_key=-1, hca_subkey=0) List[ADXCodec | HCACodec][source]

Create a list of audio codecs from the available streams.

Parameters:
  • hca_key (int, optional) – The HCA decryption key. Either int64 or a hex string. Defaults to -1, in which case the key for USM (if used) would also be used for HCA decryption.

  • hca_subkey (int, optional) – The HCA decryption subkey. Either int64 or a hex string. Defaults to 0.

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)[source]

Bases: USMCrypt

Use this class to build USM files.

__init__(key=None) None[source]

Initialize the USMBuilder from set source files.

Parameters:

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

Note

For USM with key set, HCA audio streams usually use the same key for encryption. Thus when adding HCA audio streams, make sure your HCACodec is initialized with a key itself.

For ADXCodec, this will be ALWAYS encrypted if the USMBuilder is initialized with a key. No further configuration is needed.

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

save(filepath: str) None[source]

Saves the built USM to a file.

Parameters:

filepath (str) – The path to save the USM file to.

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.