ffmpegwrapper

This module contains the following classes:

exception aeneas.ffmpegwrapper.FFMPEGPathError[source]

Error raised when the path to ffmpeg is not a valid executable.

New in version 1.4.1.

class aeneas.ffmpegwrapper.FFMPEGWrapper(logger=None, rconf=None)[source]

A wrapper around ffmpeg to convert audio files.

In abstract terms, it will perform a call like:

$ ffmpeg -i /path/to/input.mp3 [parameters] /path/to/output.wav
Parameters:
FFMPEG_FORMAT_WAVE = ['-f', 'wav']

Single parameter for ffmpeg: produce output in wav format (must be the second to last argument to ffmpeg, just before path of the output file)

FFMPEG_MONO = ['-ac', '1']

Single parameter for ffmpeg: mono (1 channel)

FFMPEG_OVERWRITE = ['-y']

Single parameter for ffmpeg: force overwriting output file

FFMPEG_PARAMETERS_DEFAULT = ['-ac', '1', '-ar', '16000', '-y', '-map_metadata', '-1', '-flags', '+bitexact', '-f', 'wav']

Default set of parameters for ffmpeg

FFMPEG_PARAMETERS_MAP = {8000: ['-ac', '1', '-ar', '8000', '-y', '-map_metadata', '-1', '-flags', '+bitexact', '-f', 'wav'], 16000: ['-ac', '1', '-ar', '16000', '-y', '-map_metadata', '-1', '-flags', '+bitexact', '-f', 'wav'], 22050: ['-ac', '1', '-ar', '22050', '-y', '-map_metadata', '-1', '-flags', '+bitexact', '-f', 'wav'], 44100: ['-ac', '1', '-ar', '44100', '-y', '-map_metadata', '-1', '-flags', '+bitexact', '-f', 'wav'], 48000: ['-ac', '1', '-ar', '48000', '-y', '-map_metadata', '-1', '-flags', '+bitexact', '-f', 'wav']}

Map sample rate to parameter list

FFMPEG_PARAMETERS_SAMPLE_16000 = ['-ac', '1', '-ar', '16000', '-y', '-map_metadata', '-1', '-flags', '+bitexact', '-f', 'wav']

Set of parameters for ffmpeg with 16000 Hz sampling

FFMPEG_PARAMETERS_SAMPLE_22050 = ['-ac', '1', '-ar', '22050', '-y', '-map_metadata', '-1', '-flags', '+bitexact', '-f', 'wav']

Set of parameters for ffmpeg with 22050 Hz sampling

FFMPEG_PARAMETERS_SAMPLE_44100 = ['-ac', '1', '-ar', '44100', '-y', '-map_metadata', '-1', '-flags', '+bitexact', '-f', 'wav']

Set of parameters for ffmpeg with 44100 Hz sampling

FFMPEG_PARAMETERS_SAMPLE_48000 = ['-ac', '1', '-ar', '48000', '-y', '-map_metadata', '-1', '-flags', '+bitexact', '-f', 'wav']

Set of parameters for ffmpeg with 48000 Hz sampling

FFMPEG_PARAMETERS_SAMPLE_8000 = ['-ac', '1', '-ar', '8000', '-y', '-map_metadata', '-1', '-flags', '+bitexact', '-f', 'wav']

Set of parameters for ffmpeg with 8000 Hz sampling

FFMPEG_PARAMETERS_SAMPLE_KEEP = ['-ac', '1', '-y', '-map_metadata', '-1', '-flags', '+bitexact', '-f', 'wav']

Set of parameters for ffmpeg without changing the sampling rate

FFMPEG_PLAIN_HEADER = ['-map_metadata', '-1', '-flags', '+bitexact']

Single parameter for ffmpeg: generate WAVE header without extra chunks (e.g., the INFO chunk)

FFMPEG_SAMPLE_16000 = ['-ar', '16000']

Single parameter for ffmpeg: 16000 Hz sampling

FFMPEG_SAMPLE_22050 = ['-ar', '22050']

Single parameter for ffmpeg: 22050 Hz sampling

FFMPEG_SAMPLE_44100 = ['-ar', '44100']

Single parameter for ffmpeg: 44100 Hz sampling

FFMPEG_SAMPLE_48000 = ['-ar', '48000']

Single parameter for ffmpeg: 48000 Hz sampling

FFMPEG_SAMPLE_8000 = ['-ar', '8000']

Single parameter for ffmpeg: 8000 Hz sampling

FFMPEG_STEREO = ['-ac', '2']

Single parameter for ffmpeg: stereo (2 channels)

convert(input_file_path, output_file_path, head_length=None, process_length=None)[source]

Convert the audio file at input_file_path into output_file_path, using the parameters set in the constructor or through the parameters property.

You can skip the beginning of the audio file by specifying head_length seconds to skip (if it is None, start at time zero), and you can specify to convert only process_length seconds (if it is None, process the entire input file length).

By specifying both head_length and process_length, you can skip a portion at the beginning and at the end of the original input file.

Parameters:
  • input_file_path (string) – the path of the audio file to convert
  • output_file_path (string) – the path of the converted audio file
  • head_length (float) – skip these many seconds from the beginning of the audio file
  • process_length (float) – process these many seconds of the audio file
Raises:

FFMPEGPathError: if the path to the ffmpeg executable cannot be called

Raises:

OSError: if input_file_path does not exist or output_file_path cannot be written