public void generateThumbnail(MediaProbe mediaProbe, VideoMetadata video,
            CancellationToken token, int timeoutSeconds, int nrThumbnails)
        {
            video.Thumbnail = null;

            List<MediaThumb> coverBitmaps = mediaProbe.grabAttachedImages(Constants.MAX_THUMBNAIL_WIDTH,
                 Constants.MAX_THUMBNAIL_HEIGHT, token, timeoutSeconds);

            if (coverBitmaps.Count > 0)
            {
                video.Thumbnail = new Thumbnail(coverBitmaps[0].Thumb);
            }

            if (coverBitmaps.Count == 0 || nrThumbnails > 1)
            {

                List<MediaThumb> thumbBitmaps = mediaProbe.grabThumbnails(Constants.MAX_THUMBNAIL_WIDTH,
                     Constants.MAX_THUMBNAIL_HEIGHT, 0, nrThumbnails, 0.025, token, timeoutSeconds, null);

                if (thumbBitmaps.Count > 0 && coverBitmaps.Count == 0)
                {
                    video.Thumbnail = new Thumbnail(thumbBitmaps[0].Thumb);
                }

            }
        }
Beispiel #2
0
        public void generateThumbnail(MediaProbe mediaProbe, ImageMetadata image,
                                      CancellationToken token, int timeoutSeconds, int nrThumbnails)
        {
            // possibly could not seek in video, try to get the first frame in the video
            List <MediaThumb> thumbBitmaps = mediaProbe.grabThumbnails(Constants.MAX_THUMBNAIL_WIDTH,
                                                                       Constants.MAX_THUMBNAIL_HEIGHT, 0, 1, 0, token, timeoutSeconds, null);

            if (thumbBitmaps.Count > 0)
            {
                BitmapSource thumb = thumbBitmaps[0].Thumb;

                if (image.Orientation.HasValue && image.Orientation.Value != 1)
                {
                    System.Windows.Media.Transform transform = null;

                    switch (image.Orientation.Value)
                    {
                    case 2:
                    {
                        //Mirror horizontal
                        transform = new System.Windows.Media.MatrixTransform(-1, 0, 0, 1, 0, 0);
                        break;
                    }

                    case 3:
                    {
                        //Rotate 180°
                        transform = new System.Windows.Media.RotateTransform(180);
                        break;
                    }

                    case 4:
                    {
                        //Mirror vertical
                        transform = new System.Windows.Media.MatrixTransform(1, 0, 0, -1, 0, 0);
                        break;
                    }

                    case 5:
                    {
                        //Mirror horizontal, rotate 270°
                        transform = new System.Windows.Media.MatrixTransform(0, -1, -1, 0, 0, 0);
                        break;
                    }

                    case 6:
                    {
                        //Rotate 90°
                        transform = new System.Windows.Media.RotateTransform(90);
                        break;
                    }

                    case 7:
                    {
                        //Mirror horizontal, rotate 90°
                        transform = new System.Windows.Media.MatrixTransform(0, 1, 1, 0, 0, 0);
                        break;
                    }

                    case 8:
                    {
                        //Rotate 270°
                        transform = new System.Windows.Media.RotateTransform(270);
                        break;
                    }

                    default:
                    {
                        Logger.Log.Warn("Unknown orientation for image");
                        break;
                    }
                    }

                    if (transform != null)
                    {
                        thumb = new TransformedBitmap(thumb, transform);
                    }
                }

                image.Thumbnail = new Thumbnail(thumb);
            }
            else
            {
                image.Thumbnail = null;
            }
        }
        public void generateThumbnail(MediaProbe mediaProbe, ImageMetadata image,
            CancellationToken token, int timeoutSeconds, int nrThumbnails)
        {
          
            // possibly could not seek in video, try to get the first frame in the video
            List<MediaThumb> thumbBitmaps = mediaProbe.grabThumbnails(Constants.MAX_THUMBNAIL_WIDTH,
                Constants.MAX_THUMBNAIL_HEIGHT, 0, 1, 0, token, timeoutSeconds, null);

            if (thumbBitmaps.Count > 0)
            {
                BitmapSource thumb = thumbBitmaps[0].Thumb;

                if (image.Orientation.HasValue && image.Orientation.Value != 1)
                {

                    System.Windows.Media.Transform transform = null;

                    switch (image.Orientation.Value)
                    {
                        case 2:
                            {
                                //Mirror horizontal
                                transform = new System.Windows.Media.MatrixTransform(-1, 0, 0, 1, 0, 0);
                                break;
                            }

                        case 3:
                            {
                                //Rotate 180°
                                transform = new System.Windows.Media.RotateTransform(180);
                                break;
                            }
                        case 4:
                            {
                                //Mirror vertical
                                transform = new System.Windows.Media.MatrixTransform(1, 0, 0, -1, 0, 0);
                                break;
                            }
                        case 5:
                            {
                                //Mirror horizontal, rotate 270°
                                transform = new System.Windows.Media.MatrixTransform(0, -1, -1, 0, 0, 0);
                                break;
                            }
                        case 6:
                            {
                                //Rotate 90°
                                transform = new System.Windows.Media.RotateTransform(90);
                                break;
                            }
                        case 7:
                            {
                                //Mirror horizontal, rotate 90°
                                transform = new System.Windows.Media.MatrixTransform(0, 1, 1, 0, 0, 0);
                                break;
                            }
                        case 8:
                            {
                                //Rotate 270°
                                transform = new System.Windows.Media.RotateTransform(270);
                                break;
                            }
                        default:
                            {
                                Logger.Log.Warn("Unknown orientation for image");
                                break;
                            }

                    }

                    if (transform != null)
                    {
                        thumb = new TransformedBitmap(thumb, transform);
                    }
                }

                image.Thumbnail = new Thumbnail(thumb);
            }
            else
            {
                image.Thumbnail = null;
            }
                                        
        }
        public void generateThumbnail(MediaProbe mediaProbe, VideoMetadata video,
            CancellationToken token, int timeoutSeconds, int nrThumbnails)
        {
            video.Thumbnail = null;
         
            List<MediaThumb> coverBitmaps = mediaProbe.grabAttachedImages(Constants.MAX_THUMBNAIL_WIDTH,
                 Constants.MAX_THUMBNAIL_HEIGHT, token, timeoutSeconds);

            if (coverBitmaps.Count > 0)
            {
                video.Thumbnail = new Thumbnail(coverBitmaps[0].Thumb);
            }

            if (coverBitmaps.Count == 0 || nrThumbnails > 1)
            {

                List<MediaThumb> thumbBitmaps = mediaProbe.grabThumbnails(Constants.MAX_THUMBNAIL_WIDTH,
                     Constants.MAX_THUMBNAIL_HEIGHT, 0, nrThumbnails, 0.025, token, timeoutSeconds, null);
              
                if (thumbBitmaps.Count > 0 && coverBitmaps.Count == 0)
                {
                    video.Thumbnail = new Thumbnail(thumbBitmaps[0].Thumb);
                }
                
            }

        }