cutcutcodec.core.analysis.ffprobe.get_metadata

cutcutcodec.core.analysis.ffprobe.get_metadata(filename: Path | str | bytes, ignore_errors=False) dict[str][source]

Call ffprobe and parse the result as a dictionary.

Parameters

filenamepathlike

The pathlike of the file containing streams.

ignore_errorsboolean, default=False

If True, returns an empty dict rather than throwing an exception if invalid data are detected.

Returns

metadatadict

All the metadata containing in the container and each streams.

Examples

>>> from pprint import pprint
>>> from cutcutcodec.core.analysis.ffprobe import get_metadata
>>> from cutcutcodec.utils import get_project_root
>>> media = get_project_root() / "media" / "video" / "intro.webm"
>>> pprint(get_metadata(media))  
{'format': {'bit_rate': '401541',
            'duration': '9.891000',
            'filename': '.../media/video/intro.webm',
            'format_long_name': 'Matroska / WebM',
            'format_name': 'matroska,webm',
            'nb_programs': 0,
            'nb_stream_groups': 0,
            'nb_streams': 4,
            'probe_score': 100,
            'size': '496456',
            'start_time': '0.000000',
            'tags': {'COMPATIBLE_BRANDS': 'isomiso2avc1mp41',
                     'ENCODER': 'Lavf60.16.100',
                     'MAJOR_BRAND': 'isom',
                     'MINOR_VERSION': '512'}},
 'streams': [{'avg_frame_rate': '30000/1001',
              'chroma_location': 'left',
              'codec_long_name': 'Google VP9',
              'codec_name': 'vp9',
              'codec_tag': '0x0000',
              'codec_tag_string': '[0][0][0][0]',
              'codec_type': 'video',
              'coded_height': 720,
              'coded_width': 1280,
              'color_primaries': 'bt709',
              'color_range': 'tv',
              'color_space': 'bt709',
              'color_transfer': 'bt709',
              'display_aspect_ratio': '16:9',
              'disposition': {'attached_pic': 0,
                              'captions': 0,
                              ...
                              'timed_thumbnails': 0,
                              'visual_impaired': 0},
              'field_order': 'progressive',
              'has_b_frames': 0,
              'height': 720,
              'index': 0,
              'level': -99,
              'pix_fmt': 'yuv420p',
              'profile': 'Profile 0',
              'r_frame_rate': '30000/1001',
              'refs': 1,
              'sample_aspect_ratio': '1:1',
              'start_pts': 0,
              'start_time': '0.000000',
              'tags': {'DURATION': '00:00:09.809000000',
                       'ENCODER': 'Lavc60.31.102 libvpx-vp9',
                       'HANDLER_NAME': 'ISO Media file produced by Google Inc.',
                       'VENDOR_ID': '[0][0][0][0]',
                       'title': '1280x720'},
              'time_base': '1/1000',
              'width': 1280},
             ...
             {'avg_frame_rate': '0/0',
              'bits_per_sample': 0,
              'channel_layout': 'mono',
              'channels': 1,
              'codec_long_name': 'Vorbis',
              'codec_name': 'vorbis',
              'codec_tag': '0x0000',
              'codec_tag_string': '[0][0][0][0]',
              'codec_type': 'audio',
              'disposition': {'attached_pic': 0,
                              'captions': 0,
                              ...
                              'timed_thumbnails': 0,
                              'visual_impaired': 0},
              'extradata_size': 3340,
              'index': 3,
              'initial_padding': 0,
              'r_frame_rate': '0/0',
              'sample_fmt': 'fltp',
              'sample_rate': '22050',
              'start_pts': 0,
              'start_time': '0.000000',
              'tags': {'DURATION': '00:00:09.891000000',
                       'ENCODER': 'Lavc59.37.100 libvorbis',
                       'HANDLER_NAME': 'ISO Media file produced by Google Inc.',
                       'VENDOR_ID': '[0][0][0][0]',
                       'language': 'eng',
                       'title': 'mono'},
              'time_base': '1/1000'}]}
>>>