summaryrefslogtreecommitdiff
path: root/tools/ipcam_stream.py
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2024-02-27 00:01:50 +0300
committerEvgeny Zinoviev <me@ch1p.io>2024-02-27 00:01:50 +0300
commit7092c79b5693b239fec739c181d300301c434d22 (patch)
treeed1029051c70767d919a62f62fbac0ab6639e8c4 /tools/ipcam_stream.py
parentd638bb4f58bf81c60ef218204b1fba75cf16b36a (diff)
some include magic; add tools/ipcam_stream.py
Diffstat (limited to 'tools/ipcam_stream.py')
-rwxr-xr-xtools/ipcam_stream.py38
1 files changed, 38 insertions, 0 deletions
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