public override VideoSummary ExtractSummary(string filePath, int thumbs, Size maxSize)
        {
            VideoSummary    summary = new VideoSummary(filePath);
            OpenVideoResult res     = Open(filePath);

            if (res != OpenVideoResult.Success || generator == null)
            {
                return(summary);
            }

            Bitmap bmp  = generator.Generate(0, maxSize);
            Size   size = bmp.Size;

            summary.ImageSize = size;

            int      height = (int)(size.Height / ((float)size.Width / maxSize.Width));
            Bitmap   thumb  = new Bitmap(maxSize.Width, height);
            Graphics g      = Graphics.FromImage(thumb);

            g.DrawImage(bmp, 0, 0, maxSize.Width, height);
            g.Dispose();
            Close();

            summary.Thumbs.Add(thumb);
            summary.DurationMilliseconds = (int)((videoInfo.DurationTimeStamps - videoInfo.AverageTimeStampsPerFrame) * videoInfo.FrameIntervalMilliseconds);
            summary.Framerate            = videoInfo.FramesPerSeconds;
            summary.IsImage = false;

            return(summary);
        }
Exemplo n.º 2
0
        public override VideoSummary ExtractSummary(string filePath, int thumbs, Size maxSize)
        {
            VideoSummary    summary = new VideoSummary(filePath);
            OpenVideoResult res     = Open(filePath);

            if (res != OpenVideoResult.Success || generator == null)
            {
                return(summary);
            }

            Bitmap   bmp   = generator.Generate(0, maxSize);
            Bitmap   thumb = new Bitmap(bmp.Width, bmp.Height);
            Graphics g     = Graphics.FromImage(thumb);

            g.DrawImage(bmp, 0, 0, bmp.Width, bmp.Height);
            g.Dispose();
            Close();

            summary.Thumbs.Add(thumb);
            summary.IsImage              = true;
            summary.ImageSize            = Size.Empty;
            summary.DurationMilliseconds = 0;

            return(summary);
        }
Exemplo n.º 3
0
        private OpenVideoResult InstanciateGenerator(string filePath)
        {
            OpenVideoResult res       = OpenVideoResult.NotSupported;
            string          extension = Path.GetExtension(filePath).ToLower();

            switch (extension)
            {
            case ".jpg":
            case ".jpeg":
            case ".png":
            case ".bmp":
            {
                generator = new FrameGeneratorImageFile();
                break;
            }

            default:
                throw new NotImplementedException();
            }

            if (generator != null)
            {
                res         = generator.Initialize(filePath);
                initialized = res == OpenVideoResult.Success;
            }
            return(res);
        }
Exemplo n.º 4
0
        public override VideoSummary ExtractSummary(string filePath, int thumbsToGet, Size maxSize)
        {
            VideoSummary summary = new VideoSummary(filePath);

            OpenVideoResult res       = LoadFile(filePath, false);
            FrameDimension  dimension = new FrameDimension(gif.FrameDimensionsList[0]);

            if (res == OpenVideoResult.Success)
            {
                summary.IsImage = count == 1;
                summary.DurationMilliseconds = (int)((double)count * videoInfo.FrameIntervalMilliseconds);
                summary.Framerate            = videoInfo.FramesPerSeconds;

                if (thumbsToGet > 0)
                {
                    int step = (int)Math.Ceiling(count / (double)thumbsToGet);
                    for (int i = 0; i < count; i += step)
                    {
                        summary.Thumbs.Add(GetFrameAt(dimension, i));
                    }
                }

                summary.ImageSize = videoInfo.OriginalSize;
            }

            if (loaded)
            {
                Close();
            }

            gif.Dispose();
            return(summary);
        }
