Skip to content

Commit

Permalink
remove hw acceleration
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm360 committed Jun 4, 2023
1 parent ae8577f commit afdd39d
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 52 deletions.
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand All @@ -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
Expand All @@ -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
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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; }
Expand Down
32 changes: 5 additions & 27 deletions src/EthernaVideoImporter.Core/Services/EncoderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,31 +100,19 @@ private void AppendOutputFFmpegCommandArgs(List<string> 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");

//filters
args.Add("-vf");
{
var filters = new List<string>();

//scale
switch (options.FFMpegHwAcceleration)
var filters = new List<string>
{
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}")}");
}
Expand Down Expand Up @@ -152,16 +140,6 @@ private IEnumerable<string> 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);

Expand Down
4 changes: 0 additions & 4 deletions src/EthernaVideoImporter.Devcon/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<FFMpegHwAccelerations>().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" +
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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<FFMpegHwAccelerations>(args[++i], true); break;
default: throw new ArgumentException(args[i] + " is not a valid argument");
}
}
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions src/EthernaVideoImporter/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<FFMpegHwAccelerations>().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" +
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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<FFMpegHwAccelerations>(args[++i], true); break;
default: throw new ArgumentException(args[i] + " is not a valid argument");
}
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit afdd39d

Please sign in to comment.