using System.Diagnostics; using Azaion.Repository; using Azaion.Repository.DTO; using Azaion.Repository.DTO.Configs; using Azaion.Repository.Entities; using Microsoft.Extensions.Options; namespace Azaion.Video; public class VideoRepository(IDbFactory dbFactory, IOptions foldersConfig) : IVideoRepository { public List GetVideos() { return dbFactory.Run(db => db.Medias .Where(x => x.AnnotatorId != null) .Select(x => new VideoDto { Id = x.Id, Path = x.Path, CreatedDate = x.CreatedDate, MediaStatus = x.Status }) .ToList()); } public void EncodeVideo(Guid mediaId) { var media = dbFactory.Run(db => db.Medias.SingleOrDefault(x => x.Id == mediaId))!; string arguments = string.Concat($"-i \"{media.Path}\" ", "-f hls ", "-hls_time 2 ", "-hls_playlist_type vod ", "-hls_flags independent_segments ", "-hls_segment_type mpegts ", $"-hls_segment_filename \"{media.SegmentFile}\"", $"\"{media.M3U8File}\""); var process = new Process { StartInfo = new() { FileName = foldersConfig.Value.FfmpegExecutable, Arguments = arguments, UseShellExecute = true, }, EnableRaisingEvents = true, }; process.Start(); } public Media Get(Guid mediaId) => dbFactory.Run(db => db.Medias.SingleOrDefault(x => x.Id == mediaId))!; public void OpenTestVideo() { } public void FinishAnnotation(Guid mediaId) { } }