Exemplo n.º 1
0
        private static (EntryFlags err, List <byte[]>?) GetImageAsBitmaps(VideoFileEntry videoFile, int count)
        {
            var images = new List <byte[]>();

            for (var i = 0; i < count; i++)
            {
                try {
                    using var byteStream  = File.OpenRead(videoFile.Path);
                    using var bitmapImage = Image.FromStream(byteStream);
                    //Set some props while we already loaded the image
                    videoFile.mediaInfo = new FFProbeWrapper.MediaInfo {
                        Streams = new FFProbeWrapper.MediaInfo.StreamInfo[] {
                            new FFProbeWrapper.MediaInfo.StreamInfo {
                                Height = bitmapImage.Height, Width = bitmapImage.Width
                            }
                        }
                    };
                    var b = new Bitmap(16, 16);
                    using (var g = Graphics.FromImage(b)) {
                        g.DrawImage(bitmapImage, 0, 0, 16, 16);
                    }
                    var d = ExtensionMethods.GetGrayScaleValues(b);
                    if (d == null)
                    {
                        return(EntryFlags.TooDark, null);
                    }
                    images.Add(d);
                }
                catch (Exception ex) {
                    Logger.Instance.Info($"Exception, file: {videoFile.Path}, reason: {ex.Message}, stacktrace {ex.StackTrace}");
                    return(EntryFlags.ThumbnailError, null);
                }
            }
            return(0, images);
        }
Exemplo n.º 2
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.º 3
0
        private static (EntryFlags err, List <byte[]>) GetImageAsBitmaps(VideoFileEntry videoFile, int count)
        {
            var images = new List <byte[]>();

            for (var i = 0; i < count; i++)
            {
                try {
                    using (var byteStream = File.OpenRead(videoFile.Path)) {
                        using (var bitmapImage = Image.FromStream(byteStream)) {
                            var b = new Bitmap(16, 16);
                            using (var g = Graphics.FromImage(b)) {
                                g.DrawImage(bitmapImage, 0, 0, 16, 16);
                            }
                            var d = ExtensionMethods.GetGrayScaleValues(b);
                            if (d == null)
                            {
                                return(EntryFlags.TooDark, null);
                            }
                            images.Add(d);
                        }
                    }
                }
                catch (Exception ex) {
                    Logger.Instance.Info($"Exception, file: {videoFile.Path}, reason: {ex.Message}, stacktrace {ex.StackTrace}");
                    return(EntryFlags.ThumbnailError, null);
                }
            }
            return(0, images);
        }
Exemplo n.º 4
0
 private bool IsVideoPassingFilter(VideoFileEntry entry)
 {
     // Here we can do our advanced filtering.
     // In our example filter out any video shorter than 60 seconds
     // you can ofcource get extended properties for the video and filter on that
     // do analysis of thumbnails in the video, scan a video for facial recognition etc.
     if (entry.LengthSeconds < 60)
     {
         return(true);
     }
     return(false);
 }
Exemplo n.º 5
0
        private void InternalBuildFileList()
        {
            ScanFileList.Clear();
            DatabaseFileList = DatabaseHelper.LoadDatabase();

            var st = Stopwatch.StartNew();

            foreach (var item in Settings.IncludeList)
            {
                foreach (var path in FileHelper.GetFilesRecursive(item, Settings.IgnoreReadOnlyFolders,
                                                                  Settings.IncludeSubDirectories, Settings.IncludeImages, Settings.BlackList.ToList()))
                {
                    if (!DatabaseFileList.TryGetValue(path, out var vf))
                    {
                        vf = new VideoFileEntry(path);
                        DatabaseFileList.Add(path, vf);
                    }
                    ScanFileList.Add(vf);
                }
            }

            st.Stop();
            Logger.Instance.Info(string.Format(Properties.Resources.FinishedBuildingFileListIn, st.Elapsed));
        }