public byte[] GetBitmapFromVideoAsByte(string videoFile, double position, FFMpegImageSize imageSize) { var intermediateFile = this.temporaryFilesStorage.GetIntermediateFile(".jpg"); try { var quality = imageSize.ToString().ToLower(); var parameters = string.Format( CultureInfo.InvariantCulture, "-ss {1} -i \"{0}\" -vframes 1 -s {2} \"{3}\"", videoFile, position, quality, intermediateFile); var command = new FFMpegCommand(pathToFfMpegExe, parameters, true); this.ExecuteFFMpegCommand(command, "ExtractFrame"); using (var fs = new FileStream(intermediateFile, FileMode.Open, FileAccess.Read)) { var byteImage = new byte[fs.Length]; fs.Read(byteImage, 0, (int)fs.Length); this.LogMessage("ExtractFrame", "RETURN: " + byteImage.Length); return(byteImage); } } catch (Exception e) { this.LogMessage("ExtractFrame error:", e.GetFullMessage()); throw; } }
public byte[] GetFrameFromVideoAsByte(string videoFile, double positionMs, FFMpegImageSize imageSize) { using (var tempFileStorage = new TemporaryFilesStorage()) { using (var mhandler = new FFMpeg(tempFileStorage)) { return(mhandler.GetBitmapFromVideoAsByte(videoFile, positionMs, imageSize)); } } }
public async Task <byte[]> GetFrameFromVideoAsByteAsync(string videoFile, double positionMs, FFMpegImageSize imageSize) { return(await await Task.Factory.StartNew( async() => { using (var tempFileStorage = new TemporaryFilesStorage()) { using (var mhandler = new FFMpeg(tempFileStorage)) { return mhandler.GetBitmapFromVideoAsByte(videoFile, positionMs, imageSize); } } }, TaskCreationOptions.RunContinuationsAsynchronously)); }