70 lines
2.1 KiB
C#
70 lines
2.1 KiB
C#
using FFMpegCore.Enums;
|
|
using FFMpegCore.Helpers;
|
|
using FFMpegCore;
|
|
using System.IO;
|
|
|
|
namespace VideoConcat.Common.Tools
|
|
{
|
|
internal class VideoCombine
|
|
{
|
|
/// <summary>
|
|
/// 生成所有组合
|
|
/// </summary>
|
|
public static void GenerateCombinations(List<List<string>> videoLists, int index, List<string> currentCombination, List<List<string>> result)
|
|
{
|
|
if (index == videoLists.Count)
|
|
{
|
|
result.Add(new List<string>(currentCombination));
|
|
return;
|
|
}
|
|
|
|
|
|
foreach (string video in videoLists[index])
|
|
{
|
|
currentCombination.Add(video);
|
|
GenerateCombinations(videoLists, index + 1, currentCombination, result);
|
|
currentCombination.RemoveAt(currentCombination.Count - 1);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 清理临时文件
|
|
/// </summary>
|
|
public static void Cleanup(List<string> pathList)
|
|
{
|
|
foreach (var path in pathList)
|
|
{
|
|
if (File.Exists(path))
|
|
{
|
|
File.Delete(path);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 将视频文件转换为ts格式
|
|
/// </summary>
|
|
public static string ConvertVideos(string videoPath)
|
|
{
|
|
|
|
var video = FFProbe.Analyse(videoPath);
|
|
FFMpegHelper.ConversionSizeExceptionCheck(video);
|
|
|
|
string _tempPath = Path.GetDirectoryName(videoPath) ?? "";
|
|
|
|
//GlobalFFOptions.Current.TemporaryFilesFolder
|
|
var destinationPath = Path.Combine(_tempPath, $"{Path.GetFileNameWithoutExtension(videoPath)}{FileExtension.Ts}");
|
|
//Directory.CreateDirectory(GlobalFFOptions.Current.TemporaryFilesFolder);
|
|
try
|
|
{
|
|
FFMpeg.Convert(videoPath, destinationPath, VideoType.Ts);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogUtils.Error($"{videoPath} 转换失败", ex);
|
|
}
|
|
return destinationPath;
|
|
}
|
|
}
|
|
}
|