Files
annotations/Web/Azaion.Web/Azaion.Video/VideoRepository.cs
T
Oleksandr Bezdieniezhnykh 7807f5bc90 add quartz for jobs
configure auto-scan folder and create hls files job WIP
2024-07-26 14:11:29 +03:00

63 lines
1.8 KiB
C#

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> foldersConfig) : IVideoRepository
{
public List<VideoDto> 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)
{
}
}