Made the service basically start working
This commit is contained in:
32
EncodingSampleTest/EncodingSampleTest.csproj
Normal file
32
EncodingSampleTest/EncodingSampleTest.csproj
Normal file
@@ -0,0 +1,32 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FFMpegCore" Version="5.4.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="testVid.mp4">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="vendor\ffmpeg.exe">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="vendor\ffprobe.exe">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="testVid6K.mp4">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="testVid8k.mp4">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
2
EncodingSampleTest/EncodingSampleTest.csproj.DotSettings
Normal file
2
EncodingSampleTest/EncodingSampleTest.csproj.DotSettings
Normal file
@@ -0,0 +1,2 @@
|
||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=vendor/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
||||
41
EncodingSampleTest/NvencExt.cs
Normal file
41
EncodingSampleTest/NvencExt.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace EncodingSampleTest;
|
||||
|
||||
public enum NvencSpeed {
|
||||
Default=0,
|
||||
Slow=1,
|
||||
Medium=2,
|
||||
Fast=3,
|
||||
p1=12,
|
||||
p2=13,
|
||||
p3=14,
|
||||
p4=15,
|
||||
p5=16,
|
||||
p6=17,
|
||||
p7=18,
|
||||
}
|
||||
|
||||
public enum NvencTune {
|
||||
hq=1,
|
||||
uhq=5,
|
||||
ll=2,
|
||||
ull=3,
|
||||
lossless=4,
|
||||
}
|
||||
|
||||
class NvencSpeedPreset(NvencSpeed speed) : FFMpegCore.Arguments.IArgument {
|
||||
public string Text { get { return $"-preset {speed.ToString().ToLower()}"; } }
|
||||
}
|
||||
|
||||
class NvencTuneArgument(NvencTune tune) : FFMpegCore.Arguments.IArgument {
|
||||
public string Text { get { return $"-tune {tune.ToString().ToLower()}"; } }
|
||||
}
|
||||
|
||||
class NvencHighBitDepthArgument(bool enable) : FFMpegCore.Arguments.IArgument {
|
||||
public string Text { get { return enable ? "-highbitdepth true" : string.Empty; } }
|
||||
}
|
||||
|
||||
class NvencQPArgument([Range(-1, 255)]byte qp) : FFMpegCore.Arguments.IArgument {
|
||||
public string Text { get { return $"-qp {qp}"; } }
|
||||
}
|
||||
65
EncodingSampleTest/Program.cs
Normal file
65
EncodingSampleTest/Program.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using EncodingSampleTest;
|
||||
using FFMpegCore;
|
||||
using FFMpegCore.Enums;
|
||||
|
||||
string ffmpegPath = Path.Combine(Environment.CurrentDirectory, "vendor");
|
||||
string tempPath = Path.Combine(Environment.CurrentDirectory, "tmp");
|
||||
string outputDir = Path.Combine(Environment.CurrentDirectory, "output");
|
||||
Directory.CreateDirectory(outputDir);
|
||||
Directory.CreateDirectory(tempPath);
|
||||
const string inputFile = "testVid8k.mp4";
|
||||
|
||||
GlobalFFOptions.Configure(options => {
|
||||
options.BinaryFolder = ffmpegPath;
|
||||
options.TemporaryFilesFolder = tempPath;
|
||||
});
|
||||
|
||||
if(!File.Exists(inputFile)) return;
|
||||
|
||||
var mediaInfo = FFProbe.Analyse(inputFile);
|
||||
if (mediaInfo.PrimaryVideoStream == null) {
|
||||
Console.WriteLine("No video stream found.");
|
||||
return;
|
||||
}
|
||||
var W = mediaInfo.PrimaryVideoStream.Width;
|
||||
var H = mediaInfo.PrimaryVideoStream.Height;
|
||||
|
||||
for (int qp = 32; qp <= 160; qp += 32) {
|
||||
await AV1Encode(W, H, qp);
|
||||
}
|
||||
|
||||
/*
|
||||
for (int qp = 32; qp <= 250; qp += 32) {
|
||||
await AV1Encode(1920, 1080, qp);
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
Task AV1Encode(int W = -1, int H = -1, int QP = 23) { // AV1 is visually lossless at QP 23
|
||||
var outputFile = Path.Combine(outputDir, $"output_av1-{W}x{H}_qp{QP}.mp4");
|
||||
var ffmpegArgs = FFMpegArguments
|
||||
.FromFileInput(inputFile, true, options => options
|
||||
.WithHardwareAcceleration()
|
||||
)
|
||||
.OutputToFile(outputFile, true, options => options
|
||||
.CopyChannel(Channel.Audio)
|
||||
.CopyChannel(Channel.Subtitle)
|
||||
.WithVideoCodec("hevc_nvenc")
|
||||
.WithArgument(new NvencSpeedPreset(NvencSpeed.p4))
|
||||
.WithArgument(new NvencTuneArgument(NvencTune.hq))
|
||||
.WithArgument(new NvencHighBitDepthArgument(true))
|
||||
.WithArgument(new NvencQPArgument((byte)QP))
|
||||
.WithVideoFilters(filterOptions => {
|
||||
if (W > 0 && H > 0) filterOptions.Scale(W, H);
|
||||
})
|
||||
.WithFastStart()
|
||||
)
|
||||
.WithLogLevel(FFMpegLogLevel.Info)
|
||||
.NotifyOnProgress(progress => Console.WriteLine($"Encoding {outputFile}: {progress:g}/{mediaInfo.Duration:g} {progress/mediaInfo.Duration:P}"));
|
||||
|
||||
Console.WriteLine(ffmpegArgs.Arguments);
|
||||
|
||||
var res = ffmpegArgs.ProcessSynchronously();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
Reference in New Issue
Block a user