Exemplo n.º 5
0
        public override VideoSummary ExtractSummary(string filePath, int thumbs, Size maxSize)
        {
            OpenVideoResult res     = Open(filePath);
            VideoSummary    summary = new VideoSummary(filePath);

            if (res != OpenVideoResult.Success || generator == null)
            {
                return(summary);
            }

            SystemBitmap bmp  = generator.Generate(0);
            Size         size = bmp.Size;

            summary.ImageSize = size;

            // TODO: compute the correct ratio stretched size. Currently this uses the maxSize.width
            // which is not the actual final width of the thumbnail if the ratio is more vertical than 4:3.
            int height = (int)(size.Height / ((float)size.Width / maxSize.Width));

            SystemBitmap thumb = new SystemBitmap(maxSize.Width, height);
            Graphics     g     = Graphics.FromImage(thumb);

            g.DrawImage(bmp, 0, 0, maxSize.Width, height);
            g.Dispose();
            Close();

            summary.Thumbs.Add(thumb);

            summary.IsImage = true;
            summary.DurationMilliseconds = 0;

            return(summary);
        }
        private OpenVideoResult InstanciateGenerator(SyntheticVideo video)
        {
            OpenVideoResult res = OpenVideoResult.NotSupported;

            generator   = new FrameGeneratorSyntheticVideo(video);
            res         = generator.Initialize(null);
            initialized = res == OpenVideoResult.Success;
            return(res);
        }
Exemplo n.º 7
0
        private OpenVideoResult LoadFile(string filePath, bool cache)
        {
            OpenVideoResult result = OpenVideoResult.UnknownError;

            do
            {
                if (gif != null)
                {
                    gif.Dispose();
                }

                gif = Image.FromFile(filePath);
                if (gif == null)
                {
                    result = OpenVideoResult.FileNotOpenned;
                    log.ErrorFormat("The file could not be openned.");
                    break;
                }

                // Get duration in frames.
                // .NET bitmaps actually have several lists of multiple images inside a single Bitmap.
                // For example, to hold the sequence of frames, the layers, or the different resolutions for icons.
                // FrameDimension is used to access the list of frames.
                FrameDimension dimension = new FrameDimension(gif.FrameDimensionsList[0]);
                count = gif.GetFrameCount(dimension);

                // Duration of first interval. (PropertyTagFrameDelay)
                // The byte array returned by the Value property contains 32bits integers for each frame interval (in 1/100th).
                PropertyItem pi       = gif.GetPropertyItem(0x5100);
                int          interval = BitConverter.ToInt32(pi.Value, 0);
                if (interval <= 0)
                {
                    interval = 5;
                }
                videoInfo.DurationTimeStamps        = count * interval;
                videoInfo.FrameIntervalMilliseconds = interval * 10;

                videoInfo.FramesPerSeconds          = 100D / interval;
                videoInfo.AverageTimeStampsPerFrame = interval;

                videoInfo.OriginalSize    = gif.Size;
                videoInfo.AspectRatioSize = videoInfo.OriginalSize;
                videoInfo.ReferenceSize   = videoInfo.OriginalSize;

                if (cache)
                {
                    LoadCache(dimension);
                }

                loaded = true;
                result = OpenVideoResult.Success;
            }while(false);

            return(result);
        }
Exemplo n.º 8
0
        public override OpenVideoResult Open(string filePath)
        {
            OpenVideoResult res = InstanciateGenerator(filePath);

            if (res != OpenVideoResult.Success)
            {
                return(res);
            }

            SetupVideoInfo(filePath);
            workingZone = new VideoSection(0, videoInfo.DurationTimeStamps);

            return(res);
        }
Exemplo n.º 9
0
        private OpenVideoResult InstanciateGenerator(string filePath)
        {
            OpenVideoResult res       = OpenVideoResult.NotSupported;
            string          extension = Path.GetExtension(filePath).ToLower();

            if (extension != ".svg")
            {
                throw new NotImplementedException();
            }

            generator   = new FrameGeneratorSVG();
            res         = generator.Initialize(filePath);
            initialized = res == OpenVideoResult.Success;
            return(res);
        }
Exemplo n.º 10
0
        public OpenVideoResult Initialize(string filepath)
        {
            OpenVideoResult res = OpenVideoResult.NotSupported;

            try
            {
                svgWindow.Src = filepath;
                InitSizeInfo();
                res = OpenVideoResult.Success;
            }
            catch (Exception e)
            {
                log.ErrorFormat("An error occured while trying to open {0}", filepath);
                log.Error(e);
            }

            return(res);
        }
