Example #1
0
        private void SaveAviHelper(AviType aviType, ref List <ManagedImage> imageList, string aviFileName, float frameRate)
        {
            // Set maximum AVI file size to 2GB. A new AVI file is generated when 2GB
            // limit is reached. Setting maximum file size to 0 indicates no limit.
            const uint AviMaxSize = 2048;

            using (ManagedAVIRecorder aviRecorder = new ManagedAVIRecorder())
            {
                aviRecorder.SetMaximumAVISize(AviMaxSize);

                switch (aviType)
                {
                case AviType.Uncompressed:
                {
                    AviOption option = new AviOption();
                    option.frameRate = frameRate;
                    aviRecorder.AVIOpen(aviFileName, option);
                }
                break;

                case AviType.Mjpg:
                {
                    MJPGOption option = new MJPGOption();
                    option.frameRate = frameRate;
                    option.quality   = 75;
                    aviRecorder.AVIOpen(aviFileName, option);
                }
                break;

                case AviType.H264:
                {
                    H264Option option = new H264Option();
                    option.frameRate = frameRate;
                    option.bitrate   = 1000000;
                    option.height    = Convert.ToInt32(imageList[0].rows);
                    option.width     = Convert.ToInt32(imageList[0].cols);
                    aviRecorder.AVIOpen(aviFileName, option);
                }
                break;
                }

                Console.WriteLine("Appending {0} images to AVI file {1}...", imageList.Count, aviFileName);

                for (int imageCnt = 0; imageCnt < imageList.Count; imageCnt++)
                {
                    // Append the image to AVI file
                    aviRecorder.AVIAppend(imageList[imageCnt]);

                    Console.WriteLine("Appended image {0}", imageCnt);
                }

                aviRecorder.AVIClose();
            }
        }
Example #2
0
        private void SaveAviHelper(AviType aviType, ref List <ManagedImage> imageList, string aviFileName, float frameRate)
        {
            using (ManagedAVIRecorder aviRecorder = new ManagedAVIRecorder())
            {
                switch (aviType)
                {
                case AviType.Uncompressed:
                {
                    AviOption option = new AviOption();
                    option.frameRate = frameRate;
                    aviRecorder.AVIOpen(aviFileName, option);
                }
                break;

                case AviType.Mjpg:
                {
                    MJPGOption option = new MJPGOption();
                    option.frameRate = frameRate;
                    option.quality   = 75;
                    aviRecorder.AVIOpen(aviFileName, option);
                }
                break;

                case AviType.H264:
                {
                    H264Option option = new H264Option();
                    option.frameRate = frameRate;
                    option.bitrate   = 1000000;
                    option.height    = Convert.ToInt32(imageList[0].rows);
                    option.width     = Convert.ToInt32(imageList[0].cols);
                    aviRecorder.AVIOpen(aviFileName, option);
                }
                break;
                }

                Console.WriteLine("Appending {0} images to AVI file {1}...", imageList.Count, aviFileName);

                for (int imageCnt = 0; imageCnt < imageList.Count; imageCnt++)
                {
                    // Append the image to AVI file
                    aviRecorder.AVIAppend(imageList[imageCnt]);

                    Console.WriteLine("Appended image {0}", imageCnt);
                }

                aviRecorder.AVIClose();
            }
        }
