Media

class audformat.Media(type='other', *, format=None, sampling_rate=None, channels=None, bit_depth=None, video_fps=None, video_resolution=None, video_channels=None, video_depth=None, description=None, meta=None)[source]

Media information.

File format is always converted to lower case.

Parameters:
  • type (str) – media type, see audformat.define.MediaType for available media types

  • format (str) – file format (e.g. ‘wav’, ‘flac’, ‘mp4’)

  • sampling_rate (int) – audio sampling rate in Hz

  • channels (int) – number of audio channels

  • bit_depth (int) – audio bit depth

  • video_fps (int) – video rate in frames per seconds

  • video_resolution (Sequence[int]) – video resolution in pixels (e.g. [800, 600])

  • video_channels (int) – number of channels per pixel (e.g. 3 for RGB)

  • video_depth (int) – number of bits per video channel

  • description (str) – media description

  • meta (dict) – additional meta fields

Raises:

BadValueError – if an invalid type is passed

Examples

>>> Media(
...     type=define.MediaType.AUDIO,
...     format="wav",
...     sampling_rate=16000,
...     channels=2,
... )
{type: audio, format: wav, channels: 2, sampling_rate: 16000}

__eq__()

Media.__eq__(other)

Return self==value.

Return type:

bool

bit_depth

Media.bit_depth

Audio bit depth

channels

Media.channels

Audio channels

description

Media.description

Description

dump()

Media.dump(stream=None, indent=2)

Serialize object to YAML.

Parameters:
  • stream – file-like object. If None serializes to string

  • indent (int) – indent

Return type:

str

Returns:

YAML string

format

Media.format

File format

from_dict()

Media.from_dict(d, ignore_keys=None)

Deserialize object from dictionary.

Parameters:
  • d (dict) – dictionary of class variables to assign

  • ignore_keys (Sequence[str]) – variables listed here will be ignored

meta

Media.meta

Dictionary with meta fields

sampling_rate

Media.sampling_rate

Audio sampling rate in Hz

to_dict()

Media.to_dict()

Serialize object to dictionary.

Return type:

dict

Returns:

dictionary with attributes

type

Media.type

Media type

video_channels

Media.video_channels

Video channels per pixel

video_depth

Media.video_depth

Video bit depth

video_fps

Media.video_fps

Video frames per second

video_resolution

Media.video_resolution

Video resolution