BililiveRecorder/BililiveRecorder.Flv/Pipeline/Rules/FfmpegDetectionRule.cs

32 lines
1.1 KiB
C#
Raw Normal View History

2022-06-24 21:29:10 +08:00
using System;
using System.Linq;
using BililiveRecorder.Flv.Amf;
using BililiveRecorder.Flv.Pipeline.Actions;
namespace BililiveRecorder.Flv.Pipeline.Rules
{
public class FfmpegDetectionRule : ISimpleProcessingRule
{
public bool EndTagDetected { get; private set; }
public bool LavfEncoderDetected { get; private set; }
public void Run(FlvProcessingContext context, Action next)
{
if (!this.EndTagDetected && context.Actions.Any(x => x is PipelineEndAction))
this.EndTagDetected = true;
if (!this.LavfEncoderDetected && context.Actions.Any(action =>
{
if (action is PipelineScriptAction scriptAction
&& (scriptAction?.Tag?.ScriptData?.GetMetadataValue()?.Value?.TryGetValue("encoder", out var encoderValue) ?? false)
&& encoderValue is ScriptDataString encoder)
return encoder.Value.StartsWith("Lavf", StringComparison.Ordinal);
return false;
}))
this.LavfEncoderDetected = true;
next();
}
}
}