summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon duSaint2023-09-14 08:44:38 -0700
committerJon duSaint2023-09-14 08:44:38 -0700
commit678d871e91a297cfb47d45efdf124467c7de429c (patch)
tree9e863edbce688644cdd2728260b6984554a9fb18
parent4793b53fafde382fb3383d4d0f2f5fcccb1a8e41 (diff)

Reolink.pm: Add additional parameters to new()

  • debug => [0|1]

    Enable/disable debug printing. Not much of this so far.

  • imagequalityworkaround => [0|1]

    Newer Reolink firmware (unknown which versions or when it started) generate JPEG images with empty or missing quantization tables. This is probably fine, except a years-old bug in ffmpeg’s mjpeg module causes it to choke when this field is missing, so timelapse videos can’t be created. Setting this flag causes the image data to get run through Image::Magick, setting a quality of 99, before saving.

-rw-r--r--reolink/Reolink.pm38
1 files changed, 30 insertions, 8 deletions
diff --git a/reolink/Reolink.pm b/reolink/Reolink.pm
index 5ce5bbd..ea95c4f 100644
--- a/reolink/Reolink.pm
+++ b/reolink/Reolink.pm
@@ -68,6 +68,12 @@ sub api {
return api ($this, %args);
}
+ if ($this->{debug}) {
+ if (! $resp->is_success) {
+ print Dumper $resp;
+ }
+ }
+
my $ret = $resp->is_success ? $resp->decoded_content : '[{"code":-1}]';
my $retref = decode_json ($ret);
@@ -103,6 +109,14 @@ sub new {
token => undef,
errors => 0
};
+
+ if ($args{image_quality_workaround}) {
+ $this->{image_quality_workaround} = 1;
+ }
+ if ($args{debug}) {
+ $this->{debug} = 1;
+ }
+
make_url ($this);
bless $this, $class;
@@ -519,6 +533,7 @@ seconds to run.
=cut
+use Image::Magick;
sub Snap {
my ($this, $filename) = @_;
# Generate random 16 char token.
@@ -534,16 +549,23 @@ sub Snap {
return 1;
}
- my $fh;
- unless (open ($fh, ">$filename")) {
- carp "Failed to open '$filename': $!";
- return 1;
- }
+ if ($this->{image_quality_workaround}) {
+ my $image = Image::Magick->new ();
+ $image->BlobToImage ($resp->decoded_content);
+ $image->Set (quality => 99);
+ $image->Write (filename => $filename);
+ } else {
+ my $fh;
+ unless (open ($fh, ">$filename")) {
+ carp "Failed to open '$filename': $!";
+ return 1;
+ }
- binmode $fh;
- print $fh $resp->decoded_content;
+ binmode $fh;
+ print $fh $resp->decoded_content;
- close $fh;
+ close $fh;
+ }
0;
}