Skip to content
Snippets Groups Projects
Commit 01308cf9 authored by Anduin Xue's avatar Anduin Xue
Browse files

Full integrate GPU.

parent f38e376e
No related branches found
No related tags found
No related merge requests found
Showing
with 120 additions and 74 deletions
......@@ -7,6 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Parser", "src\Parser\Parser
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Parser.Core", "src\Parser.Core\Parser.Core.csproj", "{8BB6EA69-6487-4709-B329-65B2F26DBDC2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Parser.FFmpeg", "src\Parser.FFMPEG\Parser.FFmpeg.csproj", "{50D3CEAA-D632-4678-BE04-3F1B468B5B96}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
......@@ -21,6 +23,10 @@ Global
{8BB6EA69-6487-4709-B329-65B2F26DBDC2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8BB6EA69-6487-4709-B329-65B2F26DBDC2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8BB6EA69-6487-4709-B329-65B2F26DBDC2}.Release|Any CPU.Build.0 = Release|Any CPU
{50D3CEAA-D632-4678-BE04-3F1B468B5B96}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{50D3CEAA-D632-4678-BE04-3F1B468B5B96}.Debug|Any CPU.Build.0 = Debug|Any CPU
{50D3CEAA-D632-4678-BE04-3F1B468B5B96}.Release|Any CPU.ActiveCfg = Release|Any CPU
{50D3CEAA-D632-4678-BE04-3F1B468B5B96}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......

using Aiursoft.Parser.Core.Models.Framework;
using Aiursoft.Parser.Core.Framework;
namespace Aiursoft.Parser.Core;
public interface INinjaPlugin
public interface IParserPlugin
{
public CommandHandler[] Install();
}
......@@ -2,7 +2,7 @@
using System.CommandLine;
namespace Aiursoft.Parser.Core.Models.Framework;
namespace Aiursoft.Parser.Core.Framework;
public abstract class CommandHandler
{
......
......@@ -2,7 +2,7 @@
using System.CommandLine;
namespace Aiursoft.Parser.Core.Models.Framework;
namespace Aiursoft.Parser.Core.Framework;
public static class OptionsProvider
{
......@@ -41,7 +41,7 @@ public static class OptionsProvider
return command;
}
public static RootCommand AddPlugins(this RootCommand command, params INinjaPlugin[] pluginInstallers)
public static RootCommand AddPlugins(this RootCommand command, params IParserPlugin[] pluginInstallers)
{
foreach (var plugin in pluginInstallers)
{
......
......@@ -4,7 +4,7 @@ using System.CommandLine;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace Aiursoft.Parser.Core.Models.Framework;
namespace Aiursoft.Parser.Core.Framework;
public abstract class ServiceCommandHandler<TE, TS> : CommandHandler
where TE : class, IEntryService
......
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.IO;
using Microsoft.Extensions.Logging;
using Parser;
using Aiursoft.Parser.Core;
using Aiursoft.Parser.FFmpeg.Services;
namespace Aiursoft.Parser.OBS
namespace Aiursoft.Parser.FFmpeg
{
public class OldEntry
public class FFmpegEntry : IEntryService
{
private readonly FFmpegOptions _options;
private readonly CommandService _commandService;
private readonly ILogger<OldEntry> logger;
public OldEntry(
CommandService commandService,
ILogger<OldEntry> logger)
public FFmpegEntry(
FFmpegOptions options,
CommandService commandService)
{
_options = options;
_commandService = commandService;
this.logger = logger;
}
public async Task StartEntry(string[] args)
public async Task OnServiceStartedAsync(string path, bool shouldTakeAction)
{
Console.WriteLine("Starting parser...");
if (args.Length < 1)
{
Console.WriteLine("Usage: WorkingPath [useGPU]");
Console.WriteLine("Current parameters:");
foreach (var arg in args)
{
Console.WriteLine(arg);
}
return;
}
var workingPath = args[0];
var videos = Directory.EnumerateFiles(workingPath, "*.*", SearchOption.AllDirectories)
var videos = Directory.EnumerateFiles(path, "*.*", SearchOption.AllDirectories)
.Where(v =>
v.EndsWith(".webm") ||
v.EndsWith(".mp4") ||
......@@ -49,7 +28,7 @@ namespace Aiursoft.Parser.OBS
foreach (var file in videos)
{
await Parse(file, coder: args.Any(a => a.Equals("useGPU", StringComparison.OrdinalIgnoreCase)) ? "hevc_nvenc" : "libx265");
await Parse(file, coder: _options.UseGPU ? "hevc_nvenc" : "libx265");
}
}
......
using Aiursoft.Parser.Core.Framework;
using Microsoft.Extensions.DependencyInjection;
using System.CommandLine;
namespace Aiursoft.Parser.FFmpeg;
public class FFmpegHandler : ServiceCommandHandler<FFmpegEntry, StartUp>
{
private Option<bool> UseGPU = new Option<bool>(
aliases: new[] { "--gpu", "-g" },
description: "Show NVIDIA GPU to speed up parsing. Only if you have an NVIDIA GPU attached.");
public override string Name => "parser";
public override string Description => "The command to convert all video files to HEVC using FFmpeg.";
public override Option[] GetOptions()
{
return new Option[]
{
UseGPU
};
}
public override void OnCommandBuilt(Command command)
{
command.SetHandler(
ExecuteOverride,
OptionsProvider.PathOptions,
OptionsProvider.DryRunOption,
OptionsProvider.VerboseOption,
UseGPU);
}
public Task ExecuteOverride(string path, bool dryRun, bool verbose, bool useGPU)
{
var services = BuildServices(verbose);
services.AddSingleton(new FFmpegOptions { UseGPU = useGPU });
return RunFromServices(services, path, dryRun);
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Aiursoft.Parser.FFmpeg
{
public class FFmpegOptions
{
public bool UseGPU { get; set; }
}
}
using Aiursoft.Parser.Core;
using Aiursoft.Parser.Core.Framework;
namespace Aiursoft.Parser.FFmpeg;
public class FFmpegPlugin : IParserPlugin
{
public CommandHandler[] Install() => new CommandHandler[] { new FFmpegHandler() };
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>Aiursoft.Parser.FFmpeg</RootNamespace>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Parser.Core\Parser.Core.csproj" />
</ItemGroup>
</Project>
using System.Diagnostics;
using System.Threading.Tasks;
namespace Parser
namespace Aiursoft.Parser.FFmpeg.Services
{
public class CommandService
{
......
using Aiursoft.Parser.Core;
using Aiursoft.Parser.FFmpeg.Services;
using Microsoft.Extensions.DependencyInjection;
namespace Aiursoft.Parser.FFmpeg;
public class StartUp : IStartUp
{
public void ConfigureServices(IServiceCollection services)
{
services.AddTransient<CommandService>();
}
}
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Parser;
namespace Aiursoft.Parser.OBS
{
public static class OldProgram
{
public static async Task MainObs(string[] args)
{
var services = new ServiceCollection();
services.AddLogging(logging =>
{
logging.AddConsole();
logging.SetMinimumLevel(LogLevel.Information);
});
services.AddSingleton<OldEntry>();
services.AddTransient<CommandService>();
var serviceProvider = services.BuildServiceProvider();
var entry = serviceProvider.GetRequiredService<OldEntry>();
await entry.StartEntry(args);
}
}
}
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!--Build and code-->
......@@ -32,7 +32,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Parser.Core\Parser.Core.csproj" />
<ProjectReference Include="..\Parser.FFMPEG\Parser.FFmpeg.csproj" />
</ItemGroup>
</Project>
using Aiursoft.Parser.Core.Models.Framework;
using Aiursoft.Parser.Core.Framework;
using System.CommandLine;
var description = "A cli tool project helps to re-encode and save all videos under a path.";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment