去重优先级,视频合成,没有音频用默认音频

This commit is contained in:
jianzhichu
2025-12-02 22:14:42 +08:00
parent 4663a03483
commit bd3a103f8f
15 changed files with 307 additions and 25 deletions
+9 -1
View File
@@ -31,6 +31,12 @@ namespace dy.net.service
var conf = GetConfig();
if (conf != null)
{
if (string.IsNullOrWhiteSpace(conf.PriorityLevel))
{
conf.PriorityLevel = "[{\"id\":1,\"name\":\"喜欢的视频\",\"sort\":1},{\"id\":2,\"name\":\"收藏的视频\",\"sort\":2},{\"id\":3,\"name\":\"关注的视频\",\"sort\":3}]";
sqlSugarClient.Updateable(conf).ExecuteCommand();
//兼容旧版本
}
return conf;
}
else
@@ -50,7 +56,8 @@ namespace dy.net.service
FollowedTitleTemplate = "",
FullFollowedTitleTemplate = "",
FollowedTitleSeparator = "",
AutoDistinct = true//默认开启
AutoDistinct = true,//默认开启
PriorityLevel= "[{\"id\":1,\"name\":\"喜欢的视频\",\"sort\":1},{\"id\":2,\"name\":\"收藏的视频\",\"sort\":2},{\"id\":3,\"name\":\"关注的视频\",\"sort\":3}]"
};
sqlSugarClient.Insertable(config).ExecuteCommand();
return config;
@@ -83,6 +90,7 @@ namespace dy.net.service
cc.ImageViedoSaveAlone = config.ImageViedoSaveAlone;
cc.FollowedTitleSeparator = config.FollowedTitleSeparator;
cc.AutoDistinct = config.AutoDistinct;
cc.PriorityLevel = config.PriorityLevel;
}
int update = await sqlSugarClient.Updateable(cc).ExecuteCommandAsync();
+13 -6
View File
@@ -177,11 +177,11 @@ namespace dy.net.service
Log.Error("图片URL列表为空,无法合成视频");
return false;
}
if (mergeImg2Viedo && (request.AudioUrls == null || request.AudioUrls.Count == 0))
{
Log.Error("合成视频时音频URL列表为空");
return false;
}
//if (mergeImg2Viedo && (request.AudioUrls == null || request.AudioUrls.Count == 0))
//{
// Log.Error("合成视频时音频URL列表为空");
// return false;
//}
string tempDir = null;
try
@@ -206,7 +206,7 @@ namespace dy.net.service
// 2. 下载音频
string[] rawAudios = Array.Empty<string>();
if (mergeImg2Viedo)
if (mergeImg2Viedo&& request.AudioUrls != null && request.AudioUrls.Count>0)
{
var (audios, audioError) = await DownloadMediaAsync(
request.AudioUrls, Path.Combine(tempDir, "raw-audios"), "audio_", "mp3", cookie);
@@ -257,6 +257,13 @@ namespace dy.net.service
// 超时控制:避免 FFmpeg 进程无限运行(300秒=5分钟)
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(300));
// 执行合成(确保每个图片都参与)
if (rawAudios.Length == 0)
{
rawAudios= new string[] { Path.Combine(AppContext.BaseDirectory,"mp3", "silent_10.mp3") };
Log.Debug("未检测到音频,使用默认静音音频-无声");
}
string resultPath = await ffmpegHelper.CreateVideoFromImagesAndAudioAsync(
rawImages, // 所有下载的图片(确保无遗漏)
rawAudios[0], // 取第一个音频(可根据需求调整)