Exemplo n.º 1
0
        private (EntryFlags err, List <byte[]>?) GetVideoThumbnailAsBitmaps(VideoFileEntry videoFile, List <float> positions)
        {
            var ffMpeg = new FFmpegWrapper.FFmpegWrapper();
            var images = new List <byte[]>();

            try {
                for (var i = 0; i < positions.Count; i++)
                {
                    var b = ffMpeg.GetVideoThumbnail(videoFile.Path, Convert.ToSingle(videoFile.mediaInfo?.Duration.TotalSeconds * positionList[i]), true);
                    if (b == null || b.Length == 0)
                    {
                        return(EntryFlags.ThumbnailError, null);
                    }
                    var d = ExtensionMethods.VerifyGrayScaleValues(b);
                    if (d == null)
                    {
                        return(EntryFlags.TooDark, null);
                    }
                    images.Add(d);
                }
            }
            catch (FFmpegWrapper.FFMpegException ex) {
                Logger.Instance.Info($"FFMpegException, file: {videoFile.Path}, reason: {ex.Message}");
                return(EntryFlags.ThumbnailError, null);
            }
            return(0, images);
        }
Exemplo n.º 2
0
        private List <Image>?GetVideoThumbnail(DuplicateItem videoFile, List <float> positions)
        {
            var ffMpeg = new FFmpegWrapper.FFmpegWrapper();
            var images = new List <Image>();

            try {
                for (var i = 0; i < positions.Count; i++)
                {
                    var b = ffMpeg.GetVideoThumbnail(videoFile.Path, Convert.ToSingle(videoFile.Duration.TotalSeconds * positionList[i]), false);
                    if (b == null || b.Length == 0)
                    {
                        return(null);
                    }
                    using var byteStream = new MemoryStream(b);
                    var bitmapImage = Image.FromStream(byteStream);
                    images.Add(bitmapImage);
                }
            }
            catch (FFmpegWrapper.FFMpegException ex) {
                Logger.Instance.Info($"FFMpegException, file: {videoFile.Path}, reason: {ex.Message}");
                return(null);
            }
            catch (Exception ex) {
                Logger.Instance.Info($"Exception, file: {videoFile.Path}, reason: {ex.Message}, stacktrace {ex.StackTrace}");
                return(null);
            }
            return(images);
        }