Coverage for pyguymer3/media/return_video_height.py: 64%
22 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_height(
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
21 from .return_video_rotation import return_video_rotation
23 # **************************************************************************
25 # Try to find the paths if the user did not provide them ...
26 if ffprobePath is None:
27 ffprobePath = shutil.which("ffprobe")
28 assert ffprobePath is not None, "\"ffprobe\" is not installed"
30 # **************************************************************************
32 # Make sure that this fname/playlist combination is in the global dictionary ...
33 if fname not in __ffprobe__:
34 __ffprobe__[fname] = {}
35 if playlist not in __ffprobe__[fname]:
36 if debug:
37 print(f"INFO: Running ffprobe(\"{fname}\", {playlist:d}) ...")
38 __ffprobe__[fname][playlist] = ffprobe(
39 fname,
40 cwd = cwd,
41 ensureNFC = ensureNFC,
42 ffprobePath = ffprobePath,
43 playlist = playlist,
44 timeout = timeout,
45 )
47 # Loop over streams ...
48 for stream in __ffprobe__[fname][playlist]["streams"]:
49 # Skip stream if it is not video ...
50 if stream["codec_type"].strip().lower() != "video":
51 continue
53 # Check the rotation ...
54 if return_video_rotation(
55 fname,
56 cwd = cwd,
57 debug = debug,
58 ensureNFC = ensureNFC,
59 ffprobePath = ffprobePath,
60 playlist = playlist,
61 timeout = timeout,
62 ) in [0, 180]:
63 # Return height ...
64 return int(stream["height"]) # [px]
65 if return_video_rotation(
66 fname,
67 cwd = cwd,
68 debug = debug,
69 ensureNFC = ensureNFC,
70 ffprobePath = ffprobePath,
71 playlist = playlist,
72 timeout = timeout,
73 ) in [90, 270]:
74 # Return width ...
75 return int(stream["width"]) # [px]
77 # Return error ...
78 return -1 # [px]