ffprobewrapper

This module contains the following classes:

exception aeneas.ffprobewrapper.FFPROBEParsingError[source]

Error raised when the call to ffprobe does not produce any output.

exception aeneas.ffprobewrapper.FFPROBEPathError[source]

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

New in version 1.4.1.

exception aeneas.ffprobewrapper.FFPROBEUnsupportedFormatError[source]

Error raised when ffprobe cannot decode the format of the given file.

class aeneas.ffprobewrapper.FFPROBEWrapper(logger=None, rconf=None)[source]

Wrapper around ffprobe to read the properties of an audio file.

It will perform a call like:

$ ffprobe -select_streams a -show_streams /path/to/audio/file.mp3

and it will parse the first [STREAM] element returned:

[STREAM]
index=0
codec_name=mp3
codec_long_name=MP3 (MPEG audio layer 3)
profile=unknown
codec_type=audio
codec_time_base=1/44100
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
sample_fmt=s16p
sample_rate=44100
channels=1
channel_layout=mono
bits_per_sample=0
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/14112000
start_pts=0
start_time=0.000000
duration_ts=1545083190
duration=109.487188
bit_rate=128000
max_bit_rate=N/A
bits_per_raw_sample=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=0
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
[/STREAM]
Parameters:
FFPROBE_PARAMETERS = ['-select_streams', 'a', '-show_streams']

ffprobe parameters

STDERR_DURATION_REGEX = re.compile('Duration: ([0-9]*):([0-9]*):([0-9]*)\\.([0-9]*)')

Regex to match ffprobe stderr duration values

STDOUT_BEGIN_STREAM = '[STREAM]'

ffprobe stdout begin stream tag

STDOUT_CHANNELS = 'channels'

ffprobe stdout channels keyword

STDOUT_CODEC_NAME = 'codec_name'

ffprobe stdout codec name (format) keyword

STDOUT_DURATION = 'duration'

ffprobe stdout duration keyword

STDOUT_END_STREAM = '[/STREAM]'

ffprobe stdout end stream tag

STDOUT_SAMPLE_RATE = 'sample_rate'

ffprobe stdout sample rate keyword

read_properties(audio_file_path)[source]

Read the properties of an audio file and return them as a dictionary.

Example:

d["index"]=0
d["codec_name"]=mp3
d["codec_long_name"]=MP3 (MPEG audio layer 3)
d["profile"]=unknown
d["codec_type"]=audio
d["codec_time_base"]=1/44100
d["codec_tag_string"]=[0][0][0][0]
d["codec_tag"]=0x0000
d["sample_fmt"]=s16p
d["sample_rate"]=44100
d["channels"]=1
d["channel_layout"]=mono
d["bits_per_sample"]=0
d["id"]=N/A
d["r_frame_rate"]=0/0
d["avg_frame_rate"]=0/0
d["time_base"]=1/14112000
d["start_pts"]=0
d["start_time"]=0.000000
d["duration_ts"]=1545083190
d["duration"]=109.487188
d["bit_rate"]=128000
d["max_bit_rate"]=N/A
d["bits_per_raw_sample"]=N/A
d["nb_frames"]=N/A
d["nb_read_frames"]=N/A
d["nb_read_packets"]=N/A
d["DISPOSITION:default"]=0
d["DISPOSITION:dub"]=0
d["DISPOSITION:original"]=0
d["DISPOSITION:comment"]=0
d["DISPOSITION:lyrics"]=0
d["DISPOSITION:karaoke"]=0
d["DISPOSITION:forced"]=0
d["DISPOSITION:hearing_impaired"]=0
d["DISPOSITION:visual_impaired"]=0
d["DISPOSITION:clean_effects"]=0
d["DISPOSITION:attached_pic"]=0
Parameters:audio_file_path (string) – the path of the audio file to analyze
Return type:dict
Raises:TypeError: if audio_file_path is None
Raises:OSError: if the file at audio_file_path cannot be read
Raises:FFPROBEParsingError: if the call to ffprobe does not produce any output
Raises:FFPROBEPathError: if the path to the ffprobe executable cannot be called
Raises:FFPROBEUnsupportedFormatError: if the file has a format not supported by ffprobe