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

Support crf arg.

parent 01308cf9
No related branches found
No related tags found
No related merge requests found
...@@ -8,7 +8,7 @@ public static class OptionsProvider ...@@ -8,7 +8,7 @@ public static class OptionsProvider
{ {
public static readonly Option<string> PathOptions = new( public static readonly Option<string> PathOptions = new(
aliases: new[] { "--path", "-p" }, aliases: new[] { "--path", "-p" },
description: "Path of the projects to be changed.") description: "Path of the videos to be parsed.")
{ {
IsRequired = true IsRequired = true
}; };
......
...@@ -49,7 +49,7 @@ namespace Aiursoft.Parser.FFmpeg ...@@ -49,7 +49,7 @@ namespace Aiursoft.Parser.FFmpeg
Console.WriteLine($"{filePath} WILL be parsed!"); Console.WriteLine($"{filePath} WILL be parsed!");
File.Delete(newFileName); File.Delete(newFileName);
await _commandService.RunCommand("ffmpeg", $@"-i ""{filePath}"" -codec:a copy -codec:v {coder} -crf 20 ""{newFileName}""", folder, getOutput: false); await _commandService.RunCommand("ffmpeg", $@"-i ""{filePath}"" -codec:a copy -codec:v {coder} -crf {_options.CRF} ""{newFileName}""", folder, getOutput: false);
if (File.Exists(newFileName)) if (File.Exists(newFileName))
{ {
......
...@@ -7,10 +7,16 @@ namespace Aiursoft.Parser.FFmpeg; ...@@ -7,10 +7,16 @@ namespace Aiursoft.Parser.FFmpeg;
public class FFmpegHandler : ServiceCommandHandler<FFmpegEntry, StartUp> public class FFmpegHandler : ServiceCommandHandler<FFmpegEntry, StartUp>
{ {
private Option<bool> UseGPU = new Option<bool>( private Option<bool> UseGPU = new Option<bool>(
getDefaultValue: () => false,
aliases: new[] { "--gpu", "-g" }, aliases: new[] { "--gpu", "-g" },
description: "Show NVIDIA GPU to speed up parsing. Only if you have an NVIDIA GPU attached."); description: "Use NVIDIA GPU to speed up parsing. Only if you have an NVIDIA GPU attached.");
public override string Name => "parser"; private Option<int> CRF = new Option<int>(
getDefaultValue: () => 20,
aliases: new[] { "--crf", "-c" },
description: "The range of the CRF scale is 0–51, where 0 is lossless (for 8 bit only, for 10 bit use -qp 0), 20 is the default, and 51 is worst quality possible.");
public override string Name => "ffmpeg";
public override string Description => "The command to convert all video files to HEVC using FFmpeg."; public override string Description => "The command to convert all video files to HEVC using FFmpeg.";
...@@ -18,7 +24,8 @@ public class FFmpegHandler : ServiceCommandHandler<FFmpegEntry, StartUp> ...@@ -18,7 +24,8 @@ public class FFmpegHandler : ServiceCommandHandler<FFmpegEntry, StartUp>
{ {
return new Option[] return new Option[]
{ {
UseGPU UseGPU,
CRF
}; };
} }
...@@ -29,13 +36,14 @@ public class FFmpegHandler : ServiceCommandHandler<FFmpegEntry, StartUp> ...@@ -29,13 +36,14 @@ public class FFmpegHandler : ServiceCommandHandler<FFmpegEntry, StartUp>
OptionsProvider.PathOptions, OptionsProvider.PathOptions,
OptionsProvider.DryRunOption, OptionsProvider.DryRunOption,
OptionsProvider.VerboseOption, OptionsProvider.VerboseOption,
UseGPU); UseGPU,
CRF);
} }
public Task ExecuteOverride(string path, bool dryRun, bool verbose, bool useGPU) public Task ExecuteOverride(string path, bool dryRun, bool verbose, bool useGPU, int crf)
{ {
var services = BuildServices(verbose); var services = BuildServices(verbose);
services.AddSingleton(new FFmpegOptions { UseGPU = useGPU }); services.AddSingleton(new FFmpegOptions { UseGPU = useGPU, CRF = crf });
return RunFromServices(services, path, dryRun); return RunFromServices(services, path, dryRun);
} }
} }
...@@ -9,5 +9,6 @@ namespace Aiursoft.Parser.FFmpeg ...@@ -9,5 +9,6 @@ namespace Aiursoft.Parser.FFmpeg
public class FFmpegOptions public class FFmpegOptions
{ {
public bool UseGPU { get; set; } public bool UseGPU { get; set; }
public int CRF { get; set; }
} }
} }
using Aiursoft.Parser.Core.Framework; using Aiursoft.Parser.Core.Framework;
using Aiursoft.Parser.FFmpeg;
using System.CommandLine; using System.CommandLine;
using System.Reflection;
var description = "A cli tool project helps to re-encode and save all videos under a path."; var descriptionAttribute = (Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly()).GetCustomAttribute<AssemblyDescriptionAttribute>()?.Description;
var program = new RootCommand(description) var program = new RootCommand(descriptionAttribute ?? "Unknown usage.")
.AddGlobalOptions() .AddGlobalOptions()
.AddPlugins(); .AddPlugins(
new FFmpegPlugin()
);
return await program.InvokeAsync(args); return await program.InvokeAsync(args);
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