madam.ffmpeg
module¶
-
class
madam.ffmpeg.
FFmpegMetadataProcessor
(config: Optional[Mapping[str, Any]] = None)[source]¶ Bases:
madam.core.MetadataProcessor
Represents a metadata processor that uses FFmpeg.
-
__init__
(config: Optional[Mapping[str, Any]] = None) → None[source]¶ Initializes a new FFmpegMetadataProcessor.
Parameters: config – Mapping with settings.
-
combine
(file: IO, metadata_by_type: Mapping[str, Mapping[KT, VT_co]]) → IO[source]¶ Returns a byte stream whose contents represent the specified file where the specified metadata was added.
Parameters: - metadata (Mapping) – Mapping of the metadata format to the metadata dict
- file (IO) – Container file
Returns: file-like object with combined content
Return type: IO
-
formats
¶ The metadata formats which are supported.
Returns: supported metadata formats Return type: set[str]
-
read
(file: IO) → Mapping[str, Mapping[KT, VT_co]][source]¶ Reads the file and returns the metadata.
The metadata that is returned is grouped by type. The keys are specified by
format
.Parameters: file (IO) – File-like object to be read Returns: Metadata contained in the file Return type: Mapping Raises: UnsupportedFormatError – if the data is corrupt or its format is not supported
-
-
class
madam.ffmpeg.
FFmpegProcessor
(config: Optional[Mapping[str, Any]] = None)[source]¶ Bases:
madam.core.Processor
Represents a processor that uses FFmpeg to read audio and video data.
The minimum version of FFmpeg required is v3.3.
-
__init__
(config: Optional[Mapping[str, Any]] = None) → None[source]¶ Initializes a new FFmpegProcessor.
Parameters: config – Mapping with settings. Raises: EnvironmentError – if the installed version of ffprobe does not match the minimum version requirement
-
can_read
(file: IO) → bool[source]¶ Returns whether the specified MIME type is supported by this processor.
Parameters: file (IO) – file-like object to be tested Returns: whether the data format of the specified file is supported or not Return type: bool
-
convert
(asset: madam.core.Asset, mime_type: Union[madam.mime.MimeType, str], video: Optional[Mapping[str, Any]] = None, audio: Optional[Mapping[str, Any]] = None, subtitle: Optional[Mapping[str, Any]] = None) → madam.core.Asset[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) – Asset whose contents will be converted
- mime_type (MimeType or str) – MIME type of the video container
- video (dict or None) – Dictionary with options for video streams.
- audio (dict or None) – Dictionary with options for audio streams.
- subtitle (dict or None) – Dictionary with the options for subtitle streams.
Returns: New asset with converted essence
Return type:
-
crop
(asset: madam.core.Asset, x: int, y: int, width: int, height: int) → madam.core.Asset[source]¶ Creates a cropped video asset whose essence is cropped to the specified rectangular area.
Parameters: Returns: New asset with cropped essence
Return type:
-
extract_frame
(asset: madam.core.Asset, mime_type: Union[madam.mime.MimeType, str], seconds: float = 0) → madam.core.Asset[source]¶ Creates a new image asset of the specified MIME type from the essence of the specified video asset.
Parameters: Returns: New image asset with converted essence
Return type:
-
read
(file: IO) → madam.core.Asset[source]¶ Returns an
Asset
object whose essence is identical to the contents of the specified file.Parameters: file (IO) – file-like object to be read Returns: Asset with essence Return type: Asset Raises: UnsupportedFormatError – if the specified data format is not supported
-
resize
(asset: madam.core.Asset, width: int, height: int) → madam.core.Asset[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: Returns: New asset with specified width and height
Return type:
-
rotate
(asset: madam.core.Asset, angle: float, expand: bool = False) → madam.core.Asset[source]¶ Creates an asset whose essence is rotated by the specified angle in degrees.
Parameters: Returns: New asset with rotated essence
Return type:
-