|
| 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 | +} |
0 commit comments