private FastBitmap GetBitmap(float time, MemoryStream stream)
 {
     FastBitmap result = null;
     var ffMpeg = new NReco.VideoConverter.FFMpegConverter();
     ffMpeg.GetVideoThumbnail(FilePath, stream, time);
     if (stream.Length != 0)
     {
         Image img = Image.FromStream(stream);
         result = new FastBitmap(new Bitmap(img, img.Width/Scale , img.Height/Scale));
     }
     return result;
 }
Beispiel #2
0
        /// <summary>
        /// だいたい0.3秒おきの動画サムネイルを取得する
        /// </summary>
        /// <param name="videoPath">ビデオファイルパス</param>
        /// <returns></returns>
        public static IEnumerable <Bitmap> GetThumbnails(string videoPath)
        {
            // メタ情報で再生時間取得
            var ffprob   = new NReco.VideoInfo.FFProbe();
            var info     = ffprob.GetMediaInfo(videoPath);
            var duration = info.Duration;

            var videoConv = new NReco.VideoConverter.FFMpegConverter();

            // 最短0.3秒おき、最大100分割
            var skipSec = duration.TotalSeconds < 30 ?
                          0.3f : (float)(duration.TotalSeconds / 100);

            var frameSec = 0f;

            while ((float)duration.TotalSeconds > frameSec)
            {
                // Bitmapリソースは受信側で開放する。
                var jpegStream = new MemoryStream();
                videoConv.GetVideoThumbnail(videoPath, jpegStream, frameSec);
                yield return((Bitmap)Image.FromStream(jpegStream));

                frameSec += skipSec;
            }
        }
        /*
         * Listener for the Open button
         * Used to get a frame from the video in the given in FilePath
         * and set it as the thumbnail on the form
         */
        private void Open_Click(object sender, EventArgs e)
        {
            //get thumbnail from video and save it as a jpg
            string path   = FilePath.Text.ToString();
            var    ffMpeg = new NReco.VideoConverter.FFMpegConverter();

            ffMpeg.GetVideoThumbnail(path, "thumbnails/thumbnail.jpg", 1);

            //set the picturebox to the thumbnail image
            Thumbnail_Box.SizeMode = PictureBoxSizeMode.StretchImage;
            Thumbnail_Box.Image    = new Bitmap("thumbnails/thumbnail.jpg");
        }
        // Get the bitmap representing a video file
        // Note that displayIntent is ignored as it's specific to interaction with WCF's bitmap cache, which doesn't occur in rendering video preview frames
        public static BitmapSource GetBitmapFromVideoFile(string filePath, Nullable <int> desiredWidthOrHeight, ImageDisplayIntentEnum displayIntent, ImageDimensionEnum imageDimension, out bool isCorruptOrMissing)
        {
            if (!System.IO.File.Exists(filePath))
            {
                isCorruptOrMissing = true;
                return(Constant.ImageValues.FileNoLongerAvailable.Value);
            }
            // Our FFMPEG installation is the 64 bit version. In case someone is using a 32 bit machine, we use the MediaEncoder instead.
            if (Environment.Is64BitOperatingSystem == false)
            {
                // System.Diagnostics.Debug.Print("Can't use ffmpeg as this is a 32 bit machine. Using MediaEncoder instead");
                return(BitmapUtilities.GetVideoBitmapFromFileUsingMediaEncoder(filePath, desiredWidthOrHeight, displayIntent, imageDimension, out isCorruptOrMissing));
            }
            try
            {
                //Saul TO DO:
                // Note: not sure of the cost of creating a new converter every time. May be better to reuse it?
                Stream          outputBitmapAsStream = new MemoryStream();
                FFMpegConverter ffMpeg = new NReco.VideoConverter.FFMpegConverter();
                ffMpeg.GetVideoThumbnail(filePath, outputBitmapAsStream);

                // Scale the video to the desired dimension
                outputBitmapAsStream.Position = 0;
                BitmapImage bitmap = new BitmapImage();
                bitmap.BeginInit();
                if (desiredWidthOrHeight != null)
                {
                    if (imageDimension == ImageDimensionEnum.UseWidth)
                    {
                        bitmap.DecodePixelWidth = desiredWidthOrHeight.Value;
                    }
                    else
                    {
                        bitmap.DecodePixelHeight = desiredWidthOrHeight.Value;
                    }
                }
                bitmap.CacheOption  = BitmapCacheOption.None;
                bitmap.StreamSource = outputBitmapAsStream;
                bitmap.EndInit();
                bitmap.Freeze();
                isCorruptOrMissing = false;
                return(bitmap);
            }
            catch // (FFMpegException e)
            {
                // Couldn't get the thumbnail using FFMPEG. Fallback to try getting it using the MediaEncoder
                return(GetVideoBitmapFromFileUsingMediaEncoder(filePath, desiredWidthOrHeight, displayIntent, imageDimension, out isCorruptOrMissing));
                // We don't print the exception // (Exception exception)
                // TraceDebug.PrintMessage(String.Format("VideoRow/LoadBitmap: Loading of {0} failed in Video - LoadBitmap. {0}", imageFolderPath));
            }
        }
