修复 测试完善后的新流程
This commit is contained in:
parent
776c2b9b52
commit
a0e00c8b5d
|
|
@ -41,16 +41,18 @@ namespace VideoAnalysisCore.AICore.FFMPGE
|
|||
var intervalSec = 5;
|
||||
var threshold = 8.15;
|
||||
var ssimThreshold = 0.9;
|
||||
var PPTVideoCode = await DbScoped.Sugar
|
||||
var taskInfo = await DbScoped.Sugar
|
||||
.Queryable<VideoTask>()
|
||||
.Where(s => s.Id == long.Parse(task))
|
||||
.Select(s => s.PPTVideoCode).FirstAsync();
|
||||
if (string.IsNullOrEmpty(PPTVideoCode)) return;
|
||||
.Where(s => s.Id == long.Parse(task)).FirstAsync();
|
||||
if (string.IsNullOrEmpty(taskInfo.PPTVideoCode) || string.IsNullOrEmpty(taskInfo.PPTVideoUrl)) return;
|
||||
//视频切帧
|
||||
var localPath = task.LocalPath();
|
||||
var filePath = Path.Combine(localPath, "ppt.mp4");
|
||||
if (!File.Exists(filePath))
|
||||
throw new Exception("存在PPTCOde但未能找到对应资源文件");
|
||||
{
|
||||
Console.WriteLine("存在PPT Code但未能找到对应资源文件");
|
||||
return;
|
||||
}
|
||||
var ffmpeg = new Engine(FFmpegPath);
|
||||
var cToken = new CancellationToken();
|
||||
RedisExpand.SetTaskProgress(task, "Frame=>10%");
|
||||
|
|
@ -65,7 +67,7 @@ namespace VideoAnalysisCore.AICore.FFMPGE
|
|||
var frameFiles = Directory.GetFiles(localPath, "*.jpg")
|
||||
.OrderBy(f => f)
|
||||
.ToList();
|
||||
RedisExpand.SetTaskProgress(task, "Frame=>50%");
|
||||
RedisExpand.SetTaskProgress(task, "Frame=>80%");
|
||||
Image<Rgb24> prevFrame = null;
|
||||
var keyFrames = new List<int>(10) { 5};
|
||||
foreach (var frameFile in frameFiles)
|
||||
|
|
|
|||
|
|
@ -257,7 +257,7 @@ namespace VideoAnalysisCore.AICore.GPT.DeepSeek
|
|||
{
|
||||
try
|
||||
{
|
||||
var keyFrameArr = string.IsNullOrEmpty(taskInfo?.PPTVideoCode)
|
||||
var keyFrameArr = string.IsNullOrEmpty(taskInfo?.PPTVideoCode) || string.IsNullOrEmpty(taskInfo?.PPTKeyFrame)
|
||||
? string.Empty
|
||||
: $"授课PPT发生了变化的时间是{taskInfo.PPTKeyFrame},所以在这些时间段附近应该发生了授课内容得变化,授课阶段结果尽量参考这些时间节点(PPT与字幕有一定的延时)。";
|
||||
var resFormat = """[{"StartTime":开始秒(number),"EndTime":结束秒(number),"Stage":阶段(string),"Theme":主题(string),"Content":内容总结(string)}]""";
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ namespace VideoAnalysisCore.AICore.SherpaOnnx
|
|||
/// <returns></returns>
|
||||
public static async Task RunTask(string task)
|
||||
{
|
||||
var filePath = Path.Combine(task.LocalPath(), task + ".wav");
|
||||
var filePath = Path.Combine(task.LocalPath(), "task.wav");
|
||||
if (string.IsNullOrEmpty(filePath) || !File.Exists(filePath))
|
||||
throw new Exception("task 音频路径未找到");
|
||||
await TaskHandle(new WaveReader(filePath), task);
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ namespace VideoAnalysisCore.AICore.SherpaOnnx
|
|||
/// <param name="task"></param>
|
||||
public static async Task Run(string task)
|
||||
{
|
||||
var filePath = Path.Combine(task.LocalPath(), task + ".wav");
|
||||
var filePath = Path.Combine(task.LocalPath(), "task.wav");
|
||||
if (string.IsNullOrEmpty(filePath) || !File.Exists(filePath))
|
||||
throw new Exception("task 音频路径未找到");
|
||||
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ namespace VideoAnalysisCore.Common
|
|||
/// </summary>
|
||||
public static class ExpandFunction
|
||||
{
|
||||
|
||||
|
||||
static Dictionary<string, string> FormulaData;
|
||||
static string FormulaDataKey;
|
||||
/// <summary>
|
||||
|
|
@ -92,6 +92,31 @@ namespace VideoAnalysisCore.Common
|
|||
/// </summary>
|
||||
public static string FrameName = "frame_";
|
||||
|
||||
/// <summary>
|
||||
/// 删除 AI分析任务的缓存文件
|
||||
/// </summary>
|
||||
/// <param name="taskId"></param>
|
||||
/// <returns></returns>
|
||||
public static bool DeleteTaskFile(long? taskId)
|
||||
{
|
||||
if(taskId is null || taskId == 0) return false;
|
||||
var path = taskId.ToString().LocalPath();
|
||||
if (!string.IsNullOrEmpty(path) && Directory.Exists(path))
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.Delete(path, true);
|
||||
Console.WriteLine($"已删除缓存文件: {taskId}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"删除缓存文件 {taskId} 时出错: {ex.Message}");
|
||||
}
|
||||
}
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 对象转化为JSON字符串
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ using VideoAnalysisCore.Model;
|
|||
using VideoAnalysisCore.Model.Enum;
|
||||
using AlibabaCloud.SDK.Vod20170321;
|
||||
using UserCenter.Model.Enum;
|
||||
using System.Security.Policy;
|
||||
|
||||
namespace VideoAnalysisCore.Common
|
||||
{
|
||||
|
|
@ -90,12 +91,16 @@ namespace VideoAnalysisCore.Common
|
|||
public static DownloadConfiguration Opt { get; set; } = default!;
|
||||
public static int DownloadSpeed { get; set; } = default!;
|
||||
private readonly Repository<VideoTask> videoTaskDB;
|
||||
private readonly Repository<NodePackageInfo> packageInfoTaskDB;
|
||||
private readonly Client vodClient;
|
||||
readonly string taskVideoName = "task.mp4";
|
||||
readonly string taskPPTVideoName = "ppt.mp4";
|
||||
|
||||
public DownloadFile(Repository<VideoTask> videoTaskDB, Client vodClient)
|
||||
public DownloadFile(Repository<VideoTask> videoTaskDB, Client vodClient, Repository<NodePackageInfo> nackageInfoTaskDB)
|
||||
{
|
||||
this.videoTaskDB = videoTaskDB;
|
||||
this.vodClient = vodClient;
|
||||
this.packageInfoTaskDB = nackageInfoTaskDB;
|
||||
}
|
||||
|
||||
// 根据 Content-Type 映射文件后缀
|
||||
|
|
@ -157,7 +162,7 @@ namespace VideoAnalysisCore.Common
|
|||
if (!Directory.Exists(AppCommon.TaskCachedFile)) Directory.CreateDirectory(AppCommon.TaskCachedFile);
|
||||
|
||||
var localPath = task.LocalPath();
|
||||
var outputPath = Path.Combine(localPath, task + fileExtension);
|
||||
var outputPath = Path.Combine(localPath, taskVideoName);
|
||||
if (!Directory.Exists(localPath)) Directory.CreateDirectory(localPath);
|
||||
|
||||
await videoTaskDB
|
||||
|
|
@ -166,38 +171,52 @@ namespace VideoAnalysisCore.Common
|
|||
.Where(it => it.Id == long.Parse(task))
|
||||
.ExecuteCommandAsync();
|
||||
//下载PPT视频
|
||||
if (!string.IsNullOrEmpty(taskInfo.PPTVideoCode))
|
||||
if (string.IsNullOrEmpty(taskInfo.PPTVideoUrl)&&
|
||||
!string.IsNullOrEmpty(taskInfo.PPTVideoCode))
|
||||
{
|
||||
try
|
||||
{
|
||||
var url = string.Empty;
|
||||
if (taskInfo.PPTVideoCode.Contains("http"))
|
||||
url = taskInfo.PPTVideoCode;
|
||||
else
|
||||
{
|
||||
var videoInfo = await vodClient.GetPlayInfoAsync(new AlibabaCloud.SDK.Vod20170321.Models.GetPlayInfoRequest()
|
||||
{
|
||||
VideoId = taskInfo.PPTVideoCode,
|
||||
Formats = "mp4",
|
||||
OutputType = "cdn",
|
||||
AuthTimeout = 3600 * 24 * 12,
|
||||
});
|
||||
if (videoInfo is null || videoInfo.StatusCode != 200 && !videoInfo.Body.PlayInfoList.PlayInfo.Any())
|
||||
throw new Exception($"{DateTime.Now} 视频订阅=>获取阿里云视频信息失败 VideoCode {taskInfo.TagId} StatusCode {videoInfo?.StatusCode}");
|
||||
url = videoInfo.Body.PlayInfoList.PlayInfo.First().PlayURL;
|
||||
}
|
||||
await Download(url, localPath, "ppt.mp4",
|
||||
(s, e) => RedisExpand.SetTaskProgress(task, "PPT->" + Math.Round(e.ProgressPercentage, 1)
|
||||
));
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
taskInfo.PPTVideoUrl = await packageInfoTaskDB.AsQueryable()
|
||||
.Where(s => s.VideoCode == taskInfo.PPTVideoCode)
|
||||
.Select(s => s.VideoUrl)
|
||||
.FirstAsync();
|
||||
if (!string.IsNullOrEmpty(taskInfo.PPTVideoUrl))
|
||||
await videoTaskDB.AsUpdateable(taskInfo)
|
||||
.UpdateColumns(it => new { it.PPTVideoUrl })
|
||||
.ExecuteCommandAsync();
|
||||
|
||||
}
|
||||
if (!string.IsNullOrEmpty(taskInfo.PPTVideoUrl))
|
||||
{
|
||||
await Download(taskInfo.PPTVideoUrl, localPath, taskPPTVideoName,
|
||||
(s, e) => RedisExpand.SetTaskProgress(task, "PPT->" + Math.Round(e.ProgressPercentage, 1)
|
||||
));
|
||||
//try
|
||||
//{
|
||||
// var url = string.Empty;
|
||||
// if (taskInfo.PPTVideoCode.Contains("http"))
|
||||
// url = taskInfo.PPTVideoCode;
|
||||
// else
|
||||
// {
|
||||
// var videoInfo = await vodClient.GetPlayInfoAsync(new AlibabaCloud.SDK.Vod20170321.Models.GetPlayInfoRequest()
|
||||
// {
|
||||
// VideoId = taskInfo.PPTVideoCode,
|
||||
// Formats = "mp4",
|
||||
// OutputType = "cdn",
|
||||
// AuthTimeout = 3600 * 24 * 12,
|
||||
// });
|
||||
// if (videoInfo is null || videoInfo.StatusCode != 200 && !videoInfo.Body.PlayInfoList.PlayInfo.Any())
|
||||
// throw new Exception($"{DateTime.Now} 视频订阅=>获取阿里云视频信息失败 VideoCode {taskInfo.TagId} StatusCode {videoInfo?.StatusCode}");
|
||||
// url = videoInfo.Body.PlayInfoList.PlayInfo.First().PlayURL;
|
||||
// }
|
||||
//}
|
||||
//catch
|
||||
//{
|
||||
// throw;
|
||||
//}
|
||||
}
|
||||
try
|
||||
{//下载原视频
|
||||
await Download(fileUrl, localPath, task + fileExtension,
|
||||
{
|
||||
//下载原视频
|
||||
await Download(fileUrl, localPath, taskVideoName,
|
||||
(s, e) => RedisExpand.SetTaskProgress(task, Math.Round(e.ProgressPercentage,1)
|
||||
));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,6 +104,7 @@ namespace VideoAnalysisCore.Controllers
|
|||
nodePackages.Add(np);
|
||||
if (videoIdArr.Contains(s.VideoCode)) continue;
|
||||
var pptCode = sPPT != null ? sPPT.VideoCode : string.Empty;
|
||||
var pptUrl = sPPT != null ? sPPT.VideoUrl : string.Empty;
|
||||
videos.Add(new VideoTask()
|
||||
{
|
||||
Id = YitIdHelper.NextId(),
|
||||
|
|
@ -115,6 +116,7 @@ namespace VideoAnalysisCore.Controllers
|
|||
TagId = s.VideoCode,
|
||||
MediaUrl = s.VideoUrl,
|
||||
PPTVideoCode = pptCode,
|
||||
PPTVideoUrl = pptUrl,
|
||||
VideoType = s.CourseType
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,21 +51,7 @@ namespace VideoAnalysisCore.Job
|
|||
|
||||
// 遍历查询结果,删除缓存文件
|
||||
foreach (var task in completedTasks)
|
||||
{
|
||||
var path = task.Id.ToString().LocalPath();
|
||||
if (!string.IsNullOrEmpty(path) && Directory.Exists(path))
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.Delete(path, true);
|
||||
Console.WriteLine($"已删除缓存文件: {task.LocalMediaPath}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"删除缓存文件 {task.Id} 时出错: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
ExpandFunction.DeleteTaskFile(task?.Id);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -79,6 +79,11 @@ namespace VideoAnalysisCore.Model
|
|||
[SugarColumn(Length = 255, ColumnDataType = "varchar", IsNullable = true)]
|
||||
public string? PPTVideoCode { get; set; }
|
||||
/// <summary>
|
||||
/// 授课视频对应PPT视频ID
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 255, ColumnDataType = "varchar", IsNullable = true)]
|
||||
public string? PPTVideoUrl { get; set; }
|
||||
/// <summary>
|
||||
/// 授课视频对应PPT视频关键帧
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDataType = "longtext",IsNullable = true)]
|
||||
|
|
|
|||
Loading…
Reference in New Issue