Skip to content

zimscraperlib.video.probing

Functions:

get_media_info

get_media_info(src_path: Path)

dict of file's details from ffprobe

codecs: list of codecs in use duration: file duration in seconds bitrate: file's main bitrate

Source code in src/zimscraperlib/video/probing.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def get_media_info(src_path: pathlib.Path):
    """dict of file's details from ffprobe

    codecs: list of codecs in use
    duration: file duration in seconds
    bitrate: file's main bitrate"""

    args = [
        "/usr/bin/env",
        "ffprobe",
        "-i",
        f"file:{src_path}",
        "-show_entries",
        "stream=codec_name",
        "-show_entries",
        "format=duration,bit_rate",
        "-v",
        "quiet",
        "-of",
        "csv",
    ]
    ffprobe = subprocess.run(
        args,
        capture_output=True,
        text=True,
        check=False,
    )
    result = ffprobe.stdout.strip().split("\n")
    streams = result[:-1]
    codecs = [stream.split(",")[-1] for stream in streams]
    format_info = result[-1].split(",")[1:]
    return {
        "codecs": codecs,
        "duration": int(format_info[0].split(".")[0]),
        "bitrate": int(format_info[1]),
    }