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>
This commit is contained in:
nyanmisaka
2024-03-16 03:40:14 +08:00
parent 1e964c9bc2
commit eca9bf41bc
4 changed files with 214 additions and 28 deletions

View File

@@ -136,6 +136,11 @@ public sealed class TranscodingJob : IDisposable
/// </summary>
public TranscodingThrottler? TranscodingThrottler { get; set; }
/// <summary>
/// Gets or sets transcoding segment cleaner.
/// </summary>
public TranscodingSegmentCleaner? TranscodingSegmentCleaner { get; set; }
/// <summary>
/// Gets or sets last ping date.
/// </summary>
@@ -239,6 +244,7 @@ public sealed class TranscodingJob : IDisposable
{
#pragma warning disable CA1849 // Can't await in lock block
TranscodingThrottler?.Stop().GetAwaiter().GetResult();
TranscodingSegmentCleaner?.Stop();
var process = Process;
@@ -276,5 +282,7 @@ public sealed class TranscodingJob : IDisposable
CancellationTokenSource = null;
TranscodingThrottler?.Dispose();
TranscodingThrottler = null;
TranscodingSegmentCleaner?.Dispose();
TranscodingSegmentCleaner = null;
}
}