From 7092c79b5693b239fec739c181d300301c434d22 Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Tue, 27 Feb 2024 00:01:50 +0300 Subject: some include magic; add tools/ipcam_stream.py --- tools/ipcam_stream.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100755 tools/ipcam_stream.py (limited to 'tools/ipcam_stream.py') diff --git a/tools/ipcam_stream.py b/tools/ipcam_stream.py new file mode 100755 index 0000000..9cf99d6 --- /dev/null +++ b/tools/ipcam_stream.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 +import include_homekit +import subprocess +import sys + +from argparse import ArgumentParser, ArgumentError +from homekit.camera import IpcamConfig + +if __name__ == '__main__': + players = ('mpv', 'vlc') + parser = ArgumentParser() + parser.add_argument('--tcp', action='store_true', + help='use tcp for rtsp') + parser.add_argument('--player', type=str, choices=players, default=players[0], + help='player to use') + parser.add_argument('--low', action='store_true', + help='use second channel') + parser.add_argument('camera', metavar='CAMERA', type=int, nargs=1, + help='number of camera to stream') + args = parser.parse_args() + + ic = IpcamConfig() + camera = args.camera[0] + if not ic.has_camera(camera): + raise ArgumentError(None, f'invalid camera {camera}') + + cmd = [args.player] + if args.tcp: + cmd.extend(['--rtsp-transport=tcp', '--force-seekable=yes']) + ip = ic.get_camera_ip(camera) + username, password = ic.get_rtsp_creds() + uri = f'rtsp://{username}:{password}@{ip}:554' + uri += ic.get_camera_type(camera).get_channel_url(1 if not args.low else 2) + cmd.append(uri) + + p = subprocess.run(cmd, capture_output=False) + if p.returncode != 0: + print(f'error: {args.player} returned {p.returncode}', file=sys.stderr) \ No newline at end of file -- cgit v1.2.3