Skip to content

Commit c00441d

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 c00441d

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

labgrid/driver/httpvideodriver.py

+31-3
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,20 @@ 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):
2525
s = urlsplit(self.video.url)
2626
if s.scheme == "http":
2727
default_port = 80
2828
elif s.scheme == "https":
2929
default_port = 443
3030
else:
3131
print(f"Unknown scheme: {s.scheme}", file=sys.stderr)
32-
return
32+
return None
33+
34+
35+
@Driver.check_active
36+
def stream(self, quality_hint=None):
37+
default_port = self._get_default_port()
3338

3439
url = proxymanager.get_url(self.video.url, default_port=default_port)
3540
pipeline = [
@@ -47,3 +52,26 @@ def stream(self, quality_hint=None):
4752

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

0 commit comments

Comments
 (0)