diff --git a/BililiveRecorder.Core/IRoom.cs b/BililiveRecorder.Core/IRoom.cs
index 7106de8..79bf213 100644
--- a/BililiveRecorder.Core/IRoom.cs
+++ b/BililiveRecorder.Core/IRoom.cs
@@ -39,5 +39,7 @@ namespace BililiveRecorder.Core
void StopRecord();
void SplitOutput();
Task RefreshRoomInfoAsync();
+
+ void MarkNextRecordShouldUseRawMode();
}
}
diff --git a/BililiveRecorder.Core/Recording/IRecordTaskFactory.cs b/BililiveRecorder.Core/Recording/IRecordTaskFactory.cs
index ab0388d..b8b1377 100644
--- a/BililiveRecorder.Core/Recording/IRecordTaskFactory.cs
+++ b/BililiveRecorder.Core/Recording/IRecordTaskFactory.cs
@@ -1,7 +1,9 @@
+using BililiveRecorder.Core.Config;
+
namespace BililiveRecorder.Core.Recording
{
internal interface IRecordTaskFactory
{
- IRecordTask CreateRecordTask(IRoom room);
+ IRecordTask CreateRecordTask(IRoom room, RecordMode? recordModeOverride = null);
}
}
diff --git a/BililiveRecorder.Core/Recording/RecordTaskFactory.cs b/BililiveRecorder.Core/Recording/RecordTaskFactory.cs
index 9e2aaf8..8cc074e 100644
--- a/BililiveRecorder.Core/Recording/RecordTaskFactory.cs
+++ b/BililiveRecorder.Core/Recording/RecordTaskFactory.cs
@@ -21,10 +21,14 @@ namespace BililiveRecorder.Core.Recording
this.factoryStandard = ActivatorUtilities.CreateFactory(typeof(StandardRecordTask), new[] { typeof(IRoom) });
}
- public IRecordTask CreateRecordTask(IRoom room)
+ public IRecordTask CreateRecordTask(IRoom room, RecordMode? recordModeOverride = null)
{
var recordMode = room.RoomConfig.RecordMode;
- this.logger.Debug("Create record task with mode {RecordMode} for room {RoomId}", recordMode, room.RoomConfig.RoomId);
+ if (recordModeOverride.HasValue)
+ {
+ recordMode = recordModeOverride.Value;
+ }
+ this.logger.Debug("Create record task with mode {RecordMode} for room {RoomId}, override: {Override}", recordMode, room.RoomConfig.RoomId, recordModeOverride);
return recordMode switch
{
RecordMode.RawData => (IRecordTask)this.factoryRawData(this.serviceProvider, new[] { room }),
diff --git a/BililiveRecorder.Core/Recording/StandardRecordTask.cs b/BililiveRecorder.Core/Recording/StandardRecordTask.cs
index 81c745d..269280f 100644
--- a/BililiveRecorder.Core/Recording/StandardRecordTask.cs
+++ b/BililiveRecorder.Core/Recording/StandardRecordTask.cs
@@ -203,8 +203,8 @@ namespace BililiveRecorder.Core.Recording
catch (UnsupportedCodecException ex)
{
// 直播流不是 H.264
- this.logger.Warning(ex, "不支持此直播流的视频编码格式(只支持 H.264),本场直播不再自动启动录制。");
- this.room.StopRecord(); // 停止自动重试
+ this.logger.Warning(ex, "不支持此直播流的视频编码格式(只支持 H.264),下次录制会尝试使用原始模式录制");
+ this.room.MarkNextRecordShouldUseRawMode();
}
catch (OperationCanceledException ex)
{
diff --git a/BililiveRecorder.Core/Room.cs b/BililiveRecorder.Core/Room.cs
index c24c73f..fd898bf 100644
--- a/BililiveRecorder.Core/Room.cs
+++ b/BililiveRecorder.Core/Room.cs
@@ -8,6 +8,7 @@ using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using BililiveRecorder.Core.Api;
+using BililiveRecorder.Core.Config;
using BililiveRecorder.Core.Config.V3;
using BililiveRecorder.Core.Danmaku;
using BililiveRecorder.Core.Event;
@@ -54,6 +55,7 @@ namespace BililiveRecorder.Core
private bool danmakuConnected;
private bool streaming;
private bool autoRecordForThisSession = true;
+ private bool nextRecordShouldUseRawMode = false;
private IRecordTask? recordTask;
private DateTimeOffset danmakuClientConnectTime;
@@ -229,6 +231,11 @@ namespace BililiveRecorder.Core
}
}
+ public void MarkNextRecordShouldUseRawMode()
+ {
+ this.nextRecordShouldUseRawMode = true;
+ }
+
private static readonly TimeSpan TitleRegexMatchTimeout = TimeSpan.FromSeconds(0.5);
///
@@ -277,7 +284,9 @@ namespace BililiveRecorder.Core
this.logger.Warning(ex, "检查标题是否匹配跳过录制正则表达式时出错");
}
- var task = this.recordTaskFactory.CreateRecordTask(this);
+ var task = this.recordTaskFactory.CreateRecordTask(this, this.nextRecordShouldUseRawMode ? RecordMode.RawData : null);
+ this.nextRecordShouldUseRawMode = false;
+
task.IOStats += this.RecordTask_IOStats;
task.RecordingStats += this.RecordTask_RecordingStats;
task.RecordFileOpening += this.RecordTask_RecordFileOpening;
@@ -516,7 +525,7 @@ namespace BililiveRecorder.Core
{
const int MAX_ATTEMPT = 3;
var attempt = 0;
-retry:
+ retry:
try
{
var coverUrl = this.RawBilibiliApiJsonData?["room_info"]?["cover"]?.ToObject();