From b071d020655973ac15e45c6150c76edff8f8dae3 Mon Sep 17 00:00:00 2001 From: Meisterlala <6453306+Meisterlala@users.noreply.github.com> Date: Fri, 17 Oct 2025 21:35:59 +0200 Subject: [PATCH] better seeking --- PKGBUILD | 2 +- cmd/compressor/processor.go | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/PKGBUILD b/PKGBUILD index 6aee86f..b5d7f06 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -1,6 +1,6 @@ # Maintainer: Misti pkgname=compressor-git -pkgver=r12.69e7ab1 +pkgver=r14.69b8d10 pkgrel=1 pkgdesc="Video compressor service that watches input directory and compresses videos using ffmpeg" arch=('x86_64' 'aarch64') diff --git a/cmd/compressor/processor.go b/cmd/compressor/processor.go index 9f8b828..2d4a1b4 100644 --- a/cmd/compressor/processor.go +++ b/cmd/compressor/processor.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" "log" - "math" "os" "os/exec" "path/filepath" @@ -212,15 +211,15 @@ func generateThumbnail(ctx context.Context, cfg config, videoPath, thumbnailPath // First, probe the video duration duration, err := getVideoDuration(ctx, cfg, videoPath) + seekString := "0" // Default to frame 1 if err != nil { - log.Printf("Failed to get video duration, using default seek: %v", err) - duration = 10 // fallback to 10 seconds + log.Printf("Failed to get video duration, seeking to frame 1: %v", err) + } else { + // Seek to 10% of the video duration + seekTime := duration * 0.1 + seekString = fmt.Sprintf("%.3f", seekTime) } - // Seek to 10% of the video duration, but at least 1 second - seekTime := math.Max(1.0, duration*0.1) - seekString := fmt.Sprintf("%.3f", seekTime) - // Generate thumbnail at calculated position, full resolution args := []string{ "-hide_banner", @@ -238,7 +237,7 @@ func generateThumbnail(ctx context.Context, cfg config, videoPath, thumbnailPath cmd.Stderr = os.Stderr cmd.Env = os.Environ() - log.Printf("generating thumbnail: %s -> %s (seek to %.1fs)", videoPath, thumbnailPath, seekTime) + log.Printf("generating thumbnail: %s -> %s (seek to %s)", videoPath, thumbnailPath, seekString) if err := cmd.Run(); err != nil { return fmt.Errorf("thumbnail generation failed: %w", err) -- 2.51.2