Example #1
0
 private static String GetVideoWriterInfo()
 {
     if (Emgu.Util.Platform.OperationSystem == Platform.OS.Windows)
     {
         try
         {
             using (VideoWriter writer = new VideoWriter(
                        "tmp.avi",
                        0,
                        VideoWriter.Fourcc('H', '2', '6', '3'),
                        30,
                        new Size(704, 576),
                        new Tuple <VideoWriter.WriterProperty, int>[]
             {
                 new Tuple <VideoWriter.WriterProperty, int>(VideoWriter.WriterProperty.IsColor, 1),
                 new Tuple <VideoWriter.WriterProperty, int>(VideoWriter.WriterProperty.HwAcceleration, (int)VideoAccelerationType.Any)
             }))
             {
                 VideoAccelerationType hwAcceleration =
                     (VideoAccelerationType)writer.Get(VideoWriter.WriterProperty.HwAcceleration);
                 return(String.Format("{0}Trying to create H263 video writer with default backend...{0}H263 VideoWriter successfully created with default backend: {1} (hw acceleration: {2})", System.Environment.NewLine, writer.BackendName, hwAcceleration));
             }
         }
         catch (Exception e)
         {
             //System.Console.WriteLine(e);
             return(Environment.NewLine + "Failed to create H263 VideoWriter with default backend.");
         }
     }
     return(String.Empty);
 }
        public void GetSetOption()
        {
            using var writer = new VideoWriter("dummy2.avi", FourCCValues.MJPG, 10, new Size(640, 480));
            Assert.True(writer.IsOpened());

            writer.Set(VideoWriterProperties.Quality, 50);
            Assert.Equal(50, writer.Get(VideoWriterProperties.Quality), 3);
        }
Example #3
0
        private static String GetVideoWriterFFMPEGInfo()
        {
            if (Emgu.Util.Platform.OperationSystem == Platform.OS.Windows)
            {
                Emgu.CV.Backend[] backends = CvInvoke.WriterBackends;
                int backend_idx = 0; //any backend;
                String backendName = String.Empty;
                foreach (Emgu.CV.Backend be in backends)
                {
                    if (be.Name.Equals("FFMPEG"))
                        //if (be.Name.Equals("INTEL_MFX"))
                    {
                        backend_idx = be.ID;
                        backendName = be.Name;
                        break;
                    }
                }

                if (backend_idx > 0) //FFMPEG backend is available
                {
                    try
                    {
                        using (VideoWriter writer = new VideoWriter(
                            "tmp.avi",
                            backend_idx,
                            VideoWriter.Fourcc('X', 'V', 'I', 'D'),
                            25,
                            new Size(640, 480),
                            new Tuple<VideoWriter.WriterProperty, int>[]
                            {
                                new Tuple<VideoWriter.WriterProperty, int>(VideoWriter.WriterProperty.IsColor, 1),
                                new Tuple<VideoWriter.WriterProperty, int>(VideoWriter.WriterProperty.HwAcceleration, (int) VideoAccelerationType.Any)
                            }))
                        {

                            VideoAccelerationType hwAcceleration =
                                (VideoAccelerationType)writer.Get(VideoWriter.WriterProperty.HwAcceleration);
                            return String.Format("{0}VideoWriter successfully created with backend: {1} (hw acceleration: {2})", System.Environment.NewLine, backendName, hwAcceleration);
                        }
                    }
                    catch (Exception e)
                    {
                        //System.Console.WriteLine(e);
                        return Environment.NewLine + "Failed to create VideoWriter with FFMPEG backend.";
                    }
                }
                else
                {
                    return Environment.NewLine + "FFMPEG backend not found.";
                }
            }

            return String.Empty;
        }
Example #4
0
        private static String GetVideoWriterFFMPEGInfo()
        {
            if (Emgu.Util.Platform.OperationSystem == Platform.OS.Windows)
            {
                Emgu.CV.Backend[] backends = CvInvoke.WriterBackends;
                int    backend_idx         = 0;//any backend;
                String backendName         = String.Empty;
                foreach (Emgu.CV.Backend be in backends)
                {
                    if (be.Name.Equals("FFMPEG"))
                    {
                        backend_idx = be.ID;
                        backendName = be.Name;
                        break;
                    }
                }

                if (backend_idx > 0) //FFMPEG backend is available
                {
                    try
                    {
                        //Environment.SetEnvironmentVariable("OPENCV_FFMPEG_WRITER_OPTIONS", "hw_encoders_any;cuda");
                        using (VideoWriter writer = new VideoWriter(
                                   "tmp.avi",
                                   backend_idx,
                                   VideoWriter.Fourcc('H', '2', '6', '3'), //VideoWriter.Fourcc('X', 'V', 'I', 'D'),
                                   25,
                                   new Size(704, 576),
                                   new Tuple <VideoWriter.WriterProperty, int>[]
                        {
                            new Tuple <VideoWriter.WriterProperty, int>(VideoWriter.WriterProperty.IsColor, 1),
                            new Tuple <VideoWriter.WriterProperty, int>(VideoWriter.WriterProperty.HwAcceleration, (int)VideoAccelerationType.Any)
                        }))
                        {
                            VideoAccelerationType hwAcceleration =
                                (VideoAccelerationType)writer.Get(VideoWriter.WriterProperty.HwAcceleration);
                            return(String.Format("{0}Trying to create H263 video writer with FFMPEG backend...{0}H263 VideoWriter successfully created with backend: {1} (hw acceleration: {2})", System.Environment.NewLine, backendName, hwAcceleration));
                        }
                    }
                    catch (Exception e)
                    {
                        //System.Console.WriteLine(e);
                        return(Environment.NewLine + "Failed to create H263 VideoWriter with FFMPEG backend.");
                    }
                }
                else
                {
                    return(Environment.NewLine + "FFMPEG backend not found.");
                }
            }

            return(String.Empty);
        }
