4.6.6 pde.tools.ffmpeg module

Functions for interacting with FFmpeg.

FFmpegFormat

Defines a FFmpeg format used for storing field data in a video.

formats

Dict of pre-defined FFmpegFormat formats.

find_format

Find a defined FFmpegFormat that satisifies the requirements.

class FFmpegFormat(pix_fmt_file, pix_fmt_data, channels, bits_per_channel, dtype, codec='ffv1')[source]

Bases: object

Defines a FFmpeg format used for storing field data in a video.

Note

All pixel formats supported by FFmpeg can be obtained by running ffmpeg -pix_fmts. However, not all pixel formats are supported by all codecs. Supported pixel formats are listed in the output of ffmpeg -h encoder=<ENCODER>, where <ENCODER> is one of the encoders listed in ffmpeg -codecs.

Parameters:
bits_per_channel: int

number of bits per color channel in this pixel format

Type:

int

property bytes_per_channel: int

number of bytes per color channel.

Type:

Int

channels: int

number of color channels in this pixel format

Type:

int

codec: str = 'ffv1'

name of the codec that supports this pixel format

Type:

str

data_from_frame(frame_data)[source]

Converts data stored in a color channel to normalized data.

Parameters:

frame_data (ndarray)

data_to_frame(normalized_data)[source]

Converts normalized data to data being stored in a color channel.

Parameters:

normalized_data (ndarray)

Return type:

ndarray

dtype: dtype[Any] | None | type[Any] | _SupportsDType[dtype[Any]] | str | tuple[Any, int] | tuple[Any, SupportsIndex | Sequence[SupportsIndex]] | list[Any] | _DTypeDict | tuple[Any, Any]

Numpy dtype corresponding to the data of a single channel.

property max_value: float | int

Maximal value stored in a color channel.

pix_fmt_data: str

name of the pixel format used in the frame data

Type:

str

pix_fmt_file: str

name of the pixel format used in the codec

Type:

str

find_format(channels, bits_per_channel=8)[source]

Find a defined FFmpegFormat that satisifies the requirements.

Parameters:
  • channels (int) – Minimal number of color channels

  • bits_per_channel (int) – Minimal number of bits per channel

Returns:

Identifier for a format that satisifies the requirements (but might have more channels or more bits per channel then requested. None is returned if no format can be identified.

Return type:

str

formats = {'gbrap16le': FFmpegFormat(pix_fmt_file='gbrap16le', pix_fmt_data='gbrap16le', channels=4, bits_per_channel=16, dtype=dtype('uint16'), codec='ffv1'), 'gbrp16le': FFmpegFormat(pix_fmt_file='gbrp16le', pix_fmt_data='gbrp16le', channels=3, bits_per_channel=16, dtype=dtype('uint16'), codec='ffv1'), 'gray': FFmpegFormat(pix_fmt_file='gray', pix_fmt_data='gray', channels=1, bits_per_channel=8, dtype=<class 'numpy.uint8'>, codec='ffv1'), 'gray16le': FFmpegFormat(pix_fmt_file='gray16le', pix_fmt_data='gray16le', channels=1, bits_per_channel=16, dtype=dtype('uint16'), codec='ffv1'), 'rgb24': FFmpegFormat(pix_fmt_file='rgb24', pix_fmt_data='rgb24', channels=3, bits_per_channel=8, dtype=<class 'numpy.uint8'>, codec='ffv1'), 'rgb32': FFmpegFormat(pix_fmt_file='rgb32', pix_fmt_data='rgb32', channels=4, bits_per_channel=8, dtype=<class 'numpy.uint8'>, codec='ffv1')}

Dict of pre-defined FFmpegFormat formats.