2025-08-12 00:17:37 -05:00
|
|
|
using StreamShorts.Library.Analysis;
|
|
|
|
|
|
2025-08-03 22:50:30 -05:00
|
|
|
namespace StreamShorts.Library.Media.Video;
|
|
|
|
|
|
2025-08-12 00:17:37 -05:00
|
|
|
/// <summary>
|
|
|
|
|
/// Represents a service that creates video shorts.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <inheritdoc/>
|
2025-08-03 22:50:30 -05:00
|
|
|
public class ShortsCreator : IShortsCreator
|
|
|
|
|
{
|
2025-08-12 00:17:37 -05:00
|
|
|
private readonly IVideoService _videoService = new FFMpegService();
|
|
|
|
|
|
|
|
|
|
public ShortsCreator()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal ShortsCreator(IVideoService videoService)
|
|
|
|
|
{
|
|
|
|
|
_videoService = videoService ?? throw new ArgumentNullException(nameof(videoService), $"{nameof(videoService)} cannot be null");
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-19 12:43:34 -05:00
|
|
|
public async Task CreateShortAsync(string sourcePath, ShortCandidate candidate, string destinationPath, TimeSpan? buffer = null)
|
2025-08-12 00:17:37 -05:00
|
|
|
{
|
2025-08-19 12:43:34 -05:00
|
|
|
if (string.IsNullOrWhiteSpace(sourcePath))
|
2025-08-12 00:17:37 -05:00
|
|
|
{
|
2025-08-19 12:43:34 -05:00
|
|
|
throw new ArgumentNullException(nameof(sourcePath), $"{nameof(sourcePath)} cannot be null or whitespace");
|
2025-08-12 00:17:37 -05:00
|
|
|
}
|
2025-08-19 12:43:34 -05:00
|
|
|
|
|
|
|
|
if (candidate is null)
|
2025-08-12 00:17:37 -05:00
|
|
|
{
|
2025-08-19 12:43:34 -05:00
|
|
|
throw new ArgumentNullException(nameof(candidate), $"{nameof(candidate)} cannot be null");
|
2025-08-12 00:17:37 -05:00
|
|
|
}
|
2025-08-19 12:43:34 -05:00
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(destinationPath))
|
2025-08-12 00:17:37 -05:00
|
|
|
{
|
2025-08-19 12:43:34 -05:00
|
|
|
throw new ArgumentNullException(nameof(destinationPath), $"{nameof(destinationPath)} cannot be null or whitespace");
|
2025-08-12 00:17:37 -05:00
|
|
|
}
|
2025-08-19 12:43:34 -05:00
|
|
|
|
|
|
|
|
await _videoService.CreateClipFromVideoAsync(sourcePath, destinationPath, candidate.StartTime, candidate.EndTime, buffer)
|
|
|
|
|
.ConfigureAwait(false);
|
2025-08-12 00:17:37 -05:00
|
|
|
}
|
|
|
|
|
}
|