Example #5
0
        private static String GetVideoWriterMSMFInfo()
        {
            if (Emgu.Util.Platform.OperationSystem == Platform.OS.Windows)
            {
                Emgu.CV.Backend[] backends = CvInvoke.WriterBackends;
                int    backend_idx         = 0;//any backend;
                String backendName         = String.Empty;
                foreach (Emgu.CV.Backend be in backends)
                {
                    if (be.Name.Equals("MSMF"))
                    {
                        backend_idx = be.ID;
                        backendName = be.Name;
                        break;
                    }
                }

                if (backend_idx > 0) //MSMF backend is available
                {
                    try
                    {
                        using (VideoWriter writer = new VideoWriter(
                                   "tmp.mp4",
                                   backend_idx,
                                   VideoWriter.Fourcc('H', '2', '6', '4'),
                                   30,
                                   new Size(640, 480),
                                   new Tuple <VideoWriter.WriterProperty, int>[]
                        {
                            new Tuple <VideoWriter.WriterProperty, int>(VideoWriter.WriterProperty.IsColor, 1),
                            new Tuple <VideoWriter.WriterProperty, int>(VideoWriter.WriterProperty.HwAcceleration, (int)VideoAccelerationType.Any)
                        }))
                        {
                            VideoAccelerationType hwAcceleration =
                                (VideoAccelerationType)writer.Get(VideoWriter.WriterProperty.HwAcceleration);
                            return(String.Format("{0}Trying to create H264 video writer with MSMF backend...{0}H264 VideoWriter successfully created with backend: {1} (hw acceleration: {2})", System.Environment.NewLine, backendName, hwAcceleration));
                        }
                    }
                    catch (Exception e)
                    {
                        //System.Console.WriteLine(e);
                        return(Environment.NewLine + "Failed to create H264 VideoWriter with MSMF backend.");
                    }
                }
                else
                {
                    return(Environment.NewLine + "MSMF backend not found.");
                }
            }
            return(String.Empty);
        }
Example #6
0
        public void GetSetOption()
        {
            const string fileName = "dummy2.avi";

            try
            {
                using var writer = new VideoWriter(fileName, VideoCaptureAPIs.OPENCV_MJPEG, FourCC.MJPG, 10, new Size(640, 480));
                Assert.True(writer.IsOpened());
                Assert.Equal("CV_MJPEG", writer.GetBackendName());

                Assert.True(writer.Set(VideoWriterProperties.Quality, 50), "VideoWriter.Set failed");
                Assert.Equal(50, writer.Get(VideoWriterProperties.Quality), 3);
            }
            finally
            {
                DeleteFile(fileName);
            }
        }
Example #7
0
        private static String GetCaptureInfo()
        {
            String captureText = String.Format("Capture Backends (VideoCapture from device): {0}{1}", System.Environment.NewLine, GetBackendInfo(CvInvoke.Backends));

            //We don't want to create VideoCapture on Mac OS unless we have requested camera permission
            if (Emgu.Util.Platform.OperationSystem != Platform.OS.MacOS)
            {
                using (VideoCapture cap = new VideoCapture(0, VideoCapture.API.Any,
                                                           new Tuple <CapProp, int>(CapProp.HwAcceleration, (int)VideoAccelerationType.Any)))
                {
                    if (cap.IsOpened)
                    {
                        String backendName = cap.BackendName;
                        VideoAccelerationType hwAcceleration = (VideoAccelerationType)cap.Get(CapProp.HwAcceleration);
                        captureText +=
                            String.Format(
                                "{0}VideoCapture device successfully opened with default backend: {1} (hw acceleration: {2})",
                                System.Environment.NewLine, backendName, hwAcceleration);
                    }
                }
            }
            captureText += String.Format("{0}{0}Stream Backends (VideoCapture from file/Stream): {0}{1}", System.Environment.NewLine, GetBackendInfo(CvInvoke.StreamBackends));

            captureText += String.Format("{0}{0}VideoWriter backends: {0}{1}{0}", Environment.NewLine,
                                         GetBackendInfo(CvInvoke.WriterBackends));

            if (Emgu.Util.Platform.OperationSystem == Platform.OS.Windows)
            {
                Emgu.CV.Backend[] backends = CvInvoke.WriterBackends;
                int    backend_idx         = 0;//any backend;
                String backendName         = String.Empty;
                foreach (Emgu.CV.Backend be in backends)
                {
                    if (be.Name.Equals("FFMPEG"))
                    //if (be.Name.Equals("INTEL_MFX"))
                    {
                        backend_idx = be.ID;
                        backendName = be.Name;
                        break;
                    }
                }

                if (backend_idx > 0) //FFMPEG backend is available
                {
                    using (VideoWriter writer = new VideoWriter(
                               "tmp.avi",
                               backend_idx,
                               VideoWriter.Fourcc('X', 'V', 'I', 'D'),
                               25,
                               new Size(640, 480),
                               new Tuple <VideoWriter.WriterProperty, int>[]
                    {
                        new Tuple <VideoWriter.WriterProperty, int>(VideoWriter.WriterProperty.IsColor, 1),
                        new Tuple <VideoWriter.WriterProperty, int>(VideoWriter.WriterProperty.HwAcceleration, (int)VideoAccelerationType.Any)
                    }))
                    {
                        VideoAccelerationType hwAcceleration =
                            (VideoAccelerationType)writer.Get(VideoWriter.WriterProperty.HwAcceleration);
                        captureText += String.Format("{0}VideoWriter successfully created with backend: {1} (hw acceleration: {2})", System.Environment.NewLine, backendName, hwAcceleration);
                    }
                }
            }


            return(captureText);
        }