From 7540b31ab82fde225115d1d2bcfff69c34f02c84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Thu, 3 Feb 2022 18:13:09 +0100 Subject: [PATCH] add play button to video thumbnails --- .gitattributes | 1 + Makefile | 1 + src/assets/play.png | 3 +++ src/previews/video.rs | 15 +++++++++++++++ 4 files changed, 20 insertions(+) create mode 100644 .gitattributes create mode 100644 src/assets/play.png diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..6e16ed8 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +src/assets/play.png filter=lfs diff=lfs merge=lfs -text diff --git a/Makefile b/Makefile index babaf81..add08ba 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ package: target/release/upend webui/public/build/main.js linuxdeploy-x86_64.AppImage --appdir dist cp target/release/upend dist/usr/bin/upend cp -r webui/public dist/usr/bin/webui + cp -r src/assets dist/usr/bin/assets cp media/upend.png dist/usr/share/icons/upend.png VERSION="$$(grep '^version' Cargo.toml|grep -Eo '[0-9]+\.[0-9]+\.[0-9]+')" \ linuxdeploy-x86_64.AppImage --appdir dist -d upend.desktop --output appimage diff --git a/src/assets/play.png b/src/assets/play.png new file mode 100644 index 0000000..7262fbd --- /dev/null +++ b/src/assets/play.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:eed4e1246369a7cb6745fedc39e743d23af78cf564298ca5c7250d63c812cfc0 +size 6616 diff --git a/src/previews/video.rs b/src/previews/video.rs index 7550d20..019efec 100644 --- a/src/previews/video.rs +++ b/src/previews/video.rs @@ -1,10 +1,13 @@ use anyhow::anyhow; +use log::warn; use std::io::Read; use std::path::Path; use std::process::Command; use anyhow::Result; +use crate::common::get_static_dir; + use super::Previewable; pub struct VideoPath<'a>(pub &'a Path); @@ -26,9 +29,21 @@ impl<'a> Previewable for VideoPath<'a> { let duration = String::from_utf8_lossy(&duration_cmd.stdout) .trim() .parse::()?; + let play_button = get_static_dir("assets").map(|d| d.join("play.png")).ok(); let outfile = tempfile::Builder::new().suffix(".webp").tempfile()?; let thumbnail_cmd = Command::new("ffmpeg") .args(["-i", &self.0.to_string_lossy()]) + .args(if let Some(play_button) = play_button { + vec![ + "-i".to_string(), + play_button.to_string_lossy().to_string(), + "-filter_complex".to_string(), + "[0:v][1:v]overlay=(W-w)/2:(H-h)/2".to_string(), + ] + } else { + warn!("Could not find play button to overlay for video thumbnail!"); + vec![] + }) .args(["-vframes", "1"]) .args(["-ss", &(duration / 2.0).to_string()]) .arg(&*outfile.path().to_string_lossy())