Exemple #1
0
        //Generates thumbnails by running ffmpeg on the file, and saving them in a temp folder.
        private void GenerateThumbnails()
        {
            double tween = Duration / (Rows * Columns);

            _thumbDir = "temp/temp_" + (FilePath.GetHashCode() + DateTime.Now.Millisecond);
            Directory.CreateDirectory(_thumbDir);

            var proc = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName        = "ffmpeg",
                    Arguments       = $"-i \"{FilePath}\" -vf fps=1/{tween} {_thumbDir}/img%05d.png",
                    UseShellExecute = false,
                    CreateNoWindow  = true
                }
            };

            try
            {
                proc.Start();
                proc.WaitForExit();
                proc.Dispose();
            }
            catch
            {
                _logger.LogError($"ffmpeg failed to start.");
                throw new FfmpegException();
            }

            int count = 0;

            foreach (string s in Directory.GetFiles(_thumbDir))
            {
                Thumbnails.Add(ThumbnailFactory.CreateThumbnail(s, ++count * tween));
            }
        }
Exemple #2
0
        private bool CreateThumnail()
        {
            if (HasCurrentThumbnail() == true)
                return true;

            ThumbnailFactory t = new ThumbnailFactory(ThumbnailSize.Normal);

            // can we attempt to create it?
            if (!t.CanThumbnail(filename, Mime, CurrentMtime)) {
                Console.WriteLine(Catalog.GetString("Cannot create thumbnail for: {0}"), filename);
                return false;
            }

            // Generate and save thumbnail
            Pixbuf tmp = t.GenerateThumbnail(filename, Mime);
            t.SaveThumbnail(tmp, filename, CurrentMtime);

            return true;
        }
Exemple #3
0
        // Grab thumbnail
        public Pixbuf Thumbnail()
        {
            string		existing;

            // Totaly ignore removed wps
            if (removed)
                return null;

            // Cached thumb nail? Just make sure it's current
            if (ThumbCache != null && HasCurrentThumbnail() == true)
                return ThumbCache;
            else
                ThumbCache = null;

            // Attempt to create a new thumbnail (or at least check if there is an old valid one)
            if (CreateThumnail() == false)
                return null;

            ThumbnailFactory t = new ThumbnailFactory(ThumbnailSize.Normal);

            // Grab the thumb
            existing = t.Lookup(filename, CurrentMtime);
            Pixbuf thumb = new Pixbuf(existing);

            // Figure out the scale for previews
            int x, y;
            switch (Res.ResolutionList.AspectType(w,h)) {
            case Res.Aspect.ASPECT_43:
                x = 64;
                y = 48;
                break;
            case Res.Aspect.ASPECT_WIDE:
                x = 64;
                y = 36;
                break;
            case Res.Aspect.ASPECT_OTHER:
            default:
                x = 64;
                y = 64;
                break;
            }

            // for really small images, do our own resizing; hopefully there won't be too many
            if (thumb.Width < x || thumb.Height < y) {
                ThumbCache = thumb.ScaleSimple(x, y, Gdk.InterpType.Bilinear);
            } else {
                ThumbCache = Gnome.Thumbnail.ScaleDownPixbuf(thumb, x, y);
            }

            thumb.Dispose();
            return ThumbCache;
        }