Files
annotations/Web/Azaion.Web/Azaion.Video/VideoManager.cs
T
Oleksandr Bezdieniezhnykh 6f78b88007 add controller for video
2024-07-22 16:01:28 +03:00

61 lines
1.7 KiB
C#

using System.Diagnostics;
using Azaion.Repository;
using Azaion.Repository.DTO;
using Azaion.Repository.Entities;
namespace Azaion.Video;
public class VideoManager(IDbFactory dbFactory) : IVideoManager
{
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 = Constants.FFMPEG_FILE,
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)
{
}
}