aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.MediaEncoding/Transcoding/TranscodeManager.cs
diff options
context:
space:
mode:
authornyanmisaka <nst799610810@gmail.com>2024-03-16 03:40:14 +0800
committernyanmisaka <nst799610810@gmail.com>2024-03-16 07:35:05 +0800
commiteca9bf41bcf536708ad74236793b363db3af1e4d (patch)
tree9c63f5ed565bc039162125eecad92a90f9f05089 /MediaBrowser.MediaEncoding/Transcoding/TranscodeManager.cs
parent1e964c9bc23b598135590f5b29f25836158a4305 (diff)
Add TranscodingSegmentCleaner to replace ffmpeg's hlsenc deletion
FFmpeg deletes segments based on its own transcoding progress, but we need to delete segments based on client download progress. Since disk and GPU speeds vary, using hlsenc's built-in deletion will result in premature deletion of some segments. As a consequence, the server has to constantly respin new ffmpeg instances, resulting in choppy video playback. Signed-off-by: nyanmisaka <nst799610810@gmail.com>
Diffstat (limited to 'MediaBrowser.MediaEncoding/Transcoding/TranscodeManager.cs')
-rw-r--r--MediaBrowser.MediaEncoding/Transcoding/TranscodeManager.cs17
1 files changed, 17 insertions, 0 deletions
diff --git a/MediaBrowser.MediaEncoding/Transcoding/TranscodeManager.cs b/MediaBrowser.MediaEncoding/Transcoding/TranscodeManager.cs
index 8bace15c6..2a72cacdc 100644
--- a/MediaBrowser.MediaEncoding/Transcoding/TranscodeManager.cs
+++ b/MediaBrowser.MediaEncoding/Transcoding/TranscodeManager.cs
@@ -546,6 +546,7 @@ public sealed class TranscodeManager : ITranscodeManager, IDisposable
if (!transcodingJob.HasExited)
{
StartThrottler(state, transcodingJob);
+ StartSegmentCleaner(state, transcodingJob);
}
else if (transcodingJob.ExitCode != 0)
{
@@ -573,6 +574,22 @@ public sealed class TranscodeManager : ITranscodeManager, IDisposable
&& state.IsInputVideo
&& state.VideoType == VideoType.VideoFile;
+ private void StartSegmentCleaner(StreamState state, TranscodingJob transcodingJob)
+ {
+ if (EnableSegmentCleaning(state))
+ {
+ transcodingJob.TranscodingSegmentCleaner = new TranscodingSegmentCleaner(transcodingJob, _loggerFactory.CreateLogger<TranscodingSegmentCleaner>(), _serverConfigurationManager, _fileSystem, _mediaEncoder, state.SegmentLength);
+ transcodingJob.TranscodingSegmentCleaner.Start();
+ }
+ }
+
+ private static bool EnableSegmentCleaning(StreamState state)
+ => state.InputProtocol is MediaProtocol.File or MediaProtocol.Http
+ && state.IsInputVideo
+ && state.TranscodingType == TranscodingJobType.Hls
+ && state.RunTimeTicks.HasValue
+ && state.RunTimeTicks.Value >= TimeSpan.FromMinutes(5).Ticks;
+
private TranscodingJob OnTranscodeBeginning(
string path,
string? playSessionId,