From d9c4595eec61adeed497c4799aa3cbd89a2c0c47 Mon Sep 17 00:00:00 2001 From: NaBian <836904362@qq.com> Date: Fri, 21 Apr 2023 11:07:56 +0800 Subject: [PATCH 1/9] fix: readme minor mistakes. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 365d0be..33f7ddf 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ FFMpeg.Join(@"..\joined_video.mp4", ``` csharp FFMpeg.SubVideo(inputPath, outputPath, - TimeSpan.FromSeconds(0) + TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(30) ); ``` From 657ee5ff5d371487e950c75e141f220a568927ab Mon Sep 17 00:00:00 2001 From: Kerry Cao Date: Fri, 5 May 2023 01:21:53 -0600 Subject: [PATCH 2/9] Comments added --- FFMpegCore/Helpers/FFMpegDownloader.cs | 52 ++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/FFMpegCore/Helpers/FFMpegDownloader.cs b/FFMpegCore/Helpers/FFMpegDownloader.cs index d6149e8..9d87001 100644 --- a/FFMpegCore/Helpers/FFMpegDownloader.cs +++ b/FFMpegCore/Helpers/FFMpegDownloader.cs @@ -1,6 +1,4 @@ -using System.ComponentModel; -using System.Net; -using System.IO; +using System.Net; using System.IO.Compression; @@ -10,7 +8,7 @@ namespace FFMpegCore.Helpers; /// /// Downloads the latest FFMpeg suite binaries from GitHub. Only supported for windows at the moment. /// -public class FFMpegDownloader // this class is built to be easily modified to support other platforms +public class FFMpegDownloader { private static Dictionary Windows64FFMpegDownloadUrls = new() { @@ -26,7 +24,7 @@ public class FFMpegDownloader // this class is built to be easily modified to su private static Dictionary Windows32FFMpegDownloadUrls = new() { - { FFMpegVersions.V4_4_1, "https://example.com/" }, + { FFMpegVersions.V4_4_1, "" }, { FFMpegVersions.V4_2_1, "https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v4.2.1/ffmpeg-4.2.1-win-32.zip"}, { FFMpegVersions.V4_2, "https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v4.2/ffmpeg-4.2-win-32.zip"}, { FFMpegVersions.V4_1, "https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v4.1/ffmpeg-4.1-win-32.zip"}, @@ -36,6 +34,9 @@ public class FFMpegDownloader // this class is built to be easily modified to su { FFMpegVersions.V3_2, "https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v3.2/ffmpeg-3.2-win-32.zip"}, }; + /// + /// Supported FFMpeg versions + /// public enum FFMpegVersions { V4_4_1, @@ -48,6 +49,11 @@ public enum FFMpegVersions V3_2 } + /// + /// Downloads the latest FFMpeg suite binaries to bin directory. + /// + /// + /// public static List AutoDownloadFFMpegSuite(FFMpegVersions version = FFMpegVersions.V4_4_1) { var files = AutoDownloadFFMpeg(version); @@ -57,6 +63,11 @@ public static List AutoDownloadFFMpegSuite(FFMpegVersions version = FFMp return files; } + /// + /// Downloads the latest FFMpeg binaries to bin directory. + /// + /// + /// public static List AutoDownloadFFMpeg(FFMpegVersions version = FFMpegVersions.V4_4_1) { var url = Environment.Is64BitProcess @@ -70,6 +81,11 @@ public static List AutoDownloadFFMpeg(FFMpegVersions version = FFMpegVer return ExtractAndSave(zipStream); } + /// + /// Downloads the latest FFProbe binaries to bin directory. + /// + /// + /// public static List AutoDownloadFFProbe(FFMpegVersions version = FFMpegVersions.V4_4_1) { var url = Environment.Is64BitProcess @@ -83,6 +99,11 @@ public static List AutoDownloadFFProbe(FFMpegVersions version = FFMpegVe return ExtractAndSave(zipStream); } + /// + /// Downloads the latest FFPlay binaries to bin directory. + /// + /// + /// public static List AutoDownloadFFPlay(FFMpegVersions version = FFMpegVersions.V4_4_1) { var url = Environment.Is64BitProcess @@ -96,6 +117,11 @@ public static List AutoDownloadFFPlay(FFMpegVersions version = FFMpegVer return ExtractAndSave(zipStream); } + /// + /// Downloads the zip file from the given url. + /// + /// + /// private static MemoryStream DownloadZip(Uri address) { var client = new WebClient(); @@ -105,13 +131,18 @@ private static MemoryStream DownloadZip(Uri address) return zipStream; } + /// + /// Extracts the zip file and saves the binaries to bin directory. + /// + /// + /// private static List ExtractAndSave(Stream zipStream) { using var archive = new ZipArchive(zipStream, ZipArchiveMode.Read); List files = new(); foreach (var entry in archive.Entries) { - if (entry.Name is "ffmpeg.exe" or "ffmpeg" or "ffprobe.exe") + if (entry.Name is "ffmpeg.exe" or "ffmpeg" or "ffprobe.exe" or "ffplay.exe" or "ffplay") // only extract the binaries { entry.ExtractToFile(Path.Combine(GlobalFFOptions.Current.BinaryFolder, entry.Name), true); files.Add(Path.Combine(GlobalFFOptions.Current.BinaryFolder, entry.Name)); @@ -121,11 +152,16 @@ private static List ExtractAndSave(Stream zipStream) return files; } + /// + /// Checks if the given uri is valid. + /// + /// + /// private static void HasValidUri(Uri uri) { - if (uri.ToString() == "https://example.com/" || !RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (uri.ToString() == "" || !RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - throw new PlatformNotSupportedException("The requested version of FFMpeg component is not available for your OS."); + throw new PlatformNotSupportedException("The requested version of FFMpeg component is not available for your OS/System."); } } } From d68ce8e953f9e914e899ace85b32058b62bfe734 Mon Sep 17 00:00:00 2001 From: Kerry Cao Date: Fri, 5 May 2023 01:30:52 -0600 Subject: [PATCH 3/9] Methods renamed to remove auto prefix --- FFMpegCore.Test/DownloaderTests.cs | 8 ++++---- FFMpegCore/Helpers/FFMpegDownloader.cs | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/FFMpegCore.Test/DownloaderTests.cs b/FFMpegCore.Test/DownloaderTests.cs index 2d968ad..d0f1f55 100644 --- a/FFMpegCore.Test/DownloaderTests.cs +++ b/FFMpegCore.Test/DownloaderTests.cs @@ -12,7 +12,7 @@ public void GetLatestSuiteTest() { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - var fileNames = FFMpegDownloader.AutoDownloadFFMpegSuite(); + var fileNames = FFMpegDownloader.DownloadFFMpegSuite(); Assert.IsTrue(fileNames.Count == 3); } else @@ -26,7 +26,7 @@ public void GetLatestFFMpegTest() { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - var fileNames = FFMpegDownloader.AutoDownloadFFMpeg(); + var fileNames = FFMpegDownloader.DownloadFFMpeg(); Assert.IsTrue(fileNames.Count == 1); } else @@ -40,7 +40,7 @@ public void GetLatestFFProbeTest() { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - var fileNames = FFMpegDownloader.AutoDownloadFFProbe(); + var fileNames = FFMpegDownloader.DownloadFFProbe(); Assert.IsTrue(fileNames.Count == 1); } else @@ -54,7 +54,7 @@ public void GetLatestFFPlayTest() { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - var fileNames = FFMpegDownloader.AutoDownloadFFPlay(); + var fileNames = FFMpegDownloader.DownloadFFPlay(); Assert.IsTrue(fileNames.Count == 1); } else diff --git a/FFMpegCore/Helpers/FFMpegDownloader.cs b/FFMpegCore/Helpers/FFMpegDownloader.cs index 9d87001..89b3d4c 100644 --- a/FFMpegCore/Helpers/FFMpegDownloader.cs +++ b/FFMpegCore/Helpers/FFMpegDownloader.cs @@ -53,12 +53,12 @@ public enum FFMpegVersions /// Downloads the latest FFMpeg suite binaries to bin directory. /// /// - /// - public static List AutoDownloadFFMpegSuite(FFMpegVersions version = FFMpegVersions.V4_4_1) + /// Names of the binary that was saved to bin directory + public static List DownloadFFMpegSuite(FFMpegVersions version = FFMpegVersions.V4_4_1) { - var files = AutoDownloadFFMpeg(version); - files.AddRange(AutoDownloadFFProbe(version)); - files.AddRange(AutoDownloadFFPlay(version)); + var files = DownloadFFMpeg(version); + files.AddRange(DownloadFFProbe(version)); + files.AddRange(DownloadFFPlay(version)); return files; } @@ -68,7 +68,7 @@ public static List AutoDownloadFFMpegSuite(FFMpegVersions version = FFMp /// /// /// - public static List AutoDownloadFFMpeg(FFMpegVersions version = FFMpegVersions.V4_4_1) + public static List DownloadFFMpeg(FFMpegVersions version = FFMpegVersions.V4_4_1) { var url = Environment.Is64BitProcess ? new Uri(Windows64FFMpegDownloadUrls[version]) @@ -86,7 +86,7 @@ public static List AutoDownloadFFMpeg(FFMpegVersions version = FFMpegVer /// /// /// - public static List AutoDownloadFFProbe(FFMpegVersions version = FFMpegVersions.V4_4_1) + public static List DownloadFFProbe(FFMpegVersions version = FFMpegVersions.V4_4_1) { var url = Environment.Is64BitProcess ? new Uri(Windows64FFMpegDownloadUrls[version].Replace("ffmpeg", "ffprobe")) @@ -104,7 +104,7 @@ public static List AutoDownloadFFProbe(FFMpegVersions version = FFMpegVe /// /// /// - public static List AutoDownloadFFPlay(FFMpegVersions version = FFMpegVersions.V4_4_1) + public static List DownloadFFPlay(FFMpegVersions version = FFMpegVersions.V4_4_1) { var url = Environment.Is64BitProcess ? new Uri(Windows64FFMpegDownloadUrls[version].Replace("ffmpeg", "ffplay")) From debb868b38ef11deee4335bc7d37a2f75bc9e333 Mon Sep 17 00:00:00 2001 From: Kerry Cao Date: Fri, 5 May 2023 01:34:21 -0600 Subject: [PATCH 4/9] README.md updated to include ffmpegdownloader usage --- README.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 365d0be..74876a7 100644 --- a/README.md +++ b/README.md @@ -162,7 +162,19 @@ If you want to use `System.Drawing.Bitmap`s as `IVideoFrame`s, a `BitmapVideoFra # Binaries -## Installation +## Runtime Auto Installation +You can install a version of ffmpeg suite at runtime using `FFMpegDownloader.DownloadFFMpegSuite();` + +Or you can download only the desired binary using `FFMpegDownloader.DownloadFFMpeg()`, `FFMpegDownloader.DownloadFFProbe()`, `FFMpegDownloader.DownloadFFPlay()`. + +| OS | Support | +|---------|:-------------------------------------------------:| +| Windows | x64 Fully Supported, x86 Up to version V4.2.1 | +| Mac OSX | NOT YET | +| Linux | NOT YET | + + +## Manual Installation If you prefer to manually download them, visit [ffbinaries](https://ffbinaries.com/downloads) or [zeranoe Windows builds](https://ffmpeg.zeranoe.com/builds/). ### Windows (using choco) From a647f440296dc5d668d10ca6b08bbda033b32998 Mon Sep 17 00:00:00 2001 From: Kerry Cao Date: Fri, 5 May 2023 01:47:08 -0600 Subject: [PATCH 5/9] refactoring and reformatting --- FFMpegCore/Helpers/FFMpegDownloader.cs | 128 +++++++++++++++++-------- 1 file changed, 88 insertions(+), 40 deletions(-) diff --git a/FFMpegCore/Helpers/FFMpegDownloader.cs b/FFMpegCore/Helpers/FFMpegDownloader.cs index 89b3d4c..fef53b3 100644 --- a/FFMpegCore/Helpers/FFMpegDownloader.cs +++ b/FFMpegCore/Helpers/FFMpegDownloader.cs @@ -1,39 +1,83 @@ using System.Net; using System.IO.Compression; - +using System.Runtime.InteropServices; namespace FFMpegCore.Helpers; -using System.Runtime.InteropServices; /// /// Downloads the latest FFMpeg suite binaries from GitHub. Only supported for windows at the moment. /// public class FFMpegDownloader { - private static Dictionary Windows64FFMpegDownloadUrls = new() + private static readonly Dictionary Windows64FFMpegDownloadUrls = new() { - { FFMpegVersions.V4_4_1, "https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v4.4.1/ffmpeg-4.4.1-win-64.zip"}, - { FFMpegVersions.V4_2_1, "https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v4.2.1/ffmpeg-4.2.1-win-64.zip"}, - { FFMpegVersions.V4_2, "https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v4.2/ffmpeg-4.2-win-64.zip"}, - { FFMpegVersions.V4_1, "https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v4.1/ffmpeg-4.1-win-64.zip"}, - { FFMpegVersions.V4_0, "https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v4.0/ffmpeg-4.0.1-win-64.zip"}, - { FFMpegVersions.V3_4, "https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v3.4/ffmpeg-3.4-win-64.zip"}, - { FFMpegVersions.V3_3, "https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v3.3/ffmpeg-3.3.4-win-64.zip"}, - { FFMpegVersions.V3_2, "https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v3.2/ffmpeg-3.2-win-64.zip"}, + { + FFMpegVersions.V4_4_1, + "https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v4.4.1/ffmpeg-4.4.1-win-64.zip" + }, + { + FFMpegVersions.V4_2_1, + "https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v4.2.1/ffmpeg-4.2.1-win-64.zip" + }, + { + FFMpegVersions.V4_2, + "https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v4.2/ffmpeg-4.2-win-64.zip" + }, + { + FFMpegVersions.V4_1, + "https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v4.1/ffmpeg-4.1-win-64.zip" + }, + { + FFMpegVersions.V4_0, + "https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v4.0/ffmpeg-4.0.1-win-64.zip" + }, + { + FFMpegVersions.V3_4, + "https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v3.4/ffmpeg-3.4-win-64.zip" + }, + { + FFMpegVersions.V3_3, + "https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v3.3/ffmpeg-3.3.4-win-64.zip" + }, + { + FFMpegVersions.V3_2, + "https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v3.2/ffmpeg-3.2-win-64.zip" + }, }; - - private static Dictionary Windows32FFMpegDownloadUrls = new() + + private static readonly Dictionary Windows32FFMpegDownloadUrls = new() { { FFMpegVersions.V4_4_1, "" }, - { FFMpegVersions.V4_2_1, "https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v4.2.1/ffmpeg-4.2.1-win-32.zip"}, - { FFMpegVersions.V4_2, "https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v4.2/ffmpeg-4.2-win-32.zip"}, - { FFMpegVersions.V4_1, "https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v4.1/ffmpeg-4.1-win-32.zip"}, - { FFMpegVersions.V4_0, "https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v4.0/ffmpeg-4.0.1-win-32.zip"}, - { FFMpegVersions.V3_4, "https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v3.4/ffmpeg-3.4-win-32.zip"}, - { FFMpegVersions.V3_3, "https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v3.3/ffmpeg-3.3.4-win-32.zip"}, - { FFMpegVersions.V3_2, "https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v3.2/ffmpeg-3.2-win-32.zip"}, + { + FFMpegVersions.V4_2_1, + "https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v4.2.1/ffmpeg-4.2.1-win-32.zip" + }, + { + FFMpegVersions.V4_2, + "https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v4.2/ffmpeg-4.2-win-32.zip" + }, + { + FFMpegVersions.V4_1, + "https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v4.1/ffmpeg-4.1-win-32.zip" + }, + { + FFMpegVersions.V4_0, + "https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v4.0/ffmpeg-4.0.1-win-32.zip" + }, + { + FFMpegVersions.V3_4, + "https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v3.4/ffmpeg-3.4-win-32.zip" + }, + { + FFMpegVersions.V3_3, + "https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v3.3/ffmpeg-3.3.4-win-32.zip" + }, + { + FFMpegVersions.V3_2, + "https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v3.2/ffmpeg-3.2-win-32.zip" + }, }; - + /// /// Supported FFMpeg versions /// @@ -59,7 +103,7 @@ public static List DownloadFFMpegSuite(FFMpegVersions version = FFMpegVe var files = DownloadFFMpeg(version); files.AddRange(DownloadFFProbe(version)); files.AddRange(DownloadFFPlay(version)); - + return files; } @@ -73,14 +117,10 @@ public static List DownloadFFMpeg(FFMpegVersions version = FFMpegVersion var url = Environment.Is64BitProcess ? new Uri(Windows64FFMpegDownloadUrls[version]) : new Uri(Windows32FFMpegDownloadUrls[version]); - - HasValidUri(url); - Stream zipStream = DownloadZip(url); - - return ExtractAndSave(zipStream); + return DownloadAndSave(url); } - + /// /// Downloads the latest FFProbe binaries to bin directory. /// @@ -91,14 +131,10 @@ public static List DownloadFFProbe(FFMpegVersions version = FFMpegVersio var url = Environment.Is64BitProcess ? new Uri(Windows64FFMpegDownloadUrls[version].Replace("ffmpeg", "ffprobe")) : new Uri(Windows32FFMpegDownloadUrls[version].Replace("ffmpeg", "ffprobe")); - - HasValidUri(url); - - Stream zipStream = DownloadZip(url); - return ExtractAndSave(zipStream); + return DownloadAndSave(url); } - + /// /// Downloads the latest FFPlay binaries to bin directory. /// @@ -109,12 +145,22 @@ public static List DownloadFFPlay(FFMpegVersions version = FFMpegVersion var url = Environment.Is64BitProcess ? new Uri(Windows64FFMpegDownloadUrls[version].Replace("ffmpeg", "ffplay")) : new Uri(Windows32FFMpegDownloadUrls[version].Replace("ffmpeg", "ffplay")); - + + return DownloadAndSave(url); + } + + /// + /// Downloads the zip file from the given url and saves the binaries to bin directory. + /// + /// + /// + private static List DownloadAndSave(Uri url) + { HasValidUri(url); Stream zipStream = DownloadZip(url); - return ExtractAndSave(zipStream); + return ExtractZip(zipStream); } /// @@ -130,19 +176,20 @@ private static MemoryStream DownloadZip(Uri address) return zipStream; } - + /// /// Extracts the zip file and saves the binaries to bin directory. /// /// /// - private static List ExtractAndSave(Stream zipStream) + private static List ExtractZip(Stream zipStream) { using var archive = new ZipArchive(zipStream, ZipArchiveMode.Read); List files = new(); foreach (var entry in archive.Entries) { - if (entry.Name is "ffmpeg.exe" or "ffmpeg" or "ffprobe.exe" or "ffplay.exe" or "ffplay") // only extract the binaries + if (entry.Name is "ffmpeg.exe" or "ffmpeg" or "ffprobe.exe" or "ffplay.exe" + or "ffplay") // only extract the binaries { entry.ExtractToFile(Path.Combine(GlobalFFOptions.Current.BinaryFolder, entry.Name), true); files.Add(Path.Combine(GlobalFFOptions.Current.BinaryFolder, entry.Name)); @@ -161,7 +208,8 @@ private static void HasValidUri(Uri uri) { if (uri.ToString() == "" || !RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - throw new PlatformNotSupportedException("The requested version of FFMpeg component is not available for your OS/System."); + throw new PlatformNotSupportedException( + "The requested version of FFMpeg component is not available for your OS/System."); } } } From 463fb9bf6b9153e945d433f8ca2349ead0cf4e2f Mon Sep 17 00:00:00 2001 From: Kerry Cao Date: Fri, 5 May 2023 01:54:50 -0600 Subject: [PATCH 6/9] Reformatted to fix lint error --- FFMpegCore.Test/DownloaderTests.cs | 6 +-- FFMpegCore/Helpers/FFMpegDownloader.cs | 56 +++++++++++++------------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/FFMpegCore.Test/DownloaderTests.cs b/FFMpegCore.Test/DownloaderTests.cs index d0f1f55..52c1780 100644 --- a/FFMpegCore.Test/DownloaderTests.cs +++ b/FFMpegCore.Test/DownloaderTests.cs @@ -20,7 +20,7 @@ public void GetLatestSuiteTest() Assert.Inconclusive("This test is only for Windows"); } } - + [TestMethod] public void GetLatestFFMpegTest() { @@ -34,7 +34,7 @@ public void GetLatestFFMpegTest() Assert.Inconclusive("This test is only for Windows"); } } - + [TestMethod] public void GetLatestFFProbeTest() { @@ -48,7 +48,7 @@ public void GetLatestFFProbeTest() Assert.Inconclusive("This test is only for Windows"); } } - + [TestMethod] public void GetLatestFFPlayTest() { diff --git a/FFMpegCore/Helpers/FFMpegDownloader.cs b/FFMpegCore/Helpers/FFMpegDownloader.cs index fef53b3..6705540 100644 --- a/FFMpegCore/Helpers/FFMpegDownloader.cs +++ b/FFMpegCore/Helpers/FFMpegDownloader.cs @@ -1,14 +1,29 @@ -using System.Net; -using System.IO.Compression; +using System.IO.Compression; +using System.Net; using System.Runtime.InteropServices; namespace FFMpegCore.Helpers; /// -/// Downloads the latest FFMpeg suite binaries from GitHub. Only supported for windows at the moment. +/// Downloads the latest FFMpeg suite binaries from GitHub. Only supported for windows at the moment. /// public class FFMpegDownloader { + /// + /// Supported FFMpeg versions + /// + public enum FFMpegVersions + { + V4_4_1, + V4_2_1, + V4_2, + V4_1, + V4_0, + V3_4, + V3_3, + V3_2 + } + private static readonly Dictionary Windows64FFMpegDownloadUrls = new() { { @@ -42,7 +57,7 @@ public class FFMpegDownloader { FFMpegVersions.V3_2, "https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v3.2/ffmpeg-3.2-win-64.zip" - }, + } }; private static readonly Dictionary Windows32FFMpegDownloadUrls = new() @@ -75,26 +90,11 @@ public class FFMpegDownloader { FFMpegVersions.V3_2, "https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v3.2/ffmpeg-3.2-win-32.zip" - }, + } }; /// - /// Supported FFMpeg versions - /// - public enum FFMpegVersions - { - V4_4_1, - V4_2_1, - V4_2, - V4_1, - V4_0, - V3_4, - V3_3, - V3_2 - } - - /// - /// Downloads the latest FFMpeg suite binaries to bin directory. + /// Downloads the latest FFMpeg suite binaries to bin directory. /// /// /// Names of the binary that was saved to bin directory @@ -108,7 +108,7 @@ public static List DownloadFFMpegSuite(FFMpegVersions version = FFMpegVe } /// - /// Downloads the latest FFMpeg binaries to bin directory. + /// Downloads the latest FFMpeg binaries to bin directory. /// /// /// @@ -122,7 +122,7 @@ public static List DownloadFFMpeg(FFMpegVersions version = FFMpegVersion } /// - /// Downloads the latest FFProbe binaries to bin directory. + /// Downloads the latest FFProbe binaries to bin directory. /// /// /// @@ -136,7 +136,7 @@ public static List DownloadFFProbe(FFMpegVersions version = FFMpegVersio } /// - /// Downloads the latest FFPlay binaries to bin directory. + /// Downloads the latest FFPlay binaries to bin directory. /// /// /// @@ -150,7 +150,7 @@ public static List DownloadFFPlay(FFMpegVersions version = FFMpegVersion } /// - /// Downloads the zip file from the given url and saves the binaries to bin directory. + /// Downloads the zip file from the given url and saves the binaries to bin directory. /// /// /// @@ -164,7 +164,7 @@ private static List DownloadAndSave(Uri url) } /// - /// Downloads the zip file from the given url. + /// Downloads the zip file from the given url. /// /// /// @@ -178,7 +178,7 @@ private static MemoryStream DownloadZip(Uri address) } /// - /// Extracts the zip file and saves the binaries to bin directory. + /// Extracts the zip file and saves the binaries to bin directory. /// /// /// @@ -200,7 +200,7 @@ private static List ExtractZip(Stream zipStream) } /// - /// Checks if the given uri is valid. + /// Checks if the given uri is valid. /// /// /// From 69b01c91c61cf1878ca5f5e99b3056266a456adb Mon Sep 17 00:00:00 2001 From: Rafael Carvalho Date: Wed, 17 May 2023 11:40:20 +1200 Subject: [PATCH 7/9] Add CopyCodecArgument --- FFMpegCore/FFMpeg/Arguments/CopyCodecArgument.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 FFMpegCore/FFMpeg/Arguments/CopyCodecArgument.cs diff --git a/FFMpegCore/FFMpeg/Arguments/CopyCodecArgument.cs b/FFMpegCore/FFMpeg/Arguments/CopyCodecArgument.cs new file mode 100644 index 0000000..8ea3484 --- /dev/null +++ b/FFMpegCore/FFMpeg/Arguments/CopyCodecArgument.cs @@ -0,0 +1,10 @@ +namespace FFMpegCore.Arguments +{ + /// + /// Represents a copy codec parameter + /// + public class CopyCodecArgument : IArgument + { + public string Text => $"-codec copy"; + } +} From 643952db7bf11e611e7e50c786fc105813fa02e3 Mon Sep 17 00:00:00 2001 From: Rafael Carvalho Date: Wed, 17 May 2023 11:40:40 +1200 Subject: [PATCH 8/9] Add "WithCopyCodec" option --- FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs b/FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs index 4930b52..6a6586c 100644 --- a/FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs +++ b/FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs @@ -77,6 +77,7 @@ public FFMpegArgumentOptions DeselectStreams(IEnumerable streamIndices, int public FFMpegArgumentOptions WithAudibleActivationBytes(string activationBytes) => WithArgument(new AudibleEncryptionKeyArgument(activationBytes)); public FFMpegArgumentOptions WithTagVersion(int id3v2Version = 3) => WithArgument(new ID3V2VersionArgument(id3v2Version)); public FFMpegArgumentOptions WithGifPaletteArgument(int streamIndex, Size? size, int fps = 12) => WithArgument(new GifPaletteArgument(streamIndex, fps, size)); + public FFMpegArgumentOptions WithCopyCodec() => WithArgument(new CopyCodecArgument()); public FFMpegArgumentOptions WithArgument(IArgument argument) { From 6c2311c86904a87339dc542160ae6b5ece18b24c Mon Sep 17 00:00:00 2001 From: Rafael Carvalho Date: Wed, 17 May 2023 11:41:13 +1200 Subject: [PATCH 9/9] Update "SaveM3U8Stream" method to use "WithCopyCodec" option --- FFMpegCore/FFMpeg/FFMpeg.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/FFMpegCore/FFMpeg/FFMpeg.cs b/FFMpegCore/FFMpeg/FFMpeg.cs index a8de12b..820d9fb 100644 --- a/FFMpegCore/FFMpeg/FFMpeg.cs +++ b/FFMpegCore/FFMpeg/FFMpeg.cs @@ -333,7 +333,10 @@ public static bool SaveM3U8Stream(Uri uri, string output) } return FFMpegArguments - .FromUrlInput(uri) + .FromUrlInput(uri, options => + { + options.WithCopyCodec(); + }) .OutputToFile(output) .ProcessSynchronously(); }