madam.ffmpeg module

class madam.ffmpeg.FFmpegMetadataProcessor[source]

Bases: madam.core.MetadataProcessor

Represents a metadata processor that uses FFmpeg.

class madam.ffmpeg.FFmpegProcessor[source]

Bases: madam.core.Processor

Represents a processor that uses FFmpeg to read audio and video data.

The minimum version of FFmpeg required is v0.9.

convert(asset, mime_type, video=None, audio=None, subtitles=None)[source]

Creates a new asset of the specified MIME type from the essence of the specified asset.

Additional options can be specified for video, audio, and subtitle streams. Options are passed as dictionary instances and can contain various keys for each stream type.

Options for video streams:

  • codec – Processor-specific name of the video codec as string
  • bitrate – Target bitrate in kBit/s as float number

Options for audio streams:

  • codec – Processor-specific name of the audio codec as string
  • bitrate – Target bitrate in kBit/s as float number

Options for subtitle streams:

  • codec – Processor-specific name of the subtitle format as string
Parameters:
  • asset – Asset whose contents will be converted
  • mime_type – MIME type of the video container
  • video – Dictionary with options for video streams.
  • audio – Dictionary with options for audio streams.
  • subtitles – Dictionary with the options for subtitle streams.
Returns:

New asset with converted essence

extract_frame(asset, mime_type, seconds=0)[source]

Creates a new image asset of the specified MIME type from the essence of the specified video asset.

Parameters:
  • asset – Video asset which will serve as the source for the frame
  • mime_type (str) – MIME type of the source
  • seconds (float) – Offset of the frame in seconds
Returns:

New image asset with converted essence

resize(asset, width, height)[source]

Creates a new image or video asset of the specified width and height from the essence of the specified image or video asset.

Width and height must be positive numbers.

Parameters:
  • asset – Video asset that will serve as the source for the frame
  • width (int) – Width of the resized asset
  • height (int) – Height of the resized asset
Returns:

New asset with specified width and height

trim(asset, from_seconds=0, to_seconds=0)[source]

Creates a trimmed audio or video asset that only contains the data between from_seconds and to_seconds.

Parameters:
  • asset – Audio or video asset, which will serve as the source
  • from_seconds (float) – Start time of the clip in seconds
  • to_seconds (float) – End time of the clip in seconds
Returns:

New asset with trimmed essence