2026-10-25 00:48:53 +01:00
|
|
|
using Microsoft.Extensions.Options;
|
|
|
|
|
|
|
|
|
|
namespace Yavsc.Services;
|
|
|
|
|
|
|
|
|
|
public sealed class FfmpegPodcastReplayRemuxer(IOptions<PodcastOptions> options) : IPodcastReplayRemuxer
|
|
|
|
|
{
|
|
|
|
|
public async Task RemuxAsync(string directory, int segmentCount, string outputPath, long maxBytes, CancellationToken ct)
|
|
|
|
|
{
|
|
|
|
|
if (segmentCount < 1) throw new InvalidDataException("Le podcast ne contient aucun segment.");
|
|
|
|
|
var list = Path.Combine(directory, "replay-concat.txt");
|
|
|
|
|
// Concatenate TS bytes without resetting timestamps or guessing durations between segments.
|
|
|
|
|
// Only generated local basenames enter the protocol, never uploaded metadata.
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await File.WriteAllLinesAsync(list,
|
|
|
|
|
Enumerable.Range(0, segmentCount).Select(i => $"{i:D8}.ts"), ct);
|
2026-11-16 14:01:24 +00:00
|
|
|
await FfmpegProcess.RunAsync(options.Value.FfmpegPath,
|
|
|
|
|
[
|
2026-10-25 00:48:53 +01:00
|
|
|
"-nostdin", "-hide_banner", "-loglevel", "error", "-y",
|
|
|
|
|
"-protocol_whitelist", "file,concatf", "-f", "mpegts", "-i", $"concatf:{list}",
|
|
|
|
|
"-map", "0:v:0", "-map", "0:a:0?", "-c", "copy", "-bsf:a", "aac_adtstoasc",
|
|
|
|
|
"-movflags", "+faststart", "-f", "mp4", outputPath
|
2026-11-16 14:01:24 +00:00
|
|
|
], directory, outputPath, maxBytes, ct);
|
2026-10-25 00:48:53 +01:00
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
File.Delete(list);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|