|
| 1 | +using Nmkoder.Data.Codecs; |
| 2 | +using Nmkoder.Extensions; |
| 3 | +using Nmkoder.IO; |
| 4 | +using System; |
| 5 | +using System.Collections.Generic; |
| 6 | +using System.Linq; |
| 7 | +using System.Text; |
| 8 | +using System.Threading.Tasks; |
| 9 | + |
| 10 | +namespace Nmkoder.Data |
| 11 | +{ |
| 12 | + class CodecUtils |
| 13 | + { |
| 14 | + //public enum CodecType { Video, AnimImage, Image, Audio } |
| 15 | + |
| 16 | + public enum Av1anCodec { AomAv1, SvtAv1, VpxVp9, X265 }; |
| 17 | + public enum VideoCodec { CopyVideo, StripVideo, H264, H265, H264Nvenc, H265Nvenc, Vp9, Av1, Gif, Png, Jpg }; |
| 18 | + public enum AudioCodec { CopyAudio, StripAudio, Aac, Opus, Mp3, Flac }; |
| 19 | + public enum SubtitleCodec { CopySubs, StripSubs, MovText, Srt, WebVtt }; |
| 20 | + |
| 21 | + public static IEncoder GetCodec(VideoCodec c) |
| 22 | + { |
| 23 | + if (c == VideoCodec.StripVideo) return new StripVideo(); |
| 24 | + if (c == VideoCodec.CopyVideo) return new CopyVideo(); |
| 25 | + if (c == VideoCodec.H264) return new H264(); |
| 26 | + if (c == VideoCodec.H264Nvenc) return new H264Nvenc(); |
| 27 | + if (c == VideoCodec.H265) return new H265(); |
| 28 | + if (c == VideoCodec.H265Nvenc) return new H265Nvenc(); |
| 29 | + if (c == VideoCodec.Vp9) return new Vp9(); |
| 30 | + if (c == VideoCodec.Av1) return new Av1(); |
| 31 | + if (c == VideoCodec.Gif) return new Gif(); |
| 32 | + if (c == VideoCodec.Png) return new Png(); |
| 33 | + if (c == VideoCodec.Jpg) return new Jpg(); |
| 34 | + return null; |
| 35 | + } |
| 36 | + |
| 37 | + public static IEncoder GetCodec(Av1anCodec c) |
| 38 | + { |
| 39 | + if (c == Av1anCodec.AomAv1) return new AomAv1(); |
| 40 | + if (c == Av1anCodec.SvtAv1) return new SvtAv1(); |
| 41 | + if (c == Av1anCodec.VpxVp9) return new VpxVp9(); |
| 42 | + if (c == Av1anCodec.X265) return new X265(); |
| 43 | + return null; |
| 44 | + } |
| 45 | + |
| 46 | + public static IEncoder GetCodec(AudioCodec c) |
| 47 | + { |
| 48 | + if (c == AudioCodec.StripAudio) return new StripAudio(); |
| 49 | + if (c == AudioCodec.CopyAudio) return new CopyAudio(); |
| 50 | + if (c == AudioCodec.Aac) return new Aac(); |
| 51 | + if (c == AudioCodec.Opus) return new Opus(); |
| 52 | + if (c == AudioCodec.Mp3) return new Mp3(); |
| 53 | + if (c == AudioCodec.Flac) return new Flac(); |
| 54 | + return null; |
| 55 | + } |
| 56 | + |
| 57 | + public static IEncoder GetCodec(SubtitleCodec c) |
| 58 | + { |
| 59 | + if (c == SubtitleCodec.StripSubs) return new StripSubs(); |
| 60 | + if (c == SubtitleCodec.CopySubs) return new CopySubs(); |
| 61 | + if (c == SubtitleCodec.MovText) return new MovText(); |
| 62 | + if (c == SubtitleCodec.Srt) return new Srt(); |
| 63 | + if (c == SubtitleCodec.WebVtt) return new WebVtt(); |
| 64 | + return null; |
| 65 | + } |
| 66 | + |
| 67 | + public static string GetKeyIntArg(MediaFile mediaFile, int intervalSeconds, string arg = "-g ") |
| 68 | + { |
| 69 | + if (mediaFile == null || mediaFile.VideoStreams.Count < 1) |
| 70 | + return ""; |
| 71 | + |
| 72 | + int keyInt = ((float)(mediaFile?.VideoStreams.FirstOrDefault().Rate.GetFloat() * intervalSeconds)).RoundToInt(); |
| 73 | + return keyInt >= 24 ? $"{arg}{keyInt}" : ""; |
| 74 | + } |
| 75 | + } |
| 76 | +} |
0 commit comments