mirror of
https://github.com/BililiveRecorder/BililiveRecorder.git
synced 2024-11-15 19:22:19 +08:00
Fix FFmpeg detection rule
This commit is contained in:
parent
4304284ff9
commit
d0c7863c9d
31
BililiveRecorder.Flv/Pipeline/Rules/FfmpegDetectionRule.cs
Normal file
31
BililiveRecorder.Flv/Pipeline/Rules/FfmpegDetectionRule.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -13,6 +13,7 @@ using BililiveRecorder.Flv.Grouping;
|
||||||
using BililiveRecorder.Flv.Parser;
|
using BililiveRecorder.Flv.Parser;
|
||||||
using BililiveRecorder.Flv.Pipeline;
|
using BililiveRecorder.Flv.Pipeline;
|
||||||
using BililiveRecorder.Flv.Pipeline.Actions;
|
using BililiveRecorder.Flv.Pipeline.Actions;
|
||||||
|
using BililiveRecorder.Flv.Pipeline.Rules;
|
||||||
using BililiveRecorder.Flv.Writer;
|
using BililiveRecorder.Flv.Writer;
|
||||||
using BililiveRecorder.Flv.Xml;
|
using BililiveRecorder.Flv.Xml;
|
||||||
using BililiveRecorder.ToolBox.ProcessingRules;
|
using BililiveRecorder.ToolBox.ProcessingRules;
|
||||||
|
|
|
@ -13,6 +13,7 @@ using BililiveRecorder.Flv.Grouping;
|
||||||
using BililiveRecorder.Flv.Parser;
|
using BililiveRecorder.Flv.Parser;
|
||||||
using BililiveRecorder.Flv.Pipeline;
|
using BililiveRecorder.Flv.Pipeline;
|
||||||
using BililiveRecorder.Flv.Pipeline.Actions;
|
using BililiveRecorder.Flv.Pipeline.Actions;
|
||||||
|
using BililiveRecorder.Flv.Pipeline.Rules;
|
||||||
using BililiveRecorder.Flv.Writer;
|
using BililiveRecorder.Flv.Writer;
|
||||||
using BililiveRecorder.Flv.Xml;
|
using BililiveRecorder.Flv.Xml;
|
||||||
using BililiveRecorder.ToolBox.ProcessingRules;
|
using BililiveRecorder.ToolBox.ProcessingRules;
|
||||||
|
|
|
@ -762,6 +762,13 @@ namespace BililiveRecorder.Flv.Pipeline
|
||||||
}
|
}
|
||||||
namespace BililiveRecorder.Flv.Pipeline.Rules
|
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 class HandleDelayedAudioHeaderRule : BililiveRecorder.Flv.Pipeline.IProcessingRule, BililiveRecorder.Flv.Pipeline.ISimpleProcessingRule
|
||||||
{
|
{
|
||||||
public HandleDelayedAudioHeaderRule() { }
|
public HandleDelayedAudioHeaderRule() { }
|
||||||
|
|
|
@ -3,6 +3,7 @@ using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using BililiveRecorder.Flv.Grouping;
|
using BililiveRecorder.Flv.Grouping;
|
||||||
using BililiveRecorder.Flv.Pipeline;
|
using BililiveRecorder.Flv.Pipeline;
|
||||||
|
using BililiveRecorder.Flv.Pipeline.Rules;
|
||||||
using BililiveRecorder.Flv.Writer;
|
using BililiveRecorder.Flv.Writer;
|
||||||
using BililiveRecorder.Flv.Xml;
|
using BililiveRecorder.Flv.Xml;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
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 writer = new FlvProcessingContextWriter(tagWriter: output, allowMissingHeader: true, disableKeyframes: true, logger: null);
|
||||||
var session = new Dictionary<object, object?>();
|
var session = new Dictionary<object, object?>();
|
||||||
var context = new FlvProcessingContext();
|
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)
|
while (true)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user