mirror of
https://github.com/BililiveRecorder/BililiveRecorder.git
synced 2024-11-15 19:22:19 +08:00
Toolbox: Add FFmpeg detection
This commit is contained in:
parent
71334605c9
commit
4304284ff9
|
@ -0,0 +1,41 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -93,7 +93,8 @@ namespace BililiveRecorder.ToolBox.Tool.Analyze
|
|||
using var grouping = new TagGroupReader(tagReader);
|
||||
using var writer = new FlvProcessingContextWriter(tagWriter: tagWriter, allowMissingHeader: true, disableKeyframes: true, logger: logger);
|
||||
var statsRule = new StatsRule();
|
||||
var pipeline = new ProcessingPipelineBuilder(new ServiceCollection().BuildServiceProvider()).Add(statsRule).AddDefault().AddRemoveFillerData().Build();
|
||||
var ffmpegDetectionRule = new FfmpegDetectionRule();
|
||||
var pipeline = new ProcessingPipelineBuilder(new ServiceCollection().BuildServiceProvider()).Add(statsRule).Add(ffmpegDetectionRule).AddDefault().AddRemoveFillerData().Build();
|
||||
|
||||
// Run
|
||||
await Task.Run(async () =>
|
||||
|
@ -144,6 +145,7 @@ namespace BililiveRecorder.ToolBox.Tool.Analyze
|
|||
|
||||
NeedFix = tagWriter.OutputFileCount != 1 || countableComments.Any(),
|
||||
Unrepairable = countableComments.Any(x => x.Type == CommentType.Unrepairable),
|
||||
FfmpegDetected = ffmpegDetectionRule.LavfEncoderDetected && ffmpegDetectionRule.EndTagDetected,
|
||||
|
||||
OutputFileCount = tagWriter.OutputFileCount,
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ namespace BililiveRecorder.ToolBox.Tool.Analyze
|
|||
|
||||
public bool NeedFix { get; set; }
|
||||
public bool Unrepairable { get; set; }
|
||||
public bool FfmpegDetected { get; set; }
|
||||
|
||||
public int OutputFileCount { get; set; }
|
||||
|
||||
|
@ -41,6 +42,18 @@ namespace BililiveRecorder.ToolBox.Tool.Analyze
|
|||
});
|
||||
}
|
||||
|
||||
if (this.FfmpegDetected)
|
||||
{
|
||||
AnsiConsole.Write(new Panel("This file seems like it was written by FFmpeg.\n" +
|
||||
"It might no longer possible to fix this file, if there's any problem.\n" +
|
||||
"Only unprocessed data taken directly from the stream server could be fixed.")
|
||||
{
|
||||
Header = new PanelHeader("[bold yellow]FFmpeg Detected[/]"),
|
||||
Border = BoxBorder.Rounded,
|
||||
BorderStyle = new Style(foreground: Color.Yellow)
|
||||
});
|
||||
}
|
||||
|
||||
AnsiConsole.Write(new Panel(this.InputPath.EscapeMarkup())
|
||||
{
|
||||
Header = new PanelHeader("Input"),
|
||||
|
|
|
@ -112,7 +112,8 @@ namespace BililiveRecorder.ToolBox.Tool.Fix
|
|||
using var grouping = new TagGroupReader(tagReader);
|
||||
using var writer = new FlvProcessingContextWriter(tagWriter: tagWriter, allowMissingHeader: true, disableKeyframes: false, logger: logger);
|
||||
var statsRule = new StatsRule();
|
||||
var pipeline = new ProcessingPipelineBuilder(new ServiceCollection().BuildServiceProvider()).Add(statsRule).AddDefault().AddRemoveFillerData().Build();
|
||||
var ffmpegDetectionRule = new FfmpegDetectionRule();
|
||||
var pipeline = new ProcessingPipelineBuilder(new ServiceCollection().BuildServiceProvider()).Add(statsRule).Add(ffmpegDetectionRule).AddDefault().AddRemoveFillerData().Build();
|
||||
|
||||
// Run
|
||||
await Task.Run(async () =>
|
||||
|
@ -200,6 +201,7 @@ namespace BililiveRecorder.ToolBox.Tool.Fix
|
|||
|
||||
NeedFix = outputPaths.Count != 1 || countableComments.Any(),
|
||||
Unrepairable = countableComments.Any(x => x.Type == CommentType.Unrepairable),
|
||||
FfmpegDetected = ffmpegDetectionRule.LavfEncoderDetected && ffmpegDetectionRule.EndTagDetected,
|
||||
|
||||
VideoStats = videoStats,
|
||||
AudioStats = audioStats,
|
||||
|
|
|
@ -12,6 +12,7 @@ namespace BililiveRecorder.ToolBox.Tool.Fix
|
|||
|
||||
public bool NeedFix { get; set; }
|
||||
public bool Unrepairable { get; set; }
|
||||
public bool FfmpegDetected { get; set; }
|
||||
|
||||
public int OutputFileCount { get; set; }
|
||||
|
||||
|
@ -41,6 +42,18 @@ namespace BililiveRecorder.ToolBox.Tool.Fix
|
|||
});
|
||||
}
|
||||
|
||||
if (this.FfmpegDetected)
|
||||
{
|
||||
AnsiConsole.Write(new Panel("This file seems like it was written by FFmpeg.\n" +
|
||||
"It might no longer possible to fix this file, if there's any problem.\n" +
|
||||
"Only unprocessed data taken directly from the stream server could be fixed.")
|
||||
{
|
||||
Header = new PanelHeader("[bold yellow]FFmpeg Detected[/]"),
|
||||
Border = BoxBorder.Rounded,
|
||||
BorderStyle = new Style(foreground: Color.Yellow)
|
||||
});
|
||||
}
|
||||
|
||||
AnsiConsole.Write(new Panel(this.InputPath.EscapeMarkup())
|
||||
{
|
||||
Header = new PanelHeader("Input"),
|
||||
|
|
|
@ -121,6 +121,9 @@
|
|||
<TextBlock Grid.Row="2" HorizontalAlignment="Center" FontSize="15" Foreground="Red"
|
||||
Visibility="{Binding Unrepairable,Converter={StaticResource BooleanToVisibilityCollapsedConverter}}"
|
||||
Text="{l:Loc Toolbox_AutoFix_AnalyzeResult_ContainsUnrepairable}"/>
|
||||
<TextBlock Grid.Row="2" HorizontalAlignment="Center" FontSize="15" Foreground="Yellow" TextAlignment="Center"
|
||||
Visibility="{Binding FfmpegDetected,Converter={StaticResource BooleanToVisibilityCollapsedConverter}}"
|
||||
Text="检测到此文件可能是 FFmpeg 输出的
文件中的问题可能已经无法修复(如果有问题的话)
只有从直播服务器直出的未处理过的数据可以被修复"/>
|
||||
<StackPanel Grid.Row="3" HorizontalAlignment="Center" Margin="10">
|
||||
<TextBlock Margin="0,0,0,5">
|
||||
<TextBlock.Text>
|
||||
|
|
Loading…
Reference in New Issue
Block a user