Skip to content

Commit 977ab17

Browse files
committed
Added libaom-av1 (ffmpeg), gop size now gets applied to x264/x265
1 parent 3505990 commit 977ab17

File tree

9 files changed

+64
-13
lines changed

9 files changed

+64
-13
lines changed

ff-utils-winforms/Data/CodecUtils.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class CodecUtils
1919
//public enum CodecType { Video, AnimImage, Image, Audio }
2020

2121
public enum Av1anCodec { AomAv1, SvtAv1, Vpx, X265 };
22-
public enum VideoCodec { CopyVideo, StripVideo, Libx264, Libx265, H264Nvenc, H265Nvenc, LibVpx, LibSvtAv1, Gif, Png, Jpg };
22+
public enum VideoCodec { CopyVideo, StripVideo, Libx264, Libx265, H264Nvenc, H265Nvenc, LibVpx, LibSvtAv1, LibAomAv1, Gif, Png, Jpg };
2323
public enum AudioCodec { CopyAudio, StripAudio, Aac, Opus, Vorbis, Mp3, Flac };
2424
public enum SubtitleCodec { CopySubs, StripSubs, MovText, Srt, WebVtt };
2525

@@ -33,6 +33,7 @@ public static IEncoder GetCodec(VideoCodec c)
3333
if (c == VideoCodec.H265Nvenc) return new H265Nvenc();
3434
if (c == VideoCodec.LibVpx) return new LibVpx();
3535
if (c == VideoCodec.LibSvtAv1) return new LibSvtAv1();
36+
if (c == VideoCodec.LibAomAv1) return new LibAomAv1();
3637
if (c == VideoCodec.Gif) return new Gif();
3738
if (c == VideoCodec.Png) return new Png();
3839
if (c == VideoCodec.Jpg) return new Jpg();
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using Nmkoder.Extensions;
2+
using Nmkoder.IO;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
6+
namespace Nmkoder.Data.Codecs
7+
{
8+
class LibAomAv1 : IEncoder
9+
{
10+
public Streams.Stream.StreamType Type { get; } = Streams.Stream.StreamType.Video;
11+
public string Name { get { return GetType().Name; } }
12+
public string FriendlyName { get; } = "AV1 (AOM-AV1)";
13+
public string[] Presets { get; } = new string[] { "0", "1", "2", "3", "4", "5", "6" };
14+
public int PresetDefault { get; } = 5;
15+
public string[] ColorFormats { get; } = new string[] { "yuv420p", "yuv420p10le" };
16+
public int ColorFormatDefault { get; } = 1;
17+
public int QMin { get; } = 0;
18+
public int QMax { get; } = 63;
19+
public int QDefault { get; } = 20;
20+
public string QInfo { get; } = "CRF (0-63 - Lower is better)";
21+
public string PresetInfo { get; } = "Lower = Better compression";
22+
23+
public bool SupportsTwoPass { get; } = true;
24+
public bool DoesNotEncode { get; } = false;
25+
public bool IsFixedFormat { get; } = false;
26+
public bool IsSequence { get; } = false;
27+
28+
public CodecArgs GetArgs(Dictionary<string, string> encArgs = null, MediaFile mediaFile = null, Pass pass = Pass.OneOfOne)
29+
{
30+
bool vbr = encArgs.ContainsKey("qMode") && (UI.Tasks.QuickConvert.QualityMode)encArgs["qMode"].GetInt() != UI.Tasks.QuickConvert.QualityMode.Crf;
31+
string g = CodecUtils.GetKeyIntArg(mediaFile, Config.GetInt(Config.Key.defaultKeyIntSecs));
32+
string q = encArgs.ContainsKey("q") ? encArgs["q"] : QDefault.ToString();
33+
string preset = encArgs.ContainsKey("preset") ? encArgs["preset"] : Presets[PresetDefault];
34+
string pixFmt = encArgs.ContainsKey("pixFmt") ? encArgs["pixFmt"] : ColorFormats[ColorFormatDefault];
35+
string grain = encArgs.ContainsKey("grainSynthStrength") ? encArgs["grainSynthStrength"] : "0";
36+
//string denoise = encArgs.ContainsKey("grainSynthDenoise") ? (encArgs["grainSynthDenoise"].GetBool() ? "1" : "0") : "0";
37+
string tiles = CodecUtils.GetTilingArgs(mediaFile.VideoStreams.FirstOrDefault().Resolution, "-tile-columns ", "-tile-rows ");
38+
string rc = vbr ? $"-b:v {(encArgs.ContainsKey("bitrate") ? encArgs["bitrate"] : "0")}k" : $"-crf {q} -b:v 0";
39+
string p = pass == Pass.OneOfOne ? "" : (pass == Pass.OneOfTwo ? "-pass 1" : "-pass 2");
40+
string cust = encArgs.ContainsKey("custom") ? encArgs["custom"] : "";
41+
return new CodecArgs($"-c:v libaom-av1 {p} {rc} -cpu-used {preset} -row-mt 1 -denoise-noise-level {grain} {tiles} {g} -pix_fmt {pixFmt} {cust}");
42+
}
43+
}
44+
}

