/// <summary> /// When using a crop, get the resolution to pass to ffmpeg in order to preserve aspect ratio. /// </summary> public static ImageSize getResolutionToUseWithCrop(string file, ImageSize desiredSize, ImageCrop crop) { ImageSize outSize; int totalCropWidth = crop.Left + crop.Right; int totalCropHeight = crop.Top + crop.Bottom; if (totalCropWidth == 0 && totalCropHeight == 0) { outSize = desiredSize; } else { ImageSize origSize = UtilsVideo.getVideoResolution(file); // output_resolution = desired_resolution + (total_crop - (desired_resolution/orig_resolution) * total_crop)) outSize = new ImageSize(); outSize.Width = desiredSize.Width + (totalCropWidth - (int)((desiredSize.Width / (float)origSize.Width) * totalCropWidth)); outSize.Height = desiredSize.Height + (totalCropHeight - (int)((desiredSize.Height / (float)origSize.Height) * totalCropHeight)); } return(outSize); }