Beispiel #5
0
        private void button2_Click(object sender, EventArgs e)
        {
            string input = @"C:\Users\a\Videos\Debut\Untitled 7.avi";

            string output = "C:\\test3.avi";

            var setting = new NReco.VideoConverter.ConvertSettings();

            setting.SetVideoFrameSize(1280, 720);
            setting.CustomInputArgs = "-ss 00:00:00 -t 00:00:10";
            // setting.CustomOutputArgs = "-vf vflip";
            setting.CustomOutputArgs = "-vf \"movie=logo.png [watermark]; [in][watermark] overlay=main_w-overlay_w-10:main_h-overlay_h-10 [out]\"";


            //            Top left corner
            //ffmpeg -i inputvideo.avi -vf "movie=watermarklogo.png [watermark]; [in][watermark] overlay=10:10 [out]" outputvideo.flv

            //Top right corner
            //ffmpeg -i inputvideo.avi -vf "movie=watermarklogo.png [watermark]; [in][watermark] overlay=main_w-overlay_w-10:10 [out]" outputvideo.flv

            //Bottom left corner
            //ffmpeg -i inputvideo.avi -vf "movie=watermarklogo.png [watermark]; [in][watermark] overlay=10:main_h-overlay_h-10 [out]" outputvideo.flv

            //Bottom right corner
            //ffmpeg -i inputvideo.avi -vf "movie=watermarklogo.png [watermark]; [in][watermark] overlay=main_w-overlay_w-10:main_h-overlay_h-10 [out]" outputvideo.flv



            var ffMpeg = new NReco.VideoConverter.FFMpegConverter();

            ffMpeg.ConvertProgress += FfMpeg_ConvertProgress;

            ffMpeg.GetVideoThumbnail(input, "temp.jpg", 10.0f);
            System.IO.FileStream hStream = new System.IO.FileStream("temp.jpg", System.IO.FileMode.Open);
            this.pictureBox1.Image = Image.FromStream(hStream);
            // FileStream を閉じる (正しくは オブジェクトの破棄を保証する を参照)
            hStream.Close();
            return;

            //ffMpeg.ConvertMedia(input, null, output, null, setting);

            ffMpeg.ConvertMedia(input, null, output, NReco.VideoConverter.Format.mp4, setting);
            //


            NReco.VideoConverter.ConcatSettings set = new NReco.VideoConverter.ConcatSettings();
            set.SetVideoFrameSize(640, 480);
            //ffMpeg.ConcatMedia(_fileNames, videoRootPath + tobename + ".mp4", NReco.VideoConverter.Format.mp4, set);

            this.Text = "FINISH";
        }
