Skip to content

Commit f0e1bbf

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 f0e1bbf

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

labgrid/driver/httpvideodriver.py

Lines changed: 32 additions & 3 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,16 +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)
32-
return
33+
return default_port
34+
35+
36+
@Driver.check_active
37+
def stream(self, quality_hint=None):
38+
default_port = self._get_default_port()
3339

3440
url = proxymanager.get_url(self.video.url, default_port=default_port)
3541
pipeline = [
@@ -47,3 +53,26 @@ def stream(self, quality_hint=None):
4753

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

0 commit comments

Comments
 (0)