summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon duSaint2023-09-06 08:00:35 -0700
committerJon duSaint2023-09-06 08:00:35 -0700
commit4db96025565959c86ba797021c6199af9f62f194 (patch)
treec17aacad2a2725c5b96903c7d5d172a6fc64c86c
parentbb5f23531b8b13ff65dca2b53eab7e2b04774013 (diff)

reolink: Fixes for video format switch

All the things that prevented the previous commit from working. The iDevice can now play video, as can Firefox.

-rwxr-xr-xreolink/reolink33
1 files changed, 23 insertions, 10 deletions
diff --git a/reolink/reolink b/reolink/reolink
index 37aeca4..0ce9ab4 100755
--- a/reolink/reolink
+++ b/reolink/reolink
@@ -26,6 +26,7 @@ my ($min_interval, $interval, $max_interval) = (10, 30, 600);
my $spool_retention_time = 24;
my $default_video_range = '0530-2130';
my ($video_format, $video_extension) = ('h264', 'mp4'); # ('vp9', 'webm') also supported
+my @video_extensions = qw(mp4 webm); # enumeration of all supported types - used to generate HTML
my %commands = (
interval => {
@@ -349,7 +350,10 @@ sub maybe_generate_video {
my $video_prefix = @_ >= 1 ? $_[0] : sprintf ('%04d%02d%02d', $t[5]+1900, $t[4]+1, $t[3]);
- my @videos = <$server_params{spool_dir}/$video_prefix*.$video_extension>;
+ my @videos;
+ foreach my $ext (@video_extensions) {
+ push @videos, <$server_params{spool_dir}/$video_prefix*.$ext>;
+ }
if (@videos) {
debug ("already generated for $video_prefix");
@@ -607,16 +611,22 @@ IMAGE
<select class="video-menu" id="video-menu" onchange="video_select();">
SLIDESHOW
+ my @video_list;
my @videos;
- foreach my $video (<"$server_params{spool_dir}/*.$video_extension">) {
- if ($video =~ m,/(\d{4})(\d{2})(\d{2})\.$video_extension$,) {
- push @videos, [$1, $2, $3];
+ foreach my $ext (@video_extensions) {
+ push @video_list, <$server_params{spool_dir}/*.$ext>;
+ }
+
+ foreach my $video (sort @video_list) {
+ my $ext = join ('|', @video_extensions);
+ if ($video =~ m,/(\d{4})(\d{2})(\d{2})\.($ext)$,) {
+ push @videos, [$1, $2, $3, $4];
}
}
print $fh $_ foreach map { qq( <option value="$_->[0]$_->[1]$_->[2]">$_->[0]-$_->[1]-$_->[2]</option>\n) } reverse @videos;
- my ($video, $keyframe) = ("$videos[-1]->[0]$videos[-1]->[1]$videos[-1]->[2].$video_extension",
+ my ($video, $keyframe) = ("$videos[-1]->[0]$videos[-1]->[1]$videos[-1]->[2].$videos[-1]->[3]",
"$videos[-1]->[0]$videos[-1]->[1]$videos[-1]->[2]_kf.jpg");
print $fh <<"SLIDESHOW";
@@ -908,6 +918,7 @@ sub process_pass {
# Two pass VP9 webm constant quality encoding
sub process_vp9 {
+ my $v = shift;
my $basefile = shift;
my @files = @_;
my $outfile = "$basefile.webm";
@@ -920,6 +931,7 @@ sub process_vp9 {
# H.264
# This is nearly twice the size of VP9, but apple products don't support that or AV1, and firefox doesn't support MP4/HEVC. Lame.
sub process_h264 {
+ my $v = shift;
my $basefile = shift;
my @files = @_;
my $outfile = "$basefile.mp4";
@@ -934,22 +946,23 @@ sub process {
my $v = shift;
my $spool = shift;
my @files = @_;
- my $basefile = File::Spec->catfile ($process_params{spool_dir}, $spool, $ARGV[0]$v->{suffix});
+ my $basefile = File::Spec->catfile ($process_params{spool_dir}, $ARGV[0].$v->{suffix});
my $outfile;
if ($video_format eq 'vp9') {
- $outfile = process_vp9 ($basefile, @files);
+ $outfile = process_vp9 ($v, $basefile, @files);
} elsif ($video_format eq 'h264') {
- $outfile = process_h264 ($basefile, @files);
+ $outfile = process_h264 ($v, $basefile, @files);
} else {
die "Video format '$video_format' not supported";
}
# "Key frame" is the still to show for the video. Use the middle image.
my ($keyframe_in, $keyframe) = ($files[int (@files / 2)], $outfile);
- $keyframe =~ s/\.$video_extention$/_kf.jpg/;
+ my $ext = join ('|', @video_extensions);
+ $keyframe =~ s/\.(?:$ext)$/_kf.jpg/;
print ("generating keyframe $keyframe_in $keyframe\n");
- my $geometry = $size;
+ my $geometry = $video_params[$v->{index}]->{size};
$geometry =~ s/:/x/g;
if (system ("convert -resize $geometry $keyframe_in $keyframe")) {
if ($? == -1) {