30 lines
1003 B
C#
30 lines
1003 B
C#
using FFMpegCore;
|
|
using NostrStreamer.Database;
|
|
|
|
namespace NostrStreamer.Services.Thumbnail;
|
|
|
|
public abstract class BaseThumbnailService
|
|
{
|
|
protected readonly ILogger Logger;
|
|
protected readonly Config Config;
|
|
|
|
protected BaseThumbnailService(Config config, ILogger logger)
|
|
{
|
|
Config = config;
|
|
Logger = logger;
|
|
}
|
|
|
|
protected async Task<string> GenerateThumbnail(UserStream stream)
|
|
{
|
|
var path = Path.ChangeExtension(Path.GetTempFileName(), ".jpg");
|
|
var cmd = FFMpegArguments
|
|
.FromUrlInput(new Uri(Config.RtmpHost, $"{stream.Endpoint.App}/source/{stream.User.StreamKey}?vhost=hls.zap.stream"))
|
|
.OutputToFile(path, true, o => { o.ForceFormat("image2").WithCustomArgument("-vframes 1"); })
|
|
.CancellableThrough(new CancellationTokenSource(TimeSpan.FromSeconds(10)).Token);
|
|
|
|
Logger.LogInformation("Running command {cmd}", cmd.Arguments);
|
|
await cmd.ProcessAsynchronously();
|
|
return path;
|
|
}
|
|
}
|