Skip to content

Commit 0722e69

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 32a1b1b commit 0722e69

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

labgrid/driver/httpvideodriver.py

+29-3
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,20 @@ class HTTPVideoDriver(Driver, VideoProtocol):
2020
def get_qualities(self):
2121
return ("high", [("high", None)])
2222

23-
@Driver.check_active
24-
def stream(self, quality_hint=None):
23+
def _get_default_port(self):
2524
s = urlsplit(self.video.url)
2625
if s.scheme == "http":
2726
default_port = 80
2827
elif s.scheme == "https":
2928
default_port = 443
3029
else:
3130
print(f"Unknown scheme: {s.scheme}", file=sys.stderr)
32-
return
31+
return None
32+
33+
34+
@Driver.check_active
35+
def stream(self, quality_hint=None):
36+
default_port = self._get_default_port()
3337

3438
url = proxymanager.get_url(self.video.url, default_port=default_port)
3539
pipeline = [
@@ -47,3 +51,25 @@ def stream(self, quality_hint=None):
4751

4852
sub = subprocess.run(pipeline)
4953
return sub.returncode
54+
55+
@Driver.check_active
56+
def screenshot(self, filename):
57+
default_port = self._get_default_port()
58+
59+
url = proxymanager.get_url(self.video.url, default_port=default_port)
60+
pipeline = [
61+
"gst-launch-1.0",
62+
"souphttpsrc",
63+
"num-buffers=75",
64+
f"location={url}",
65+
"!",
66+
"decodebin",
67+
"!",
68+
"jpegenc",
69+
"!",
70+
"filesink",
71+
f"location={filepath.absolute()}"
72+
]
73+
74+
sub = subprocess.run(pipeline)
75+
return sub.returncode

0 commit comments

Comments
 (0)