From fa33d78ac2d19a548e1e46fb8e552e967389b5e1 Mon Sep 17 00:00:00 2001 From: Tim Kainz Date: Wed, 7 Jan 2026 23:57:39 +0100 Subject: [PATCH] Add FFmpeg Downloader --- Flashcap-Demo/FFmpeg.cs | 27 +++++++++++++++++++++++++++ Flashcap-Demo/Flashcap-Demo.csproj | 4 +--- Flashcap-Demo/Program.cs | 10 +++++++++- 3 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 Flashcap-Demo/FFmpeg.cs diff --git a/Flashcap-Demo/FFmpeg.cs b/Flashcap-Demo/FFmpeg.cs new file mode 100644 index 0000000..b8820d1 --- /dev/null +++ b/Flashcap-Demo/FFmpeg.cs @@ -0,0 +1,27 @@ +using Xabe.FFmpeg; +using Xabe.FFmpeg.Downloader; + +namespace Flashcap_Demo; + +public class FFmpeg +{ + public static Task DownloadBackground() + { + return FFmpegDownloader.GetLatestVersion(FFmpegVersion.Official, new Progress(info => + { + if (info.TotalBytes<=1)return; + var percentageDone = (double)info.DownloadedBytes / info.TotalBytes; + Console.Write($"Downloaded {FormatBytes(info.DownloadedBytes)} of {FormatBytes(info.TotalBytes)}, {FormatPercentage(percentageDone)}\r"); + })); + } + + private static string FormatBytes(long bytes) + { + return $"{bytes / 1000000.0d:#00.00}MB"; + } + private static string FormatPercentage(double percentage) + { + return $"{percentage*100:00.00}%"; + } + +} \ No newline at end of file diff --git a/Flashcap-Demo/Flashcap-Demo.csproj b/Flashcap-Demo/Flashcap-Demo.csproj index 7a36335..e4e727d 100644 --- a/Flashcap-Demo/Flashcap-Demo.csproj +++ b/Flashcap-Demo/Flashcap-Demo.csproj @@ -9,9 +9,7 @@ - - - + diff --git a/Flashcap-Demo/Program.cs b/Flashcap-Demo/Program.cs index f1090ee..5aa4902 100644 --- a/Flashcap-Demo/Program.cs +++ b/Flashcap-Demo/Program.cs @@ -5,8 +5,9 @@ namespace Flashcap_Demo; internal static class Program { - public static void Main(string[] args) + public static async Task Main(string[] args) { + var backgroundDownload = FFmpeg.DownloadBackground(); var device = new CaptureDevices(); var deviceDescriptors = device.GetDescriptors() .Where(x=>x.Characteristics.Length > 0) @@ -20,6 +21,13 @@ internal static class Program Console.WriteLine($"Chosen:\n\t" + $"{captureDeviceDescriptor}\n\t" + $"{characteristic}"); + if (!backgroundDownload.IsCompleted) + { + await backgroundDownload; + } + + Console.WriteLine("We have both a selected Device and FFmpeg"); + } } \ No newline at end of file