Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.
C# audio-converteravaloniabatch-conversionconvertercsharpdocument-converterdocx-to-pdfdotnetdrag-and-dropfile-conversionfile-converterheic-converterhwphwpximage-converterlinuxmacospdf-convertervideo-converterwindows
fix(thumbnails): handle videos under 1s, improve test assertions, and document FFmpeg thumbnails
gtxPrimea24fb5f507dd
diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.mdindex 4a7c9e40..51dde6d6 100644--- a/docs/ARCHITECTURE.md+++ b/docs/ARCHITECTURE.md@@ -225,7 +225,7 @@ so a file is handed to its app and never started itself; only formats Filee know`SupportsOpenWith` (Windows), the shell's "Open with" dialog (`SHOpenWithDialog`, on a thread of its own because itblocks until closed). The cards' pictures come from `HistoryThumbnails`: Skia decodes them off the UI thread, scaleddown while decoding where the format allows, from a copy read in one go so the file isn't held open, and a small cache-keeps them while the files are unchanged.+keeps them while the files are unchanged. For video files, FFmpeg extracts and scales a representative frame off the UI thread without locking the file.On macOS, files reach Filee from file managers other than Finder too (issue #160). The "Convert with Filee" service(`MacOSServicesProvider`) and the donut's drags (`DraggedFiles`) read file URLs first, then the olderdiff --git a/src/Filee.App/Services/HistoryThumbnails.cs b/src/Filee.App/Services/HistoryThumbnails.csindex c9672784..87955a4e 100644--- a/src/Filee.App/Services/HistoryThumbnails.cs+++ b/src/Filee.App/Services/HistoryThumbnails.cs@@ -5,6 +5,7 @@// without locking the file. A small cache keeps them while the files don't change: a search lists the same conversions// again at once.+using System.ComponentModel;using Avalonia;using Avalonia.Media.Imaging;using Avalonia.Platform;@@ -131,7 +132,23 @@ internal static class HistoryThumbnailsvar result = FfmpegRunner.RunBriefly(ffmpeg, arguments, TimeSpan.FromSeconds(5));if (result.ExitCode != 0 || !File.Exists(temp))- return null;+ {+ // Trying once more without -ss when no file came out covers videos shorter than 1 s.+ var fallbackArguments = new[]+ {+ "-hide_banner",+ "-nostdin",+ "-v", "error",+ "-i", Path.GetFullPath(path),+ "-frames:v", "1",+ "-vf", $"scale={Size}:{Size}:force_original_aspect_ratio=increase,crop={Size}:{Size}",+ "-y",+ temp+ };+ result = FfmpegRunner.RunBriefly(ffmpeg, fallbackArguments, TimeSpan.FromSeconds(5));+ if (result.ExitCode != 0 || !File.Exists(temp))+ return null;+ }using var stream = new FileStream(temp, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);using var data = SKData.Create(stream);@@ -149,7 +166,7 @@ internal static class HistoryThumbnailsreturn Square(decoded, codec.EncodedOrigin);}- catch (Exception)+ catch (Exception e) when (e is TimeoutException or InvalidOperationException or Win32Exception or IOException or UnauthorizedAccessException){return null;}@@ -160,7 +177,9 @@ internal static class HistoryThumbnailsif (File.Exists(temp))File.Delete(temp);}- catch { }+ catch (Exception e) when (e is IOException or UnauthorizedAccessException)+ {+ }}}diff --git a/tests/Filee.App.Tests/RecentConversionTests.cs b/tests/Filee.App.Tests/RecentConversionTests.csindex 13f2ee3d..391e577b 100644--- a/tests/Filee.App.Tests/RecentConversionTests.cs+++ b/tests/Filee.App.Tests/RecentConversionTests.cs@@ -116,8 +116,7 @@ public class RecentConversionTestspublic void A_video_generates_a_thumbnail_when_ffmpeg_is_available(){var tools = Filee.Engines.Media.FfmpegConverter.Locate();- if (tools is null)- return;+ Assert.SkipUnless(tools is not null, "FFmpeg is not installed (pwsh build/fetch-engines.ps1 -Only ffmpeg)");var folder = Directory.CreateTempSubdirectory("filee-videothumbs-").FullName;try@@ -144,8 +143,51 @@ public class RecentConversionTestsusing var process = System.Diagnostics.Process.Start(psi);Assert.NotNull(process);Assert.True(process.WaitForExit(20_000));- if (process.ExitCode != 0 || !File.Exists(video))- return;+ Assert.True(process.ExitCode == 0 && File.Exists(video), "Sample video could not be created by FFmpeg.");++ var thumbnail = HistoryThumbnails.Load(video);+ Assert.NotNull(thumbnail);+ Assert.Equal(new PixelSize(HistoryThumbnails.Size, HistoryThumbnails.Size), thumbnail.PixelSize);+ Assert.Same(thumbnail, HistoryThumbnails.Cached(video));+ }+ finally+ {+ Directory.Delete(folder, true);+ }+ }++ [AvaloniaFact]+ public void A_video_shorter_than_one_second_generates_a_thumbnail()+ {+ var tools = Filee.Engines.Media.FfmpegConverter.Locate();+ Assert.SkipUnless(tools is not null, "FFmpeg is not installed (pwsh build/fetch-engines.ps1 -Only ffmpeg)");++ var folder = Directory.CreateTempSubdirectory("filee-videoshort-").FullName;+ try+ {+ var video = Path.Combine(folder, "short.mp4");+ var psi = new System.Diagnostics.ProcessStartInfo(tools.Value.Ffmpeg)+ {+ UseShellExecute = false,+ CreateNoWindow = true,+ };+ psi.ArgumentList.Add("-hide_banner");+ psi.ArgumentList.Add("-nostdin");+ psi.ArgumentList.Add("-v");+ psi.ArgumentList.Add("error");+ psi.ArgumentList.Add("-y");+ psi.ArgumentList.Add("-f");+ psi.ArgumentList.Add("lavfi");+ psi.ArgumentList.Add("-i");+ psi.ArgumentList.Add("testsrc=duration=0.5:size=320x240:rate=10");+ psi.ArgumentList.Add("-pix_fmt");+ psi.ArgumentList.Add("yuv420p");+ psi.ArgumentList.Add(video);++ using var process = System.Diagnostics.Process.Start(psi);+ Assert.NotNull(process);+ Assert.True(process.WaitForExit(20_000));+ Assert.True(process.ExitCode == 0 && File.Exists(video), "Short sample video could not be created by FFmpeg.");var thumbnail = HistoryThumbnails.Load(video);Assert.NotNull(thumbnail);