#!/usr/bin/perl
# Copyright 2026 SUSE LLC
# SPDX-License-Identifier: GPL-2.0-or-later

=head1 NAME

openterface-snapshot - grab one frame from the Openterface Mini-KVM video input

=head1 SYNOPSIS

    openterface-snapshot [--device /dev/video0] [outfile.png]

Captures a single frame from the Openterface UVC capture device
(autodetected by USB ID unless --device is given) into I<outfile.png>
(default: F<openterface-snapshot.png>). Also prints the detected device
and current capture resolution, which is useful for verifying a setup
before pointing os-autoinst's GENERAL_HW_VIDEO_STREAM_URL at it.

=cut

use strict;
use warnings;
use Getopt::Long;
use Openterface::Video;

my %opt;
GetOptions(\%opt, 'device=s', 'help')
  or die "Usage: $0 [--device /dev/videoN] [outfile.png]\n";
if ($opt{help}) { exec 'perldoc', $0 }

my $outfile = shift // 'openterface-snapshot.png';
my $device = $opt{device} // Openterface::Video::find_device
  or die "No Openterface video device (MS2109/MS2130S) found\n";
my ($width, $height) = Openterface::Video::resolution($device);
print "device: $device ($width x $height)\n";
Openterface::Video::grab_frame($outfile, $device);
print "saved: $outfile\n";
