public void AnalyzePath( MediaAnalyzePathRequest request, CurveFittingSettings curveFittingSettings, MediaAnalyzeActions actions ) { // Sanity checks if (request.MaxAllowedHeight > request.MaxAllowedWidth) { throw new ArgumentException(nameof(request), $"{nameof(request.MaxAllowedWidth)} must be always greater than {nameof(request.MaxAllowedHeight)}!"); } // Reset counters _reEncodeFiles = 0; _totalFiles = 0; // Get the Data for calculating the CurveFittingFunction var data = curveFittingSettings.Data.ToDictionary( k => (double)k.Width * k.Height, v => (double)v.Bitrate / (double)(v.Width * v.Height) ); // Get the CurveFitting Function var targetFunction = new CurveFittingFactory() .GetCurveFittingService(curveFittingSettings.CurveFittingType) .GetCurveFittingFunction(data); // Call the internal recursive method AnalyzePathInternal(request, targetFunction, actions); }
private void AnalyzePathInternal( MediaAnalyzePathRequest request, Func <double, double> targetFunction, MediaAnalyzeActions actions ) { // Sanity checks if (request.MaxAllowedHeight > request.MaxAllowedWidth) { throw new ArgumentException(nameof(request), $"{nameof(request.MaxAllowedWidth)} must be always greater than {nameof(request.MaxAllowedHeight)}!"); } var files = Directory.GetFiles(request.MediaDirectoryName); var mediaFiles = files.Where(f => _mediaExtensions.Any(m => m.Equals(Path.GetExtension(f).Substring(1).ToLower()))).OrderBy(f => f).ToList(); if (mediaFiles.Any()) { foreach (var mediaFile in mediaFiles) { _totalFiles++; actions.UpdateProgressAction(_reEncodeFiles, _totalFiles); AnalyzeVideoFileInternal( new MediaAnalyzeFileRequest(mediaFile, request), targetFunction, actions ); } } var subDirs = Directory.GetDirectories(request.MediaDirectoryName); if (subDirs.Any()) { foreach (var subDir in subDirs.OrderBy(d => d).ToList()) { AnalyzePathInternal( new MediaAnalyzePathRequest(subDir, request), targetFunction, actions ); } } }