ffmpeg

exception mautrix.util.ffmpeg.ConverterError

Bases: ChildProcessError

exception mautrix.util.ffmpeg.NotInstalledError

Bases: mautrix.util.ffmpeg.ConverterError

__init__()
Return type

None

async mautrix.util.ffmpeg.convert_bytes(data, output_extension, input_args=None, output_args=None, input_mime=None)

Convert media file data using ffmpeg.

Parameters
  • data (bytes) – The bytes of the file to convert.

  • output_extension (str) – The extension that the output file should be.

  • input_args (Optional[Iterable[str]]) – Arguments to tell ffmpeg how to parse the input file.

  • output_args (Optional[Iterable[str]]) – Arguments to tell ffmpeg how to convert the file to reach the wanted output.

  • input_mime (Optional[str]) – The mime type of the input data. If not specified, will be guessed using magic.

Returns

The converted file as bytes.

Raises

ConverterError – if ffmpeg returns a non-zero exit code.

Return type

bytes

async mautrix.util.ffmpeg.convert_path(input_file, output_extension, input_args=None, output_args=None, remove_input=False, output_path_override=None)

Convert a media file on the disk using ffmpeg.

Parameters
  • input_file (os.PathLike[str] | str) – The full path to the file.

  • output_extension (str | None) – The extension that the output file should be.

  • input_args (Optional[Iterable[str]]) – Arguments to tell ffmpeg how to parse the input file.

  • output_args (Optional[Iterable[str]]) – Arguments to tell ffmpeg how to convert the file to reach the wanted output.

  • remove_input (bool) – Whether the input file should be removed after converting. Not compatible with output_path_override.

  • output_path_override (Optional[Union[os.PathLike[str], str]]) – A custom output path to use (instead of using the input path with a different extension).

Returns

The path to the converted file, or the stdout if output_path_override was set to -.

Raises

ConverterError – if ffmpeg returns a non-zero exit code.

Return type

pathlib.Path | bytes