Coverage for pyguymer3/media/return_video_bit_depth.py: 50%
26 statements
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-08 18:47 +0000
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-08 18:47 +0000
1#!/usr/bin/env python3
3# Define function ...
4def return_video_bit_depth(
5 fname,
6 /,
7 *,
8 cwd = None,
9 debug = __debug__,
10 ensureNFC = True,
11 ffprobePath = None,
12 playlist = -1,
13 timeout = 60.0,
14):
15 # Import standard modules ...
16 import shutil
18 # Import sub-functions ...
19 from .__ffprobe__ import __ffprobe__
20 from .ffprobe import ffprobe
22 # **************************************************************************
24 # Try to find the paths if the user did not provide them ...
25 if ffprobePath is None:
26 ffprobePath = shutil.which("ffprobe")
27 assert ffprobePath is not None, "\"ffprobe\" is not installed"
29 # **************************************************************************
31 # Make sure that this fname/playlist combination is in the global dictionary ...
32 if fname not in __ffprobe__:
33 __ffprobe__[fname] = {}
34 if playlist not in __ffprobe__[fname]:
35 if debug:
36 print(f"INFO: Running ffprobe(\"{fname}\", {playlist:d}) ...")
37 __ffprobe__[fname][playlist] = ffprobe(
38 fname,
39 cwd = cwd,
40 ensureNFC = ensureNFC,
41 ffprobePath = ffprobePath,
42 playlist = playlist,
43 timeout = timeout,
44 )
46 # Loop over streams ...
47 for stream in __ffprobe__[fname][playlist]["streams"]:
48 # Skip stream if it is not video ...
49 if stream["codec_type"].strip().lower() != "video":
50 continue
52 # Return bit depth ...
53 if "bits_per_raw_sample" in stream:
54 return int(stream["bits_per_raw_sample"]) # [b]
56 # **************************************************************************
58 # Loop over streams ...
59 for stream in __ffprobe__[fname][playlist]["streams"]:
60 # Skip stream if it is not video ...
61 if stream["codec_type"].strip().lower() != "video":
62 continue
64 # Return bit depth ...
65 # HACK: As of 29/Nov/2023, "ffprobe" does not populate the standard
66 # "bits_per_raw_sample" field of HEVC "Main 10" videos.
67 if stream["codec_name"] == "hevc" and stream["profile"] == "Main 10":
68 return 10 # [b]
70 # Return bit depth ...
71 # HACK: As of 2/Dec/2023, "ffprobe" does not populate the standard
72 # "bits_per_raw_sample" field of VP9 "Profile 0" videos.
73 if stream["codec_name"] == "vp9" and stream["profile"] == "Profile 0":
74 return 8 # [b]
76 # **************************************************************************
78 # Return error ...
79 return -1 # [b]