Beispiel #1
0
        /// <summary>
        ///     Saves a 'png' thumbnail from the input video to drive
        /// </summary>
        /// <param name="input">Source video analysis</param>
        /// <param name="output">Output video file path</param>
        /// <param name="captureTime">Seek position where the thumbnail should be taken.</param>
        /// <param name="size">Thumbnail size. If width or height equal 0, the other will be computed automatically.</param>
        /// <param name="streamIndex">Selected video stream index.</param>
        /// <param name="inputFileIndex">Input file index</param>
        /// <returns>Bitmap with the requested snapshot.</returns>
        public static async Task <bool> SnapshotAsync(string input, string output, Size?size = null, TimeSpan?captureTime = null, int?streamIndex = null, int inputFileIndex = 0)
        {
            if (Path.GetExtension(output) != FileExtension.Png)
            {
                output = Path.GetFileNameWithoutExtension(output) + FileExtension.Png;
            }

            var source = await FFProbe.AnalyseAsync(input);

            var(arguments, outputOptions) = BuildSnapshotArguments(input, source, size, captureTime, streamIndex, inputFileIndex);

            return(await arguments
                   .OutputToFile(output, true, outputOptions)
                   .ProcessAsynchronously());
        }
Beispiel #2
0
        /// <summary>
        ///     Saves a 'png' thumbnail to an in-memory bitmap
        /// </summary>
        /// <param name="input">Source video file.</param>
        /// <param name="captureTime">Seek position where the thumbnail should be taken.</param>
        /// <param name="size">Thumbnail size. If width or height equal 0, the other will be computed automatically.</param>
        /// <param name="streamIndex">Selected video stream index.</param>
        /// <param name="inputFileIndex">Input file index</param>
        /// <returns>Bitmap with the requested snapshot.</returns>
        public static async Task <Bitmap> SnapshotAsync(string input, Size?size = null, TimeSpan?captureTime = null, int?streamIndex = null, int inputFileIndex = 0)
        {
            var source = await FFProbe.AnalyseAsync(input);

            var(arguments, outputOptions) = BuildSnapshotArguments(input, source, size, captureTime, streamIndex, inputFileIndex);
            using var ms = new MemoryStream();

            await arguments
            .OutputToPipe(new StreamPipeSink(ms), options => outputOptions(options
                                                                           .ForceFormat("rawvideo")))
            .ProcessAsynchronously();

            ms.Position = 0;
            return(new Bitmap(ms));
        }