Example #3
0
        // This function prepares, saves, and cleans up an video from a list of images.
        int SaveListToVideo(INodeMap nodeMap, INodeMap nodeMapTLDevice, ref List <IManagedImage> images)
        {
            int result = 0;

            Console.WriteLine("\n\n*** CREATING VIDEO ***\n");

            try {
                // Retrieve device serial number for filename
                String deviceSerialNumber = "";

                IString iDeviceSerialNumber = nodeMapTLDevice.GetNode <IString>("DeviceSerialNumber");
                if (iDeviceSerialNumber != null && iDeviceSerialNumber.IsReadable)
                {
                    deviceSerialNumber = iDeviceSerialNumber.Value;

                    Console.WriteLine("Device serial number retrieved as {0}...", deviceSerialNumber);
                }

                //
                // Retrieve the current frame rate; acquisition frame rate recorded in hertz
                //
                // *** NOTES ***
                // The video frame rate can be set to anything; however, in
                // order to have videos play in real-time, the acquisition frame
                // rate can be retrieved from the camera.
                //
                IFloat iAcquisitionFrameRate = nodeMap.GetNode <IFloat>("AcquisitionFrameRate");
                if (iAcquisitionFrameRate == null || !iAcquisitionFrameRate.IsReadable)
                {
                    Console.WriteLine("Unable to retrieve frame rate. Aborting...\n");
                    return(-1);
                }

                float frameRateToSet = (float)iAcquisitionFrameRate.Value;

                Console.WriteLine("Frame rate to be set to {0}", frameRateToSet);

                //
                // Create a unique filename
                //
                // *** NOTES ***
                // This example creates filenames according to the type of
                // video being created. Notice that '.avi' does not need to be
                // appended to the name of the file. This is because the video
                // recorder object takes care of the file extension
                // automatically.
                //
                string videoFilename;

                switch (chosenFileType)
                {
                case VideoType.Uncompressed:
                    videoFilename = "SaveToAvi-CSharp-Uncompressed";
                    if (deviceSerialNumber != "")
                    {
                        videoFilename = videoFilename + "-" + deviceSerialNumber;
                    }
                    break;

                case VideoType.Mjpg:
                    videoFilename = "SaveToAvi-CSharp-MJPG";
                    if (deviceSerialNumber != "")
                    {
                        videoFilename = videoFilename + "-" + deviceSerialNumber;
                    }
                    break;

                case VideoType.H264:
                    videoFilename = "SaveToAvi-CSharp-H264";
                    if (deviceSerialNumber != "")
                    {
                        videoFilename = videoFilename + "-" + deviceSerialNumber;
                    }
                    break;

                default:
                    videoFilename = "SaveToAvi-CSharp";
                    break;
                }

                //
                // Select option and open video file type
                //
                // *** NOTES ***
                // Depending on the filetype, a number of settings need to be
                // set in an object called an option. An uncompressed option
                // only needs to have the video frame rate set whereas videos
                // with MJPG or H264 compressions should have more values set.
                //
                // Once the desired option object is configured, open the video
                // file with the option in order to create the image file.
                //
                // *** LATER ***
                // Once all images have been added, it is important to close the
                // file - this is similar to many other standard file streams.
                //
                using (IManagedSpinVideo video = new ManagedSpinVideo()) {
                    // Set maximum video file size to 2GB. A new video file is generated when 2GB
                    // limit is reached. Setting maximum file size to 0 indicates no limit.
                    const uint FileMaxSize = 2048;

                    video.SetMaximumFileSize(FileMaxSize);

                    switch (chosenFileType)
                    {
                    case VideoType.Uncompressed:
                        AviOption uncompressedOption = new AviOption();
                        uncompressedOption.frameRate = frameRateToSet;
                        video.Open(videoFilename, uncompressedOption);
                        break;

                    case VideoType.Mjpg:
                        MJPGOption mjpgOption = new MJPGOption();
                        mjpgOption.frameRate = frameRateToSet;
                        mjpgOption.quality   = 75;
                        video.Open(videoFilename, mjpgOption);
                        break;

                    case VideoType.H264:
                        H264Option h264Option = new H264Option();
                        h264Option.frameRate = frameRateToSet;
                        h264Option.bitrate   = 1000000;
                        h264Option.height    = Convert.ToInt32(images[0].Height);
                        h264Option.width     = Convert.ToInt32(images[0].Width);
                        video.Open(videoFilename, h264Option);
                        break;
                    }

                    //
                    // Construct and save video
                    //
                    // *** NOTES ***
                    // Although the video file has been opened, images must be
                    // individually appended in order to construct the video.
                    //
                    Console.WriteLine("Appending {0} images to video file {1}.avi...", images.Count, videoFilename);

                    for (int imageCnt = 0; imageCnt < images.Count; imageCnt++)
                    {
                        video.Append(images[imageCnt]);

                        Console.WriteLine("Appended image {0}...", imageCnt);
                    }
                    Console.WriteLine();

                    //
                    // Close video file
                    //
                    // *** NOTES ***
                    // Once all images have been appended, it is important to
                    // close the video file. Notice that once an video file has
                    // been closed, no more images can be added.
                    //
                    video.Close();
                }
            } catch (SpinnakerException ex) {
                Console.WriteLine("Error: {0}", ex.Message);
                result = -1;
            }

            return(result);
        }