Skip to content

Commit

Permalink
driver/httpvideodriver: implement screenshot
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Emantor committed Feb 17, 2025
1 parent 32a1b1b commit 0722e69
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions labgrid/driver/httpvideodriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@ class HTTPVideoDriver(Driver, VideoProtocol):
def get_qualities(self):
return ("high", [("high", None)])

@Driver.check_active
def stream(self, quality_hint=None):
def _get_default_port(self):
s = urlsplit(self.video.url)
if s.scheme == "http":
default_port = 80
elif s.scheme == "https":
default_port = 443
else:
print(f"Unknown scheme: {s.scheme}", file=sys.stderr)
return
return None


@Driver.check_active
def stream(self, quality_hint=None):
default_port = self._get_default_port()

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

sub = subprocess.run(pipeline)
return sub.returncode

@Driver.check_active
def screenshot(self, filename):
default_port = self._get_default_port()

url = proxymanager.get_url(self.video.url, default_port=default_port)
pipeline = [
"gst-launch-1.0",
"souphttpsrc",
"num-buffers=75",
f"location={url}",
"!",
"decodebin",
"!",
"jpegenc",
"!",
"filesink",
f"location={filepath.absolute()}"
]

sub = subprocess.run(pipeline)
return sub.returncode

0 comments on commit 0722e69

Please sign in to comment.