Beispiel #6
0
        private void ChooseVidBtn_Click(object sender, EventArgs e)
        {
            PreviewImg.SetLength(0);
            PreviewImg.Position       = 0;
            VideoFileChooser.Filter   = "Video File|*.avi;*.mpeg;*.flv;*.mov;*.ogg;*.mp4;*.wmv;*.mkv;*.h264";
            VideoFileChooser.FileName = "";
            DialogResult result = VideoFileChooser.ShowDialog();

            if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(VideoFileChooser.FileName))
            {
                var ffMpeg      = new NReco.VideoConverter.FFMpegConverter();
                var ffMpegInput = new NReco.VideoConverter.FFMpegInput(VideoFileChooser.FileName.ToString());
                ffMpeg.GetVideoThumbnail(VideoFileChooser.FileName.ToString(), PreviewImg);
                ThumbNailPicture.Image       = Image.FromStream(PreviewImg);
                EnableWatermarkChkBx.Enabled = true;
            }
        }
Beispiel #7
0
        void SetImageSource(FileInfo fileInfo, Image source, int timeCode = 0)
        {
            MemoryStream imageStream = new MemoryStream();

            source.Resources["path"] = fileInfo.FullName;
            // image
            if (timeCode == 0)
            {
                try
                {
                    BitmapImage LoadImage = new BitmapImage();
                    LoadImage.BeginInit();
                    LoadImage.UriSource = new Uri(fileInfo.FullName);
                    LoadImage.EndInit();
                    LoadImage.Freeze();
                    source.Source = LoadImage;
                }
                catch (Exception e)
                {
                    Console.Write(e.Data);
                }
            }
            // video
            else
            {
                NReco.VideoConverter.FFMpegConverter ffMpeg = new NReco.VideoConverter.FFMpegConverter();
                ffMpeg.GetVideoThumbnail(fileInfo.FullName, imageStream, timeCode);
                imageStream.Seek(0, SeekOrigin.Begin);
                using (var stream = imageStream)
                {
                    var bitmap = new BitmapImage();
                    bitmap.BeginInit();
                    bitmap.StreamSource = stream;
                    bitmap.CacheOption  = BitmapCacheOption.OnLoad;
                    bitmap.EndInit();
                    bitmap.Freeze();
                    source.Source = bitmap;
                }
            }
        }
 private void getIconImage(MediaSingleElement tmpmedia, string extension)
 {
     if (!tmpmedia.Extension.Equals(".mp3"))
     {
         var ffMpeg = new NReco.VideoConverter.FFMpegConverter();
         using (MemoryStream sampleStream = new MemoryStream())
         {
             ffMpeg.GetVideoThumbnail(new Uri(tmpmedia.mediaUri).LocalPath, sampleStream, 2);
             sampleStream.Seek(0, SeekOrigin.Begin);
             var bitmapImage = new BitmapImage();
             bitmapImage.BeginInit();
             bitmapImage.CacheOption  = BitmapCacheOption.OnLoad;
             bitmapImage.StreamSource = sampleStream;
             bitmapImage.EndInit();
             tmpmedia.IconImage = bitmapImage;
         }
     }
     else
     {
         tmpmedia.IconImage = new BitmapImage(new Uri("pack://application:,,,/XMediaPlayer;component/Icons/mp3.png"));
     }
 }
Beispiel #9
0
 private void lbVideos_SelectedIndexChanged(object sender, EventArgs e)
 {
     try
     {
         string videofile = @"C:\\Users\\BePulverized\\Videos\\Recordings\\" + lbVideos.SelectedItem.ToString();
         var    ffmpeg    = new NReco.VideoConverter.FFMpegConverter();
         string thumbnail = @"C:\\Users\\BePulverized\\Videos\\Recordings\\" + lbVideos.SelectedItem.ToString() +
                            ".jpg";
         ffmpeg.GetVideoThumbnail(videofile, thumbnail, 20);
         pbThumbnail.ImageLocation = @"C:\\Users\\BePulverized\\Videos\\Recordings\\" +
                                     lbVideos.SelectedItem.ToString() + ".jpg";
         string date  = videofile.Substring(videofile.IndexOf('_') + 1);
         int    index = date.IndexOf(".");
         if (index > 0)
         {
             date = date.Substring(0, index);
         }
         lbRecorded.Text = "Recorded: " + date;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }