mirror of
https://github.com/abhiTronix/vidgear.git
synced 2026-02-06 19:03:18 +00:00
♻️ Refactor code for improved readability and consistency across multiple files
This commit is contained in:
committed by
Abhishek Thakur
parent
ef8dbd3184
commit
00ce8d500e
@@ -222,7 +222,10 @@ def generate_webdata(
|
||||
css_static_dir, c_name=c_name, files=["custom.css"], logging=logging
|
||||
)
|
||||
download_webdata(
|
||||
js_static_dir, c_name=c_name, files=["custom.js"], logging=logging,
|
||||
js_static_dir,
|
||||
c_name=c_name,
|
||||
files=["custom.js"],
|
||||
logging=logging,
|
||||
)
|
||||
download_webdata(
|
||||
favicon_dir, c_name=c_name, files=["favicon-32x32.png"], logging=logging
|
||||
|
||||
@@ -615,7 +615,8 @@ class NetGear_Async:
|
||||
|
||||
# create return type dict without data
|
||||
rettype_dict = dict(
|
||||
return_type=(type(return_data).__name__), return_data=None,
|
||||
return_type=(type(return_data).__name__),
|
||||
return_data=None,
|
||||
)
|
||||
# encode it
|
||||
rettype_enc = msgpack.packb(rettype_dict)
|
||||
|
||||
@@ -422,9 +422,9 @@ class WebGear_RTC:
|
||||
if isinstance(value, bool):
|
||||
if value:
|
||||
self.__relay = MediaRelay()
|
||||
options[
|
||||
"enable_infinite_frames"
|
||||
] = True # enforce infinite frames
|
||||
options["enable_infinite_frames"] = (
|
||||
True # enforce infinite frames
|
||||
)
|
||||
logger.critical(
|
||||
"Enabled live broadcasting for Peer connection(s)."
|
||||
)
|
||||
|
||||
@@ -195,7 +195,11 @@ def deprecated(parameter=None, message=None, stacklevel=2):
|
||||
|
||||
|
||||
def import_dependency_safe(
|
||||
name, error="raise", pkg_name=None, min_version=None, custom_message=None,
|
||||
name,
|
||||
error="raise",
|
||||
pkg_name=None,
|
||||
min_version=None,
|
||||
custom_message=None,
|
||||
):
|
||||
"""
|
||||
## import_dependency_safe
|
||||
@@ -719,7 +723,7 @@ def extract_time(value: str) -> int:
|
||||
t_duration = re.findall(r"\d{2}:\d{2}:\d{2}(?:\.\d{2})?", stripped_data)
|
||||
return (
|
||||
sum(
|
||||
float(x) * 60 ** i
|
||||
float(x) * 60**i
|
||||
for i, x in enumerate(reversed(t_duration[0].split(":")))
|
||||
)
|
||||
if t_duration
|
||||
@@ -1139,7 +1143,8 @@ def download_ffmpeg_binaries(
|
||||
os.path.abspath(path), "ffmpeg-static-{}-gpl.zip".format(os_bit)
|
||||
)
|
||||
file_path = os.path.join(
|
||||
os.path.abspath(path), "ffmpeg-static-{}-gpl/bin/ffmpeg.exe".format(os_bit),
|
||||
os.path.abspath(path),
|
||||
"ffmpeg-static-{}-gpl/bin/ffmpeg.exe".format(os_bit),
|
||||
)
|
||||
base_path, _ = os.path.split(file_name) # extract file base path
|
||||
# check if file already exists
|
||||
|
||||
+11
-4
@@ -307,7 +307,11 @@ class PiGear:
|
||||
# unless format is either BGR or BGRA
|
||||
(
|
||||
not (colorspace is None)
|
||||
or options["format"] in ["RGB888", "XRGB8888",]
|
||||
or options["format"]
|
||||
in [
|
||||
"RGB888",
|
||||
"XRGB8888",
|
||||
]
|
||||
) and logger.warning(
|
||||
"Custom Output frames `format={}` detected. It is advised to define `colorspace` parameter or handle this format manually in your code!".format(
|
||||
options["format"]
|
||||
@@ -337,7 +341,8 @@ class PiGear:
|
||||
invalid_sensor_keys = set(list(sensor)) - set(valid_sensor)
|
||||
invalid_sensor_keys and logger.warning(
|
||||
"Discarding sensor properties NOT supported by current Camera Sensor: `{}`. Only supported are: (`{}`)".format(
|
||||
"`, `".join(invalid_sensor_keys), "`, `".join(valid_sensor),
|
||||
"`, `".join(invalid_sensor_keys),
|
||||
"`, `".join(valid_sensor),
|
||||
)
|
||||
)
|
||||
# delete all unsupported control keys
|
||||
@@ -608,8 +613,10 @@ class PiGear:
|
||||
# clear frame
|
||||
self.frame = None
|
||||
# re-raise error for debugging
|
||||
error_msg = "[PiGear:ERROR] :: Camera Module API failure occurred: {}".format(
|
||||
self.__exceptions[1]
|
||||
error_msg = (
|
||||
"[PiGear:ERROR] :: Camera Module API failure occurred: {}".format(
|
||||
self.__exceptions[1]
|
||||
)
|
||||
)
|
||||
raise RuntimeError(error_msg).with_traceback(self.__exceptions[2])
|
||||
# return the frame
|
||||
|
||||
@@ -294,7 +294,8 @@ class ScreenGear:
|
||||
self.__thread.start()
|
||||
if self.__backend == "dxcam":
|
||||
self.__capture_object.start(
|
||||
target_fps=self.__target_fps, video_mode=True,
|
||||
target_fps=self.__target_fps,
|
||||
video_mode=True,
|
||||
)
|
||||
self.__logging and self.__target_fps and logger.debug(
|
||||
"Targeting FPS: {}".format(self.__target_fps)
|
||||
|
||||
+23
-18
@@ -359,7 +359,9 @@ class StreamGear:
|
||||
elif os.path.isfile(abs_path) and self.__clear_assets:
|
||||
# clear previous assets if specified
|
||||
delete_ext_safe(
|
||||
os.path.dirname(abs_path), assets_exts, logging=self.__logging,
|
||||
os.path.dirname(abs_path),
|
||||
assets_exts,
|
||||
logging=self.__logging,
|
||||
)
|
||||
# check if path has valid file extension
|
||||
assert abs_path.endswith(
|
||||
@@ -587,7 +589,8 @@ class StreamGear:
|
||||
logger.info("Input video's audio source will be used for this run.")
|
||||
# assign audio codec
|
||||
output_parameters["-acodec"] = self.__params.pop(
|
||||
"-acodec", "aac" if ("-streams" in self.__params) else "copy",
|
||||
"-acodec",
|
||||
"aac" if ("-streams" in self.__params) else "copy",
|
||||
)
|
||||
if output_parameters["-acodec"] != "copy":
|
||||
output_parameters["a_bitrate"] = bitrate # temporary handler
|
||||
@@ -744,11 +747,13 @@ class StreamGear:
|
||||
# process given dash/hls stream and return it
|
||||
if self.__format == "dash":
|
||||
processed_params = self.__generate_dash_stream(
|
||||
input_params=input_params, output_params=output_params,
|
||||
input_params=input_params,
|
||||
output_params=output_params,
|
||||
)
|
||||
else:
|
||||
processed_params = self.__generate_hls_stream(
|
||||
input_params=input_params, output_params=output_params,
|
||||
input_params=input_params,
|
||||
output_params=output_params,
|
||||
)
|
||||
return processed_params
|
||||
|
||||
@@ -844,11 +849,11 @@ class StreamGear:
|
||||
# otherwise calculate video-bitrate
|
||||
fps = stream.pop("-framerate", 0.0)
|
||||
if dimensions and isinstance(fps, (float, int)) and fps > 0:
|
||||
intermediate_dict[
|
||||
"-b:v:{}".format(stream_count)
|
||||
] = "{}k".format(
|
||||
get_video_bitrate(
|
||||
int(dimensions[0]), int(dimensions[1]), fps, bpp
|
||||
intermediate_dict["-b:v:{}".format(stream_count)] = (
|
||||
"{}k".format(
|
||||
get_video_bitrate(
|
||||
int(dimensions[0]), int(dimensions[1]), fps, bpp
|
||||
)
|
||||
)
|
||||
)
|
||||
else:
|
||||
@@ -863,16 +868,16 @@ class StreamGear:
|
||||
audio_bitrate = stream.pop("-audio_bitrate", "")
|
||||
if "-acodec" in output_params:
|
||||
if audio_bitrate and audio_bitrate.endswith(("k", "M")):
|
||||
intermediate_dict[
|
||||
"-b:a:{}".format(stream_count)
|
||||
] = audio_bitrate
|
||||
intermediate_dict["-b:a:{}".format(stream_count)] = (
|
||||
audio_bitrate
|
||||
)
|
||||
else:
|
||||
# otherwise calculate audio-bitrate
|
||||
if dimensions:
|
||||
aspect_width = int(dimensions[0])
|
||||
intermediate_dict[
|
||||
"-b:a:{}".format(stream_count)
|
||||
] = "{}k".format(128 if (aspect_width > 800) else 96)
|
||||
intermediate_dict["-b:a:{}".format(stream_count)] = (
|
||||
"{}k".format(128 if (aspect_width > 800) else 96)
|
||||
)
|
||||
# update output parameters
|
||||
output_params.update(intermediate_dict)
|
||||
# clear intermediate dict
|
||||
@@ -949,9 +954,9 @@ class StreamGear:
|
||||
else:
|
||||
# otherwise reset to default
|
||||
logger.warning("Invalid `-hls_flags` value skipped!")
|
||||
output_params[
|
||||
"-hls_flags"
|
||||
] = "delete_segments+discont_start+split_by_time"
|
||||
output_params["-hls_flags"] = (
|
||||
"delete_segments+discont_start+split_by_time"
|
||||
)
|
||||
# clean everything at exit?
|
||||
remove_at_exit = self.__params.pop("-remove_at_exit", 0)
|
||||
if isinstance(remove_at_exit, int) and remove_at_exit in [
|
||||
|
||||
@@ -17,6 +17,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
===============================================
|
||||
"""
|
||||
|
||||
# import the necessary packages
|
||||
|
||||
import cv2
|
||||
|
||||
@@ -17,6 +17,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
===============================================
|
||||
"""
|
||||
|
||||
# import the necessary packages
|
||||
|
||||
import os
|
||||
|
||||
@@ -17,6 +17,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
===============================================
|
||||
"""
|
||||
|
||||
# import the packages
|
||||
import time
|
||||
import numpy as np
|
||||
|
||||
@@ -17,6 +17,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
===============================================
|
||||
"""
|
||||
|
||||
# import the necessary packages
|
||||
|
||||
import time
|
||||
|
||||
@@ -17,6 +17,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
===============================================
|
||||
"""
|
||||
|
||||
# import the necessary packages
|
||||
|
||||
import os
|
||||
|
||||
@@ -17,6 +17,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
===============================================
|
||||
"""
|
||||
|
||||
# import the necessary packages
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -17,6 +17,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
===============================================
|
||||
"""
|
||||
|
||||
# import the necessary packages
|
||||
|
||||
import os
|
||||
|
||||
@@ -17,6 +17,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
===============================================
|
||||
"""
|
||||
|
||||
# import the necessary packages
|
||||
|
||||
import numpy as np
|
||||
|
||||
Reference in New Issue
Block a user