public void FfmpegWrapper_GetImagesFromMedia_Returns_Expected_Values(int requestedFrameCount) { CreateTestVideoIfNecessary(); var ffmpegWrapper = new FfmpegWrapper(FfmpegExecutablePath); var images = ffmpegWrapper.GetImagesFromMedia( TestVideoFileName, requestedFrameCount, CancellationToken.None) .ToList(); CollectionAssert.AllItemsAreNotNull(images); Assert.AreEqual(requestedFrameCount, images.Count); foreach (var image in images) { Assert.AreEqual(TestVideoWidth, image.Width); Assert.AreEqual(TestVideoHeight, image.Height); } }
public async Task FfmpegWrapper_GetImagesFromMedia_Returns_Expected_Values(int requestedFrameCount) { CreateTestVideoIfNecessary(); var ffmpegWrapper = new FfmpegWrapper(FfmpegExecutablePath); var images = ffmpegWrapper.GetImagesFromMedia( TestVideoFileName, requestedFrameCount, CancellationToken.None) .ToList(); CollectionAssert.AllItemsAreNotNull(images); Assert.AreEqual(requestedFrameCount, images.Count); foreach (var bitmapStream in images) { var imageInfo = await Task.Run(() => ImageFileInfo.Load(bitmapStream)); Assert.AreEqual(TestVideoWidth, imageInfo.Frames[0].Width); Assert.AreEqual(TestVideoHeight, imageInfo.Frames[0].Height); } }
public IReadOnlyDictionary <IBarGenerator, Bitmap> CreateBarCodes( BarCodeParameters parameters, FfmpegWrapper ffmpeg, CancellationToken cancellationToken, IProgress <double> progress = null, Action <string> log = null) { var barCount = (int)Math.Round((double)parameters.Width / parameters.BarWidth); var bitmapStreamSource = ffmpeg.GetImagesFromMedia(parameters.InputPath, barCount, cancellationToken, log); var barGenerators = parameters.GeneratorOutputPaths.Keys.ToArray(); Bitmap[] finalBitmaps = new Bitmap[barGenerators.Length]; Graphics[] finalBitmapGraphics = new Graphics[barGenerators.Length]; int actualBarHeight = 0; int x = 0; foreach (var bitmapStream in bitmapStreamSource) { if (x == 0) { var imageInfo = ImageFileInfo.Load(bitmapStream); actualBarHeight = parameters.Height ?? imageInfo.Frames.First().Height; for (int i = 0; i < barGenerators.Length; i++) { finalBitmaps[i] = new Bitmap(parameters.Width, actualBarHeight); finalBitmapGraphics[i] = Graphics.FromImage(finalBitmaps[i]); } } using (bitmapStream) { for (int i = 0; i < barGenerators.Length; i++) { bitmapStream.Position = 0; var bar = barGenerators[i].GetBar(bitmapStream, parameters.BarWidth, actualBarHeight); var srcRect = new Rectangle(0, 0, bar.Width, bar.Height); var destRect = new Rectangle(x, 0, parameters.BarWidth, actualBarHeight); finalBitmapGraphics[i].DrawImage(bar, destRect, srcRect, GraphicsUnit.Pixel); } x += parameters.BarWidth; progress?.Report((double)x / parameters.Width); } } for (int i = 0; i < barGenerators.Length; i++) { finalBitmapGraphics[i]?.Dispose(); } var result = new Dictionary <IBarGenerator, Bitmap>(); for (int i = 0; i < barGenerators.Length; i++) { result.Add(barGenerators[i], finalBitmaps[i]); } return(result); }