Codecs, encoders and formats support in FFmpeg

The avtk.backends.ffmpeg.cap module can be used to discover versions of the available ffmpeg and ffprobe command-line tools, and list codecs, encoders and formats they support.

Example usage:

>>> from avtk.backends.ffmpeg import cap

>>> cap.get_ffmpeg_version()
'4.1.2'
>>> cap.get_ffprobe_version()
'4.1.2'
>>> 'vp9' in cap.get_available_codecs()
True
>>> 'libx264' in cap.get_availble_encoders()
True
>>> 'webm' in cap.get_available_formats()
True
class Codec(name, type, can_encode, can_decode, can_all_i, lossy, lossless, desc)

Describes a codec known to FFmpeg

This doesn’t mean it can be encoded or decoded. For encoding support, look at Encoder.

Attributes:

  • name - Codec (short) name

  • description - Codec description (long name)

  • type - Codec type, one of TYPE_AUDIO, TYPE_VIDEO or TYPE_SUBTITLE

  • can_encode - Whether ffmpeg can encode to this codec

  • can_decode - Whether ffmpeg can decode this codec

  • can_all_i - Whether the codec is all-intra (can have only I frames)

  • lossy - Whether the codec supports lossy encoding

  • lossless - Whether the codec supports lossless encoding

TYPE_AUDIO = 'audio'

Audio codec

TYPE_VIDEO = 'video'

Video codec

TYPE_SUBTITLE = 'subtitle'

Subtitle codec

class Encoder(name, type, desc)

Describes an available encoder

Attributes:

class Format(name, can_mux, can_demux, desc)

Describes a format known to FFmpeg

Attributes:

  • name - Format name

  • description - Format description (long name)

  • can_mux - Whether ffmpeg can mux (pack) to this format

  • can_demux - Whether ffmpeg can demux (unpack) this format

get_available_codecs()

Discovers and returns a list of available codecs.

Result is cached between runs so the results will only be discovered once.

Returns

A list of available codecs

Return type

list(Codec)

Raises

ValueError – if ffmpeg utility cannot be found

get_available_formats()

Discovers and returns a list of available formats

Result is cached between runs so the results will only be discovered once.

Returns

A list of available formats

Return type

list(Format)

Raises

ValueError – if ffmpeg utility cannot be found

get_available_encoders()

Discovers and returns a list of available encoders

Result is cached between runs so the results will only be discovered once.

Returns

A list of available encoders

Return type

list(Encoder)

Raises

ValueError – if ffmpeg utility cannot be found

get_ffmpeg_version()

Returns version of installed ffmpeg tool

Returns

FFmpeg version in ‘x.y.z’ format

Return type

str

Raises

ValueError – if ffmpeg utility cannot be found

get_ffprobe_version()

Returns version of installed ffprobe tool

Returns

FFprobe version in ‘x.y.z’ format

Return type

str

Raises

ValueError – if ffprobe utility cannot be found