Inspecting media files¶
A wrapper around ffprobe that gathers and makes available information about the inspected media file or stream in a Pythonic way.
-
class
MediaInfo(source)¶ Bases:
objectRepresents all available information about the inspected media file or stream.
- Attributes
The
avtk.backends.ffmpeg.shortcuts.inspect()function is a simple wrapper around the MediaInfo constructor.Example:
>>> info = MediaInfo(test-media/video/sintel.mkv')
-
audio_streams¶ List of audio streams in the media object
-
video_streams¶ List of video streams in the media object
-
subtitle_streams¶ List of subtitle streams in the media objects
-
has_audio¶ Whether there is at least one audio stream present
-
has_video¶ Whether there is at least one video stream present
-
has_subtitles¶ Whether there is at least one subtitles stream present
-
class
Codec(raw)¶ Bases:
objectInformation about the codec used in a stream.
- Attributes
name (str) - codec (short) name
type (str) - codec type, one of
TYPE_AUDIO,TYPE_VIDEO,TYPE_SUBTITLEorTYPE_DATAdescription (str) - codec description (long name)
profile (str or None) - profile used, if applicable
-
TYPE_AUDIO= 'audio'¶ Audio codec
-
TYPE_VIDEO= 'video'¶ Video codec
-
TYPE_SUBTITLE= 'subtitle'¶ Subtitles codec
-
TYPE_DATA= 'data'¶ Raw (unknown) data
-
class
Stream(raw)¶ Bases:
objectInformation about a stream in a media file.
This is a base class handling information common to most stream types. Streams returned in
MediaInfoobject will be one of the subclasses holding more information.- Subclasses
VideoStream- for video streamsAudioStream- for audio streamsSubtitleStream- for subtitle streamsDataStream- raw or unrecognized data
- Attributes
codec (
Codec) - codec used in this streamindex (int) - 0-based index of this stream in the container
time_base (Fraction) - unit of time for timestamp calculations
nb_frames (int or None) - total number of frames in the stream
start_time (timedelta or None) - start timestamp of the stream
duration (timedelta or None) - duration of the stream
duration_ts (int or None) - duration in time_base units
bit_rate (int or None) - bit rate of the stream
tags (dict) - stream tags, if any
-
class
VideoStream(raw)¶ Bases:
avtk.backends.ffmpeg.probe.StreamHolds video-specific information about a stream.
- Attributes
width (int) - display width, in pixels
height (int) - display height, in pixels
display_aspect_ratio (str) - aspect ratio, in ‘W:H’ format
pix_fmt (str) - image pixel format name
has_b_frames (int) - how many frames might need reordering for B-frame decoding or 0 if B-frames are not used
For a list of all known pixel formats and more information about them, run
ffmpeg -pix_fmts.
-
class
AudioStream(raw)¶ Bases:
avtk.backends.ffmpeg.probe.StreamHolds video-specific information about a stream.
- Attributes
channels (int) - number of channels
channel_layout (str) - channel layout
sample_fmt (str) - sample format
sample_rate (int) - audio sample rate in Hz
For a list of all known channel names and standard layouts, run
ffmpeg -layouts. To get a list of all known sample formats, runffmpeg -sample_fmts.
-
class
SubtitleStream(raw)¶ Bases:
avtk.backends.ffmpeg.probe.StreamHolds information about a subtitle stream.
- Attributes
language (str) - language
-
class
DataStream(raw)¶ Bases:
avtk.backends.ffmpeg.probe.StreamHolds information about unknown or raw data stream.
- Attributes
raw (dict) - raw data parsed from
ffprobe
-
class
Format(raw)¶ Bases:
objectInformation about the container format.
- Attributes
name (str) - format name, or multiple comma-separated format names (aliases)
names (list(str)) - list of format names
description (str) - format description (long name)
start_time (timedelta or None) - start timestamp of the entire media object
duration (timedelta or None) - duration of the entire media object
size (int or None) - size in bytes, if known
bit_rate (int or None) - bit rate of the entire media object
tags (dict) - stream tags, if any