Exemplo n.º 11
0
        public override OpenVideoResult Open(string filePath)
        {
            if (loaded)
            {
                Close();
            }

            videoInfo.FirstTimeStamp = 0;
            videoInfo.AverageTimeStampsPerSeconds = 100;
            videoInfo.FilePath = filePath;

            // This reader can only function in frozen cache mode,
            // so we systematically load the cache during opening.
            OpenVideoResult res = LoadFile(filePath, true);

            gif.Dispose();
            DumpInfo();
            return(res);
        }
Exemplo n.º 12
0
        public OpenVideoResult Initialize(string init)
        {
            OpenVideoResult res = OpenVideoResult.NotSupported;

            try
            {
                bitmap = new SystemBitmap(init);
                if (bitmap != null)
                {
                    res = OpenVideoResult.Success;
                }
            }
            catch (Exception e)
            {
                log.ErrorFormat("An error occured while trying to open {0}", init);
                log.Error(e);
            }
            return(res);
        }
Exemplo n.º 13
0
        public OpenVideoResult Initialize(string init)
        {
            OpenVideoResult res = OpenVideoResult.NotSupported;

            try
            {
                bitmap = new SystemBitmap(init);
                if (bitmap != null)
                {
                    res = OpenVideoResult.Success;
                }

                // Force input to be 96 dpi like GDI+ so we don't have any surprises when calling Graphics.DrawImageUnscaled().
                bitmap.SetResolution(96, 96);
            }
            catch (Exception e)
            {
                log.ErrorFormat("An error occured while trying to open {0}", init);
                log.Error(e);
            }
            return(res);
        }
        public override OpenVideoResult Open(string filePath)
        {
            this.filePath = filePath;
            this.video    = SyntheticVideoSerializer.Deserialize(filePath);

            if (video == null)
            {
                return(OpenVideoResult.NotSupported);
            }

            OpenVideoResult res = InstanciateGenerator(video);

            if (res != OpenVideoResult.Success)
            {
                return(res);
            }

            SetupVideoInfo();
            workingZone = new VideoSection(0, videoInfo.DurationTimeStamps - videoInfo.AverageTimeStampsPerFrame);

            return(res);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Actually loads the video into the chosen screen.
        /// </summary>
        private static void LoadVideo(PlayerScreen player, string path, ScreenDescriptionPlayback screenDescription)
        {
            log.DebugFormat("Loading video {0}.", path);

            NotificationCenter.RaiseStopPlayback(null);

            if (player.FrameServer.Loaded)
            {
                player.view.ResetToEmptyState();
            }

            if (screenDescription != null)
            {
                player.view.SetLaunchDescription(screenDescription);
            }

            OpenVideoResult res = player.FrameServer.Load(path);

            player.Id = Guid.NewGuid();

            if (screenDescription != null && screenDescription.Id != Guid.Empty)
            {
                player.Id = screenDescription.Id;
            }

            switch (res)
            {
            case OpenVideoResult.Success:
            {
                AfterLoadSuccess(player);
                break;
            }

            case OpenVideoResult.FileNotOpenned:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_FileNotOpened);
                break;
            }

            case OpenVideoResult.StreamInfoNotFound:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_StreamInfoNotFound);
                break;
            }

            case OpenVideoResult.VideoStreamNotFound:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_VideoStreamNotFound);
                break;
            }

            case OpenVideoResult.CodecNotFound:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_CodecNotFound);
                break;
            }

            case OpenVideoResult.CodecNotOpened:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_CodecNotOpened);
                break;
            }

            case OpenVideoResult.CodecNotSupported:
            case OpenVideoResult.NotSupported:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_CodecNotSupported);
                break;
            }

            case OpenVideoResult.Cancelled:
            {
                break;
            }

            default:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_UnkownError);
                break;
            }
            }
        }
        /// <summary>
        /// Actually loads the video into the chosen screen.
        /// </summary>
        public static void LoadVideo(PlayerScreen player, string path, ScreenDescriptionPlayback screenDescription)
        {
            // In the case of replay watcher this will only be called the first time, to setup the screen.
            // Subsequent video loads will be done directly by the replay watcher.

            log.DebugFormat("Loading video {0}.", Path.GetFileName(path));

            NotificationCenter.RaiseStopPlayback(null);

            if (player.FrameServer.Loaded)
            {
                player.view.ResetToEmptyState();
            }

            player.view.LaunchDescription = screenDescription;

            OpenVideoResult res = player.FrameServer.Load(path);

            player.Id = Guid.NewGuid();

            if (screenDescription != null && screenDescription.Id != Guid.Empty)
            {
                player.Id = screenDescription.Id;
            }

            switch (res)
            {
            case OpenVideoResult.Success:
            {
                AfterLoadSuccess(player);
                break;
            }

            case OpenVideoResult.FileNotOpenned:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_FileNotOpened);
                break;
            }

            case OpenVideoResult.StreamInfoNotFound:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_StreamInfoNotFound);
                break;
            }

            case OpenVideoResult.VideoStreamNotFound:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_VideoStreamNotFound);
                break;
            }

            case OpenVideoResult.CodecNotFound:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_CodecNotFound);
                break;
            }

            case OpenVideoResult.CodecNotOpened:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_CodecNotOpened);
                break;
            }

            case OpenVideoResult.CodecNotSupported:
            case OpenVideoResult.NotSupported:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_CodecNotSupported);
                break;
            }

            case OpenVideoResult.Cancelled:
            {
                break;
            }

            case OpenVideoResult.EmptyWatcher:
            {
                break;
            }

            default:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_UnkownError);
                break;
            }
            }

            if (res != OpenVideoResult.Success && player.view.LaunchDescription != null && player.view.LaunchDescription.IsReplayWatcher)
            {
                // Even if we can't load the latest video, or there's no video at all, we should still start watching this folder.
                player.view.EnableDisableActions(false);
                player.StartReplayWatcher(player.view.LaunchDescription, null);
                PreferencesManager.FileExplorerPreferences.LastReplayFolder = path;
                PreferencesManager.Save();
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Actually loads the video into the chosen screen.
        /// </summary>
        public static void LoadVideo(PlayerScreen player, string path, ScreenDescriptionPlayback screenDescription)
        {
            log.DebugFormat("Loading video {0}.", Path.GetFileName(path));

            NotificationCenter.RaiseStopPlayback(null);

            if (player.FrameServer.Loaded)
            {
                player.view.ResetToEmptyState();
            }

            player.view.LaunchDescription = screenDescription;
            player.Id = Guid.NewGuid();
            if (screenDescription != null && screenDescription.Id != Guid.Empty)
            {
                player.Id = screenDescription.Id;
            }

            // This can happen when we load an empty screen from launch settings / workspace.
            if (string.IsNullOrEmpty(path))
            {
                player.view.EnableDisableActions(false);
                return;
            }

            OpenVideoResult res = player.FrameServer.Load(path);

            switch (res)
            {
            case OpenVideoResult.Success:
            {
                AfterLoadSuccess(player);
                break;
            }

            case OpenVideoResult.FileNotOpenned:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_FileNotOpened);
                break;
            }

            case OpenVideoResult.StreamInfoNotFound:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_StreamInfoNotFound);
                break;
            }

            case OpenVideoResult.VideoStreamNotFound:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_VideoStreamNotFound);
                break;
            }

            case OpenVideoResult.CodecNotFound:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_CodecNotFound);
                break;
            }

            case OpenVideoResult.CodecNotOpened:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_CodecNotOpened);
                break;
            }

            case OpenVideoResult.CodecNotSupported:
            case OpenVideoResult.NotSupported:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_CodecNotSupported);
                break;
            }

            case OpenVideoResult.Cancelled:
            {
                break;
            }

            case OpenVideoResult.EmptyWatcher:
            {
                break;
            }

            default:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_UnkownError);
                break;
            }
            }

            if (res != OpenVideoResult.Success && player.view.LaunchDescription != null && player.view.LaunchDescription.IsReplayWatcher)
            {
                // Even if we can't load the latest video, or there's no video at all, we should still start watching this folder.
                player.view.EnableDisableActions(false);
                player.StartReplayWatcher(player.view.LaunchDescription, null);
                PreferencesManager.FileExplorerPreferences.LastReplayFolder = path;
                PreferencesManager.Save();
            }
        }