From afdd39d1ab2dae9d72e0bb4e6c7831951d133608 Mon Sep 17 00:00:00 2001 From: Mirko Da Corte Date: Sun, 4 Jun 2023 11:53:37 +0200 Subject: [PATCH] remove hw acceleration --- README.md | 6 ---- .../Models/Domain/FFMpegHwAccelerations.cs | 8 ----- .../Options/EncoderServiceOptions.cs | 4 +-- .../Services/EncoderService.cs | 32 +++---------------- src/EthernaVideoImporter.Devcon/Program.cs | 4 --- src/EthernaVideoImporter/Program.cs | 4 --- 6 files changed, 6 insertions(+), 52 deletions(-) delete mode 100644 src/EthernaVideoImporter.Core/Models/Domain/FFMpegHwAccelerations.cs diff --git a/README.md b/README.md index 35a88cf..78ef580 100644 --- a/README.md +++ b/README.md @@ -18,10 +18,6 @@ Future releases will improve this aspect accepting API keys instead. ### Setup FFmpeg To run the importer it is necessary to download [FFmpeg](https://ffmpeg.org/download.html) locally, and copy the binary file into the default folder "\FFmpeg", or specify its location with arguments. -### Setup CUDA Toolkit (optional) -To use hardware acceleration with CUDA is necessary to install [CUDA Toolkit](https://developer.nvidia.com/cuda-toolkit). -Moreover, is necessary to use an FFmpeg version compiled with support to hardware acceleration. - ### How to use **EthernaVideoImporter's help** @@ -35,7 +31,6 @@ Source types: Options: -ff Path FFmpeg (default dir: .\FFmpeg\) - -hw Use hardware acceleration on FFmpeg (default: none). Valid values: [none, cuda] -t TTL (days) Postage Stamp (default value: 365 days) -o Offer video downloads to everyone -p Pin videos @@ -62,7 +57,6 @@ Usage: EthernaVideoImporter.Devcon md MD_FOLDER [OPTIONS] Options: -ff Path FFmpeg (default dir: .\FFmpeg\) - -hw Use hardware acceleration on FFmpeg (default: none). Valid values: [none, cuda] -t TTL (days) Postage Stamp (default value: 365 days) -o Offer video downloads to everyone -p Pin videos diff --git a/src/EthernaVideoImporter.Core/Models/Domain/FFMpegHwAccelerations.cs b/src/EthernaVideoImporter.Core/Models/Domain/FFMpegHwAccelerations.cs deleted file mode 100644 index d23559f..0000000 --- a/src/EthernaVideoImporter.Core/Models/Domain/FFMpegHwAccelerations.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Etherna.VideoImporter.Core.Models.Domain -{ - public enum FFMpegHwAccelerations - { - None, - Cuda - } -} diff --git a/src/EthernaVideoImporter.Core/Options/EncoderServiceOptions.cs b/src/EthernaVideoImporter.Core/Options/EncoderServiceOptions.cs index b1fd377..b98722c 100644 --- a/src/EthernaVideoImporter.Core/Options/EncoderServiceOptions.cs +++ b/src/EthernaVideoImporter.Core/Options/EncoderServiceOptions.cs @@ -1,5 +1,4 @@ -using Etherna.VideoImporter.Core.Models.Domain; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; namespace Etherna.VideoImporter.Core.Options @@ -9,7 +8,6 @@ public sealed class EncoderServiceOptions // Properties. public string FFMpegBinaryPath => Path.Combine(FFMpegFolderPath, CommonConsts.FFMpegBinaryName); public string FFMpegFolderPath { get; set; } = CommonConsts.DefaultFFmpegFolder; - public FFMpegHwAccelerations FFMpegHwAcceleration { get; set; } = FFMpegHwAccelerations.None; public bool IncludeAudioTrack { get; set; } public bool Skip360 { get; set; } public bool Skip480 { get; set; } diff --git a/src/EthernaVideoImporter.Core/Services/EncoderService.cs b/src/EthernaVideoImporter.Core/Services/EncoderService.cs index 26fdab7..8b29536 100644 --- a/src/EthernaVideoImporter.Core/Services/EncoderService.cs +++ b/src/EthernaVideoImporter.Core/Services/EncoderService.cs @@ -100,12 +100,7 @@ private void AppendOutputFFmpegCommandArgs(List args, int height, int wi args.Add("-c:a"); args.Add("aac"); //video codec - args.Add("-c:v"); args.Add(options.FFMpegHwAcceleration switch - { - FFMpegHwAccelerations.None => "libx264", - FFMpegHwAccelerations.Cuda => "h264_nvenc", - _ => throw new InvalidOperationException() - }); + args.Add("-c:v"); args.Add("libx264"); //flags args.Add("-movflags"); args.Add("faststart"); @@ -113,18 +108,11 @@ private void AppendOutputFFmpegCommandArgs(List args, int height, int wi //filters args.Add("-vf"); { - var filters = new List(); - - //scale - switch (options.FFMpegHwAcceleration) + var filters = new List { - case FFMpegHwAccelerations.Cuda: - filters.Add($"scale_cuda=w={width}:h={height}"); - break; - default: - filters.Add($"scale=w={width}:h={height}"); - break; - } + //scale + $"scale=w={width}:h={height}" + }; args.Add($"{filters.Aggregate((r, f) => $"{r},{f}")}"); } @@ -152,16 +140,6 @@ private IEnumerable BuildFFmpegCommandArgs( var resolutionRatio = (decimal)sourceVideoFile.Width / sourceVideoFile.Height; var outputsList = new List<(string filePath, int height, int width)>(); - //hw acceleration - switch (options.FFMpegHwAcceleration) - { - case FFMpegHwAccelerations.Cuda: - args.Add("-hwaccel"); args.Add("cuda"); - args.Add("-hwaccel_output_format"); args.Add("cuda"); - break; - default: break; - } - //input args.Add("-i"); args.Add(sourceVideoFile.FilePath); diff --git a/src/EthernaVideoImporter.Devcon/Program.cs b/src/EthernaVideoImporter.Devcon/Program.cs index 6324b25..80f3de9 100644 --- a/src/EthernaVideoImporter.Devcon/Program.cs +++ b/src/EthernaVideoImporter.Devcon/Program.cs @@ -41,7 +41,6 @@ internal static class Program "\n" + "Options:\n" + $" -ff\tPath FFmpeg (default dir: {CommonConsts.DefaultFFmpegFolder})\n" + - $" -hw\tUse hardware acceleration on FFmpeg (default: {nameof(FFMpegHwAccelerations.None).ToLowerInvariant()}). Valid values: [{Enum.GetNames().Aggregate((r, i) => $"{r}, {i}").ToLowerInvariant()}]\n" + $" -t\tTTL (days) Postage Stamp (default value: {VideoUploaderServiceOptions.DefaultTtlPostageStamp.TotalDays} days)\n" + " -o\tOffer video downloads to everyone\n" + " -p\tPin videos\n" + @@ -89,7 +88,6 @@ static async Task Main(string[] args) bool skip480 = false; bool skip360 = false; bool useBeeNativeNode = false; - var ffMpegHwAcceleration = FFMpegHwAccelerations.None; // Parse input. if (args.Length == 0) @@ -175,7 +173,6 @@ static async Task Main(string[] args) case "-skip720": skip720 = true; break; case "-skip480": skip480 = true; break; case "-skip360": skip360 = true; break; - case "-hw": ffMpegHwAcceleration = Enum.Parse(args[++i], true); break; default: throw new ArgumentException(args[i] + " is not a valid argument"); } } @@ -237,7 +234,6 @@ static async Task Main(string[] args) { if (customFFMpegFolderPath is not null) encoderOptions.FFMpegFolderPath = customFFMpegFolderPath; - encoderOptions.FFMpegHwAcceleration = ffMpegHwAcceleration; encoderOptions.IncludeAudioTrack = includeAudioTrack; encoderOptions.Skip1440 = skip1440; encoderOptions.Skip1080 = skip1080; diff --git a/src/EthernaVideoImporter/Program.cs b/src/EthernaVideoImporter/Program.cs index 7b405e6..4c6bef9 100644 --- a/src/EthernaVideoImporter/Program.cs +++ b/src/EthernaVideoImporter/Program.cs @@ -47,7 +47,6 @@ internal static class Program "\n" + "Options:\n" + $" -ff\tPath FFmpeg (default dir: {CommonConsts.DefaultFFmpegFolder})\n" + - $" -hw\tUse hardware acceleration on FFmpeg (default: {nameof(FFMpegHwAccelerations.None).ToLowerInvariant()}). Valid values: [{Enum.GetNames().Aggregate((r, i) => $"{r}, {i}").ToLowerInvariant()}]\n" + $" -t\tTTL (days) Postage Stamp (default value: {VideoUploaderServiceOptions.DefaultTtlPostageStamp.TotalDays} days)\n" + " -o\tOffer video downloads to everyone\n" + " -p\tPin videos\n" + @@ -96,7 +95,6 @@ static async Task Main(string[] args) bool skip480 = false; bool skip360 = false; bool useBeeNativeNode = false; - var ffMpegHwAcceleration = FFMpegHwAccelerations.None; // Parse input. if (args.Length == 0) @@ -198,7 +196,6 @@ static async Task Main(string[] args) case "-skip720": skip720 = true; break; case "-skip480": skip480 = true; break; case "-skip360": skip360 = true; break; - case "-hw": ffMpegHwAcceleration = Enum.Parse(args[++i], true); break; default: throw new ArgumentException(args[i] + " is not a valid argument"); } } @@ -259,7 +256,6 @@ static async Task Main(string[] args) { if (customFFMpegFolderPath is not null) encoderOptions.FFMpegFolderPath = customFFMpegFolderPath; - encoderOptions.FFMpegHwAcceleration = ffMpegHwAcceleration; encoderOptions.IncludeAudioTrack = includeAudioTrack; encoderOptions.Skip1440 = skip1440; encoderOptions.Skip1080 = skip1080;