Skip to content
This repository was archived by the owner on Apr 13, 2024. It is now read-only.

Commit a6b1299

Browse files
author
Marcos Cordeiro
committed
Adds ffmpeg threads options
1 parent 2c02708 commit a6b1299

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

Wasari.Cli/Commands/DownloadCommand.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.ComponentModel.DataAnnotations;
1+
using System.ComponentModel.DataAnnotations;
22
using CliFx;
33
using CliFx.Attributes;
44
using CliFx.Exceptions;
@@ -93,6 +93,9 @@ public DownloadCommand(EnvironmentService environmentService, ILogger<DownloadCo
9393

9494
[CommandOption("enrich-episodes", Description = "If true, will try to enrich episodes with metadata from TVDB (Fixes season and episode numbers)")]
9595
public bool EnrichEpisodes { get; init; } = true;
96+
97+
[CommandOption("ffmpeg-threads", Description = "Number of threads to use for FFmpeg")]
98+
public int FfmpegThreads { get; init; } = 8;
9699

97100
private EnvironmentService EnvironmentService { get; }
98101

@@ -196,6 +199,7 @@ public async ValueTask ExecuteAsync(IConsole console)
196199
o.UseTemporaryEncodingPath = UseTemporaryEncodingPath;
197200
o.Shaders = Shaders;
198201
o.Resolution = Resolution;
202+
o.Threads = FfmpegThreads;
199203
});
200204
serviceCollection.Configure<AuthenticationOptions>(o =>
201205
{

Wasari.FFmpeg/FFmpegOptions.cs

+2
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ public record FFmpegOptions
1111
public bool UseNvidiaAcceleration { get; set; }
1212

1313
public bool UseTemporaryEncodingPath { get; set; }
14+
15+
public int Threads { get; set; } = 8;
1416
}

Wasari.FFmpeg/FFmpegService.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,22 @@ private static FileInfo CompileShaders(IEnumerable<IFFmpegShader> shaders)
5555

5656
private async IAsyncEnumerable<string> BuildArgumentsForEpisode(IWasariEpisode episode, string filePath)
5757
{
58+
yield return $"-threads {Options.Value.Threads}";
59+
5860
await using var providerScope = Provider.CreateAsyncScope();
5961
var inputs = await episode.InputsFactory(providerScope.ServiceProvider);
6062

6163
if (inputs.Count == 0)
6264
{
6365
throw new EmptyFFmpegInputsException(episode);
6466
}
65-
66-
67+
6768
var resolution = Options.Value.Resolution ?? inputs.Where(i => i.Type is InputType.Video or InputType.VideoWithAudio)
6869
.Select(i =>
6970
{
7071
var mediaAnalysis = FFProbe.Analyse(new Uri(i.Url));
7172

72-
var videoStream = i is IWasariEpisodeInputStreamSelector { VideoIndex: { } } streamSelector ? mediaAnalysis.VideoStreams.Single(o => o.Index == streamSelector.VideoIndex.Value) : mediaAnalysis.PrimaryVideoStream;
73+
var videoStream = i is IWasariEpisodeInputStreamSelector { VideoIndex: not null } streamSelector ? mediaAnalysis.VideoStreams.Single(o => o.Index == streamSelector.VideoIndex.Value) : mediaAnalysis.PrimaryVideoStream;
7374
return videoStream == null ? null : new FFmpegResolution(videoStream.Width, videoStream.Height);
7475
}).Single(i => i != null);
7576

0 commit comments

Comments
 (0)