Ejemplo n.º 1
0
        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;
            }
        }
Ejemplo n.º 2
0
        public FFMpegVideoInfo GetVideoInfo(string inputFile)
        {
            if (string.IsNullOrEmpty(inputFile) || (!inputFile.Contains("http://") && !inputFile.Contains("https://") && !File.Exists(inputFile)))
            {
                throw new FileNotFoundException($"Can't get video info. File path is null or file doesn't exist. Path: {inputFile}");
            }

            // информация о видео придёт вместе с сообщением об ошибке, что не задан выходной файл.
            var command = new FFMpegCommand(pathToFfMpegExe, $"-i \"{inputFile}\"", true);
            var result  = this.ExecuteFFMpegCommand(command, "GetVideoInfo");

            return(ParseVideoInfo(result));
        }
Ejemplo n.º 3
0
 private string ExecuteFFMpegCommand(FFMpegCommand command, string operationName)
 {
     try
     {
         var result = command.Execute();
         this.LogMessage(operationName, result);
         return(result);
     }
     catch (FFMpegException ffMpegException)
     {
         this.LogMessage(operationName, ffMpegException.AllFFMpegOutput);
         throw;
     }
     catch (Exception exception)
     {
         this.LogMessage(operationName + " UNKNOWN ERROR", exception.Message);
         throw;
     }
 }