ffmpegwrapper¶
This module contains the following classes:
FFMPEGWrapper, a wrapper aroundffmpegto convert audio files;FFMPEGPathError, representing a failure to locate theffmpegexecutable.
-
exception
aeneas.ffmpegwrapper.FFMPEGPathError[source]¶ Error raised when the path to
ffmpegis not a valid executable.New in version 1.4.1.
-
class
aeneas.ffmpegwrapper.FFMPEGWrapper(logger=None, rconf=None)[source]¶ A wrapper around
ffmpegto convert audio files.In abstract terms, it will perform a call like:
$ ffmpeg -i /path/to/input.mp3 [parameters] /path/to/output.wav
Parameters: - rconf (
RuntimeConfiguration) – a runtime configuration - logger (
Logger) – the logger object
-
FFMPEG_FORMAT_WAVE= ['-f', 'wav']¶ Single parameter for
ffmpeg: produce output inwavformat (must be the second to last argument toffmpeg, 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
ffmpegwith 16000 Hz sampling
-
FFMPEG_PARAMETERS_SAMPLE_22050= ['-ac', '1', '-ar', '22050', '-y', '-map_metadata', '-1', '-flags', '+bitexact', '-f', 'wav']¶ Set of parameters for
ffmpegwith 22050 Hz sampling
-
FFMPEG_PARAMETERS_SAMPLE_44100= ['-ac', '1', '-ar', '44100', '-y', '-map_metadata', '-1', '-flags', '+bitexact', '-f', 'wav']¶ Set of parameters for
ffmpegwith 44100 Hz sampling
-
FFMPEG_PARAMETERS_SAMPLE_48000= ['-ac', '1', '-ar', '48000', '-y', '-map_metadata', '-1', '-flags', '+bitexact', '-f', 'wav']¶ Set of parameters for
ffmpegwith 48000 Hz sampling
-
FFMPEG_PARAMETERS_SAMPLE_8000= ['-ac', '1', '-ar', '8000', '-y', '-map_metadata', '-1', '-flags', '+bitexact', '-f', 'wav']¶ Set of parameters for
ffmpegwith 8000 Hz sampling
-
FFMPEG_PARAMETERS_SAMPLE_KEEP= ['-ac', '1', '-y', '-map_metadata', '-1', '-flags', '+bitexact', '-f', 'wav']¶ Set of parameters for
ffmpegwithout 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_pathintooutput_file_path, using the parameters set in the constructor or through theparametersproperty.You can skip the beginning of the audio file by specifying
head_lengthseconds to skip (if it isNone, start at time zero), and you can specify to convert onlyprocess_lengthseconds (if it isNone, process the entire input file length).By specifying both
head_lengthandprocess_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 theffmpegexecutable cannot be calledRaises: OSError: if
input_file_pathdoes not exist oroutput_file_pathcannot be written
- rconf (