Esempio n. 1
0
        /// <summary>
        /// Extracts a screenshot from the center of the video.
        /// </summary>
        private async Task CreateVideoThumbnailAsync(string path)
        {
            _logger.Information($"Thumbnail extraction started for video file: {path}");

            var durationRaw = await ProcessHelper.GetOutputAsync(GetFFPath("ffprobe"), $@"-i ""{path}"" -show_entries format=duration -v quiet -of csv=""p=0""");

            var duration = durationRaw.Replace(",", ".").TryParse <double?>();

            if (duration == null)
            {
                _logger.Error($"Failed to get media duration: '{durationRaw}' is not a valid number.");
            }

            var position = (int)((duration ?? 0) / 2);

            var screenPath = Path.ChangeExtension(path, ".jpg");
            await ProcessHelper.InvokeAsync(GetFFPath("ffmpeg"), $@"-i ""{path}"" -y -vframes 1 -ss {position} ""{screenPath}""");

            _logger.Information("Thumbnail extraction completed.");

            using var img = await Image.LoadAsync(screenPath);

            await MediaHandlerHelper.CreateThumbnailsAsync(screenPath, img);

            File.Delete(screenPath);
        }
Esempio n. 2
0
        /// <summary>
        /// Extracts a screenshot from the center of the video.
        /// </summary>
        private async Task CreateVideoThumbnailAsync(string path)
        {
            var durationRaw = await ProcessHelper.GetOutputAsync(GetFFPath("ffprobe"), $@"-i ""{path}"" -show_entries format=duration -v quiet -of csv=""p=0""");

            var duration = durationRaw.Parse <double>();
            var middle   = (int)(duration / 2);

            var screenPath = Path.ChangeExtension(path, ".jpg");
            await ProcessHelper.InvokeAsync(GetFFPath("ffmpeg"), $@"-i ""{path}"" -y -vframes 1 -ss {middle} ""{screenPath}""");

            using (var img = Image.FromFile(screenPath))
                MediaHandlerHelper.CreateThumbnails(screenPath, img);

            File.Delete(screenPath);
        }