Exemplo n.º 1
0
        private void CreateImageButton_Click(object sender, RoutedEventArgs e)
        {
            _imageExt.ToBitmapImage(Screen);

            ImageItem.Source = _imageExt.GetImageSource();

            var time = Screen.Position;

            var foo = new MediaFile {Filename = "Hist.bmp"};

            if (File.Exists("Hist.bmp"))
            {
                File.Delete("Hist.bmp");
            }

            using (var engine = new Engine())
            {
                engine.GetMetadata(inputFile);

                var options = new ConversionOptions {Seek = TimeSpan.FromMilliseconds(time.Milliseconds)};
                engine.GetThumbnail(inputFile, foo, options);
            }
        }
Exemplo n.º 2
0
 public void genThumb()
 {
     thumbPath = System.IO.Path.Combine( System.IO.Path.GetTempPath(), cutName+index.ToString()+".jpg");
     var inputFile = new MediaFile { Filename = sourcePath };
     var outputFile = new MediaFile { Filename = thumbPath };
     using (var engine = new Engine())
     {
         engine.GetMetadata(inputFile);
         var options = new ConversionOptions { Seek = startTime };
         engine.GetThumbnail(inputFile, outputFile, options);
     }
     var img = System.Drawing.Image.FromFile(thumbPath);
     MemoryStream ms = new MemoryStream();
     img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
     imgThumb = ms.ToArray();
 }
Exemplo n.º 3
0
        public static void ExtractFrame(string file, int momentFromStartInSeconds, string output)
        {
            var inputFile = new MediaFile { Filename = file };
            var outputFile = new MediaFile { Filename = output };

            using (var engine = new Engine())
            {
                engine.GetMetadata(inputFile);
                var options = new ConversionOptions { Seek = TimeSpan.FromSeconds(momentFromStartInSeconds) };
                try
                {
                    engine.GetThumbnail(inputFile, outputFile, options);
                }
                catch(Exception ex)
                {
                    Console.WriteLine("Failed to extract the image from: {0} because of {1}", inputFile, ex.ToString());
                }
            }
        }
        public StdResult<List<string>> ExtractFrames(int nbFramesDesired)
        {
            DesiredFramesAmount = nbFramesDesired;
            int nbSeconds = (int)GetVideoLength().ReturnObject.TotalSeconds;
            int framePeriod = nbSeconds / (nbFramesDesired + 1);

            List<MediaFile> outputFiles = new List<MediaFile>();

            using (var engine = new Engine())
            {
                engine.GetMetadata(InputFile);

                for (int i = 0; i < DesiredFramesAmount; i++)
                {
                    outputFiles.Add(new MediaFile { Filename = string.Format(OutputSpriteFramePathTemplate, i) });
                    var options = new ConversionOptions { Seek = TimeSpan.FromSeconds((i + 1) * framePeriod), VideoSize = VideoSize._200par125 };
                    if (File.Exists(outputFiles[i].Filename))
                        File.Delete(outputFiles[i].Filename);
                    engine.GetThumbnail(InputFile, outputFiles[i], options);
                }
            }
            OutputSpriteFrames = outputFiles.Select(of => of.Filename).ToList();
            return StdResult<List<string>>.OkResultInstance(OutputSpriteFrames);
        }
        public StdResult<string> CreateThumbnail(string forceOutputFilePath = null, TimeSpan? forceTimeSpan = null)
        {
            var outputFile = new MediaFile { Filename = OutputImagePath };

            using (var engine = new Engine())
            {
                engine.GetMetadata(InputFile);

                // Saves the frame located on the 15th second of the video.
                var options = new ConversionOptions { Seek = TimeSpan.FromSeconds(15) };
                engine.GetThumbnail(InputFile, outputFile, options);
            }
            return StdResult<string>.OkResultInstance(OutputImagePath);
        }