ff-utils-winforms/Data/Codecs/Video/LibSvtAv1.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class LibSvtAv1 : IEncoder
1010
{
1111
public Streams.Stream.StreamType Type { get; } = Streams.Stream.StreamType.Video;
1212
public string Name { get { return GetType().Name; } }
13-
public string FriendlyName { get; } = "AV1 (svt-av1)";
13+
public string FriendlyName { get; } = "AV1 (SVT-AV1)";
1414
public string[] Presets { get; } = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8" };
1515
public int PresetDefault { get; } = 5;
1616
public string[] ColorFormats { get; } = new string[] { "yuv420p", "yuv420p10le" };

ff-utils-winforms/Data/Codecs/Video/Libx264.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Nmkoder.Extensions;
2+
using Nmkoder.IO;
23
using System;
34
using System.Collections.Generic;
45

@@ -27,13 +28,14 @@ class Libx264 : IEncoder
2728
public CodecArgs GetArgs(Dictionary<string, string> encArgs = null, MediaFile mediaFile = null, Pass pass = Pass.OneOfOne)
2829
{
2930
bool vbr = encArgs.ContainsKey("qMode") && (UI.Tasks.QuickConvert.QualityMode)encArgs["qMode"].GetInt() != UI.Tasks.QuickConvert.QualityMode.Crf;
31+
string g = CodecUtils.GetKeyIntArg(mediaFile, Config.GetInt(Config.Key.defaultKeyIntSecs));
3032
string q = encArgs.ContainsKey("q") ? encArgs["q"] : QDefault.ToString();
3133
string preset = encArgs.ContainsKey("preset") ? encArgs["preset"] : Presets[PresetDefault];
3234
string pixFmt = encArgs.ContainsKey("pixFmt") ? encArgs["pixFmt"] : ColorFormats[ColorFormatDefault];
3335
string rc = vbr ? $"-b:v {(encArgs.ContainsKey("bitrate") ? encArgs["bitrate"] : "0")}k" : $"-crf {q}";
3436
string p = pass == Pass.OneOfOne ? "" : (pass == Pass.OneOfTwo ? "-pass 1" : "-pass 2");
3537
string cust = encArgs.ContainsKey("custom") ? encArgs["custom"] : "";
36-
return new CodecArgs($"-c:v libx264 {p} {rc} -preset {preset} -pix_fmt {pixFmt} {cust}");
38+
return new CodecArgs($"-c:v libx264 {p} {rc} -preset {preset} {g} -pix_fmt {pixFmt} {cust}");
3739
}
3840
}
3941
}

ff-utils-winforms/Data/Codecs/Video/Libx265.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
using Nmkoder.Extensions;
2-
using System;
2+
using Nmkoder.IO;
33
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
74

