Fix FFmpeg detection rule

This commit is contained in:
genteure 2022-06-24 21:29:10 +08:00
parent 4304284ff9
commit d0c7863c9d
6 changed files with 42 additions and 42 deletions

View File

@ -0,0 +1,31 @@
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();
}
}
}

View File

@ -1,41 +0,0 @@
using System;
using System.Linq;
using BililiveRecorder.Flv.Amf;
using BililiveRecorder.Flv.Pipeline;
using BililiveRecorder.Flv.Pipeline.Actions;
namespace BililiveRecorder.ToolBox.ProcessingRules
{
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)
{
if (context.Actions.Any(action =>
{
if (action is PipelineScriptAction scriptAction)
{
var encoder = scriptAction?.Tag?.ScriptData?.GetMetadataValue()?.Value?["encoder"] as ScriptDataString;
if (encoder is not null)
{
return encoder.Value.StartsWith("Lavf", StringComparison.Ordinal);
}
}
return false;
}))
{
this.LavfEncoderDetected = true;
}
}
}
}
}

View File

@ -13,6 +13,7 @@ using BililiveRecorder.Flv.Grouping;
using BililiveRecorder.Flv.Parser;
using BililiveRecorder.Flv.Pipeline;
using BililiveRecorder.Flv.Pipeline.Actions;
using BililiveRecorder.Flv.Pipeline.Rules;
using BililiveRecorder.Flv.Writer;
using BililiveRecorder.Flv.Xml;
using BililiveRecorder.ToolBox.ProcessingRules;

View File

@ -13,6 +13,7 @@ using BililiveRecorder.Flv.Grouping;
using BililiveRecorder.Flv.Parser;
using BililiveRecorder.Flv.Pipeline;
using BililiveRecorder.Flv.Pipeline.Actions;
using BililiveRecorder.Flv.Pipeline.Rules;
using BililiveRecorder.Flv.Writer;
using BililiveRecorder.Flv.Xml;
using BililiveRecorder.ToolBox.ProcessingRules;

View File

@ -762,6 +762,13 @@ namespace BililiveRecorder.Flv.Pipeline
}
namespace BililiveRecorder.Flv.Pipeline.Rules
{
public class FfmpegDetectionRule : BililiveRecorder.Flv.Pipeline.IProcessingRule, BililiveRecorder.Flv.Pipeline.ISimpleProcessingRule
{
public FfmpegDetectionRule() { }
public bool EndTagDetected { get; }
public bool LavfEncoderDetected { get; }
public void Run(BililiveRecorder.Flv.Pipeline.FlvProcessingContext context, System.Action next) { }
}
public class HandleDelayedAudioHeaderRule : BililiveRecorder.Flv.Pipeline.IProcessingRule, BililiveRecorder.Flv.Pipeline.ISimpleProcessingRule
{
public HandleDelayedAudioHeaderRule() { }

View File

@ -3,6 +3,7 @@ using System.Linq;
using System.Threading.Tasks;
using BililiveRecorder.Flv.Grouping;
using BililiveRecorder.Flv.Pipeline;
using BililiveRecorder.Flv.Pipeline.Rules;
using BililiveRecorder.Flv.Writer;
using BililiveRecorder.Flv.Xml;
using Microsoft.Extensions.DependencyInjection;
@ -17,7 +18,7 @@ namespace BililiveRecorder.Flv.Tests.RuleTests
var writer = new FlvProcessingContextWriter(tagWriter: output, allowMissingHeader: true, disableKeyframes: true, logger: null);
var session = new Dictionary<object, object?>();
var context = new FlvProcessingContext();
var pipeline = new ProcessingPipelineBuilder(new ServiceCollection().BuildServiceProvider()).AddDefault().AddRemoveFillerData().Build();
var pipeline = new ProcessingPipelineBuilder(new ServiceCollection().BuildServiceProvider()).Add<FfmpegDetectionRule>().AddDefault().AddRemoveFillerData().Build();
while (true)
{