Files
FileFlowsPlugins/VideoNodes/VideoCodec.cs
2021-11-21 07:07:37 +13:00

41 lines
1.3 KiB
C#

namespace FileFlows.VideoNodes
{
using System.Linq;
using System.ComponentModel;
using FileFlows.Plugin;
using FileFlows.Plugin.Attributes;
public class VideoCodec : VideoNode
{
public override int Inputs => 1;
public override int Outputs => 2;
public override FlowElementType Type => FlowElementType.Logic;
[StringArray(1)]
public string[] Codecs { get; set; }
public override int Execute(NodeParameters args)
{
var videoInfo = GetVideoInfo(args);
if (videoInfo == null)
return -1;
var codec = videoInfo.VideoStreams.FirstOrDefault(x => Codecs.Contains(x.Codec.ToLower()));
if (codec != null)
{
args.Logger.ILog($"Matching video codec found[{codec.Index}]: {codec.Codec}");
return 1;
}
var acodec = videoInfo.AudioStreams.FirstOrDefault(x => Codecs.Contains(x.Codec.ToLower()));
if (acodec != null)
{
args.Logger.ILog($"Matching audio codec found[{acodec.Index}]: {acodec.Codec}, language: {acodec.Language}");
return 1;
}
// not found, execute 2nd outputacodec
return 2;
}
}
}