Skip to content

Commit 78e851e

Browse files
committed
driver/httpvideodriver: implement screenshot
Implement screenshots for HTTP video cameras. For this we factor out the default_port function out of stream() and reuse it for screenshot(). The screenshot function takes the stream, waits for 75 buffers to ensure we have hit an i-frame in the pipeline so we can encode a complete picture and than encodes the picture into a jpeg file. Signed-off-by: Rouven Czerwinski <[email protected]>
1 parent 6dbf096 commit 78e851e

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

labgrid/driver/httpvideodriver.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import pathlib
12
import subprocess
23
import sys
34
from urllib.parse import urlsplit
@@ -20,15 +21,21 @@ class HTTPVideoDriver(Driver, VideoProtocol):
2021
def get_qualities(self):
2122
return ("high", [("high", None)])
2223

23-
@Driver.check_active
24-
def stream(self, quality_hint=None):
24+
def _get_default_port(self):
25+
default_port = None
2526
s = urlsplit(self.video.url)
2627
if s.scheme == "http":
2728
default_port = 80
2829
elif s.scheme == "https":
2930
default_port = 443
3031
else:
3132
print(f"Unknown scheme: {s.scheme}", file=sys.stderr)
33+
return default_port
34+
35+
@Driver.check_active
36+
def stream(self, quality_hint=None):
37+
default_port = self._get_default_port()
38+
if default_port is None:
3239
return
3340

3441
url = proxymanager.get_url(self.video.url, default_port=default_port)
@@ -47,3 +54,28 @@ def stream(self, quality_hint=None):
4754

4855
sub = subprocess.run(pipeline)
4956
return sub.returncode
57+
58+
@Driver.check_active
59+
def screenshot(self, filename):
60+
default_port = self._get_default_port()
61+
if default_port is None:
62+
return
63+
64+
filepath = pathlib.Path(filename)
65+
url = proxymanager.get_url(self.video.url, default_port=default_port)
66+
pipeline = [
67+
"gst-launch-1.0",
68+
"souphttpsrc",
69+
"num-buffers=75",
70+
f"location={url}",
71+
"!",
72+
"decodebin",
73+
"!",
74+
"jpegenc",
75+
"!",
76+
"filesink",
77+
f"location={filepath.absolute()}",
78+
]
79+
80+
sub = subprocess.run(pipeline)
81+
return sub.returncode

0 commit comments

Comments
 (0)