Skip to content

Commit 235f340

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 235f340

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

labgrid/driver/httpvideodriver.py

Lines changed: 35 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,22 @@ 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+
36+
@Driver.check_active
37+
def stream(self, quality_hint=None):
38+
default_port = self._get_default_port()
39+
if default_port is None:
3240
return
3341

3442
url = proxymanager.get_url(self.video.url, default_port=default_port)
@@ -47,3 +55,28 @@ def stream(self, quality_hint=None):
4755

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

0 commit comments

Comments
 (0)