diff --git a/app/rtsp_event.py b/app/rtsp_event.py index 69bf74e1..2eca246d 100644 --- a/app/rtsp_event.py +++ b/app/rtsp_event.py @@ -60,7 +60,7 @@ def pub_start(self) -> None: + env_bool(f"RTSP_PATHS_{self.uri.upper()}_READPASS") + f"@{rtsp_addr}" ) - ffmpeg_cmd = f"ffmpeg -loglevel fatal -threads 1 -analyzeduration 1 -rtsp_transport tcp -i rtsp://{rtsp_addr}/{self.uri} -f:v h264 -an -f image2 -frames:v 1 -y {img_file}" + ffmpeg_cmd = f"ffmpeg -loglevel error -threads 1 -analyzeduration 50 -probesize 50 -rtsp_transport tcp -i rtsp://{rtsp_addr}/{self.uri} -an -f image2 -frames:v 1 -y {img_file}" while True: self.send_mqtt("state", "online") if rtsp: diff --git a/app/wyze_bridge.py b/app/wyze_bridge.py index 2501e612..5c7b1cb3 100644 --- a/app/wyze_bridge.py +++ b/app/wyze_bridge.py @@ -20,7 +20,7 @@ class WyzeBridge: def __init__(self) -> None: - print("🚀 STARTING DOCKER-WYZE-BRIDGE v1.3.4 DEV 3\n") + print("🚀 STARTING DOCKER-WYZE-BRIDGE v1.3.4 DEV 4\n") signal.signal(signal.SIGTERM, lambda n, f: self.clean_up()) self.hass: bool = bool(os.getenv("HASS")) self.on_demand: bool = bool(os.getenv("ON_DEMAND")) @@ -397,7 +397,7 @@ def start_tutk_stream(self, cam: wyzecam.WyzeCamera, stop_flag, connected) -> No ) as sess: connected.set() fps = check_cam_sess(sess, uri) - cmd = get_ffmpeg_cmd(uri, cam.product_model) + cmd = get_ffmpeg_cmd(uri, cam.product_model, fps) with Popen(cmd, stdin=PIPE) as ffmpeg: for frame in sess.recv_bridge_frame( stop_flag, self.keep_bad_frames, self.timeout, fps @@ -524,6 +524,7 @@ def check_cam_sess(sess: wyzecam.WyzeIOTCSession, uri: str) -> int: if (force_fps := int(env_bool(f"FORCE_FPS_{uri}", 0))) and force_fps != fps: log.info(f"Attempting to change FPS to {force_fps}") sess.change_fps(force_fps) + fps = force_fps if env_bool("DEBUG_LEVEL"): log.info(f"[videoParm] {video_param}") firmware = sess.camera.camera_info["basicInfo"].get("firmware", "NA") @@ -537,25 +538,25 @@ def check_cam_sess(sess: wyzecam.WyzeIOTCSession, uri: str) -> int: return fps or 15 -def get_ffmpeg_cmd(uri: str, cam_model: str = None) -> list: +def get_ffmpeg_cmd(uri: str, cam_model: str = None, fps: int = None) -> list: """Return the ffmpeg cmd with options from the env.""" lib264 = ( - ["libx264", "-vf", "transpose=1"] + ["libx264", "-vf", "transpose=1", "-b:v", "3000K"] # , "-r", f"{fps}"] + ["-tune", "zerolatency", "-preset", "ultrafast"] + ["-force_key_frames", "expr:gte(t,n_forced*2)"] ) flags = "-fflags +genpts+flush_packets+nobuffer -flags +low_delay" rotate = cam_model == "WYZEDB3" and env_bool("ROTATE_DOOR", False) - rtsp_ss = f"[select=v:f=rtsp]rtsp://0.0.0.0:8554/{uri.lower()}" + rtsp_ss = f"[select=v:f=rtsp:rtsp_transport=tcp]rtsp://0.0.0.0:8554/{uri.lower()}" livestream = get_livestream_cmd(uri) cmd = env_bool(f"FFMPEG_CMD_{uri}", env_bool("FFMPEG_CMD", "")).strip( "'\"\n " ).format(cam_name=uri.lower(), CAM_NAME=uri).split() or ( - ["-loglevel", "verbose" if env_bool("DEBUG_FFMPEG") else "fatal"] + ["-loglevel", "verbose" if env_bool("DEBUG_FFMPEG") else "error"] + env_bool(f"FFMPEG_FLAGS_{uri}", env_bool("FFMPEG_FLAGS", flags)) .strip("'\"\n ") .split() - + ["-analyzeduration", "1", "-f", "h264", "-i", "pipe:"] + + ["-analyzeduration", "50", "-probesize", "50", "-f", "h264", "-i", "pipe:"] + (["-f", "lavfi", "-i", "anullsrc=cl=mono"] if livestream else []) + ["-c:v"] + (["copy"] if not rotate else lib264) diff --git a/app/wyzecam/iotc.py b/app/wyzecam/iotc.py index 56bcb6bf..92cb4a46 100644 --- a/app/wyzecam/iotc.py +++ b/app/wyzecam/iotc.py @@ -481,7 +481,7 @@ def update_frame_size_rate(self, bitrate: bool = False, fps: int = None) -> None if bitrate: param = mux.send_ioctl(K10020CheckCameraParams(3, 5)).result() if fps and int(param.get("5", fps)) != fps: - warnings.warn(f"FPS param mismatch (framerate={param.get('5')})") + warnings.warn(f"FPS param mismatch (avRecv FPS={fps})") if os.getenv("FPS_FIX"): self.change_fps(fps) return