85
namespace Nmkoder.Data.Codecs
96
{
@@ -30,13 +27,14 @@ class Libx265 : IEncoder
3027
public CodecArgs GetArgs(Dictionary<string, string> encArgs = null, MediaFile mediaFile = null, Pass pass = Pass.OneOfOne)
3128
{
3229
bool vbr = encArgs.ContainsKey("qMode") && (UI.Tasks.QuickConvert.QualityMode)encArgs["qMode"].GetInt() != UI.Tasks.QuickConvert.QualityMode.Crf;
30+
string g = CodecUtils.GetKeyIntArg(mediaFile, Config.GetInt(Config.Key.defaultKeyIntSecs));
3331
string q = encArgs.ContainsKey("q") ? encArgs["q"] : QDefault.ToString();
3432
string preset = encArgs.ContainsKey("preset") ? encArgs["preset"] : Presets[PresetDefault];
3533
string pixFmt = encArgs.ContainsKey("pixFmt") ? encArgs["pixFmt"] : ColorFormats[ColorFormatDefault];
3634
string rc = vbr ? $"-b:v {(encArgs.ContainsKey("bitrate") ? encArgs["bitrate"] : "0")}k" : $"-crf {q}";
3735
string p = pass == Pass.OneOfOne ? "" : (pass == Pass.OneOfTwo ? "-x265-params pass=1" : "-x265-params pass=2");
3836
string cust = encArgs.ContainsKey("custom") ? encArgs["custom"] : "";
39-
return new CodecArgs($"-c:v libx265 {p} {rc} -preset {preset} -pix_fmt {pixFmt} {cust}");
37+
return new CodecArgs($"-c:v libx265 {p} {rc} -preset {preset} {g} -pix_fmt {pixFmt} {cust}");
4038
}
4139
}
4240
}

ff-utils-winforms/Data/Codecs/Video/X265.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
using Nmkoder.Extensions;
22
using Nmkoder.IO;
3-
using System;
43
using System.Collections.Generic;
5-
using System.Linq;
64

75
namespace Nmkoder.Data.Codecs
86
{

ff-utils-winforms/Data/Containers.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ public enum Container { Mp4, Mkv, Webm, Mov, M4a, Ogg };
1616
public static VC[] GetSupportedVideoCodecs (Container c)
1717
{
1818
if (c == Container.Mp4)
19-
return new VC[] { VC.Libx264, VC.Libx265, VC.H264Nvenc, VC.H265Nvenc, VC.LibSvtAv1 };
19+
return new VC[] { VC.Libx264, VC.Libx265, VC.H264Nvenc, VC.H265Nvenc, VC.LibSvtAv1, VC.LibAomAv1 };
2020

2121
if (c == Container.Mkv)
22-
return new VC[] { VC.Libx264, VC.Libx265, VC.H264Nvenc, VC.H265Nvenc, VC.LibVpx, VC.LibSvtAv1, VC.Png, VC.Jpg };
22+
return new VC[] { VC.Libx264, VC.Libx265, VC.H264Nvenc, VC.H265Nvenc, VC.LibVpx, VC.LibSvtAv1, VC.LibAomAv1, VC.Png, VC.Jpg };
2323

2424
if (c == Container.Webm)
25-
return new VC[] { VC.LibVpx, VC.LibSvtAv1 };
25+
return new VC[] { VC.LibVpx, VC.LibSvtAv1, VC.LibAomAv1 };
2626

2727
if (c == Container.Mov)
2828
return new VC[] { VC.Libx264, VC.Libx265, VC.H264Nvenc, VC.H265Nvenc };

ff-utils-winforms/Media/FfmpegOutputHandler.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ public static void LogOutput(string line, ref string appendStr, string logFilena
4040
UpdateFfmpegProgress(timeRegex.Match(line).Value);
4141
}
4242

43+
44+
if (line.Contains("Unable to"))
45+
{
46+
RunTask.Cancel($"Error: {line}");
47+
return;
48+
}
49+
4350
if (line.Contains("Could not open file"))
4451
{
4552
RunTask.Cancel($"Error: {line}");

ff-utils-winforms/Nmkoder.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@
268268
<Compile Include="Data\Codecs\Subs\CopySubs.cs" />
269269
<Compile Include="Data\Codecs\Subs\WebVtt.cs" />
270270
<Compile Include="Data\Codecs\Video\AomAv1.cs" />
271+
<Compile Include="Data\Codecs\Video\LibAomAv1.cs" />
271272
<Compile Include="Data\Codecs\Video\LibSvtAv1.cs" />
272273
<Compile Include="Data\Codecs\Video\CopyVideo.cs" />
273274
<Compile Include="Data\Codecs\Video\Gif.cs" />

0 commit comments

Comments
 (0)