У меня есть функция: public List<VideoInfo> FindNearestVideosByDuration(string…
- User
У меня есть функция: public List FindNearestVideosByDuration(string folderPath, double eventStart, double eventLength, List VideosOnTimeline) { List videoInfos = folderAnalizator.GetVideoInfoFromFolder(folderPath) .Except(VideosOnTimeline, new VideoInfoNameComparer()) .ToList();
codevideoInfos = videoInfos.OrderByDescending(v => v.DurationInMilliseconds).ToList(); Dictionary<double, List<VideoInfo>> dp = new Dictionary<double, List<VideoInfo>> { { 0, new List<VideoInfo>() } }; foreach (var video in videoInfos) { var newDp = new Dictionary<double, List<VideoInfo>>(dp); foreach (var entry in dp) { double newDuration = entry.Key + video.DurationInMilliseconds; if (newDuration <= eventLength && !newDp.ContainsKey(newDuration)) { var newList = new List<VideoInfo>(entry.Value) { video }; int generalVideo = video.GeneralVideo; // Находим "близкие" видео на таймлайне (в пределах 19000 мс) var nearbyVideos = VideosOnTimeline .Where(v => v.GeneralVideo == generalVideo && (Math.Abs(v.StartOnTimeline - eventStart) <= 19000 || Math.Abs(v.EndOnTimeline - (eventStart + eventLength)) <= 19000) .ToList(); // Вычисляем суммарную длительность "близких" видео double totalNearbyDuration = nearbyVideos.Sum(v => v.DurationInMilliseconds); // Вычисляем суммарную длительность видео в новом наборе double totalNewListDuration = newList .Where(v => v.GeneralVideo == generalVideo) .Sum(v => v.DurationInMilliseconds); // Общая длительность double totalGeneralDuration = totalNearbyDuration + totalNewListDuration; // Проверяем, все ли видео свободны от авторских прав bool allCopyrightFree = newList.All(v => v.CopyrightFree); if ((totalGeneralDuration <= 19000 || allCopyrightFree) && newDuration <= eventLength) { newDp[newDuration] = newList; } } } dp = newDp; } var bestMatch = dp.OrderByDescending(x => x.Key).FirstOrDefault().Value; if (bestMatch != null) { bestMatch = bestMatch.OrderBy(v => v.VideoSegment).ToList(); double currentStart = eventStart; foreach (var video in bestMatch) { string Info = $"{video.Name}\n"; video.StartOnTimeline = currentStart; video.LengthOnTimeline = video.DurationInMilliseconds; Info += $"Start: {video.StartOnTimeline}\nLength: {video.LengthOnTimeline}\nDuration: {video.DurationInMilliseconds}"; MessageBox.Show(Info); video.EndOnTimeline = currentStart + video.LengthOnTimeline; VideosOnTimeline.Add(video); currentStart = video.EndOnTimeline; } } return bestMatch ?? new List<VideoInfo>(); - Assistant
- User
- Assistant