Maybe someone could help with the following problem. I need to write a viewer for Basler Usb cameras which will be able to write video to avi file using the selected codec. I'm using pylon sdk for creating application. And I faced the following problem - AviWriter object provided by pylon libraries doesn't write frames to avi file as effective as standard pylon viewer does. For testing I have chosen the following code sample which has been provided with pylon SDK:

    internal static void Main()
    {

        int exitCode = 0;
        int counter = 0;

        try
        {

            using (Camera camera = new Camera())
            {

                camera.Open();

                camera.Parameters[PLCameraInstance.MaxNumBuffer].SetValue(1000);


                using (AviVideoWriter writer = new AviVideoWriter())
                {


                    byte[] ar = { };
                    writer.Create("test.avi", 35, PixelType.BGR8packed, 1280, 960, ImageOrientation.BottomUp, "msvc", 100, 0, 1, ref ar, true, (IntPtr)null);


                    camera.StreamGrabber.Start(1000); //1000 frames are to be grabbed

                    Console.WriteLine("Please wait. Images are being grabbed.");

                    while (camera.StreamGrabber.IsGrabbing)
                    {

                        IGrabResult grabResult = camera.StreamGrabber.RetrieveResult(5000, TimeoutHandling.ThrowException);


                        if (grabResult.GrabSucceeded)
                        {

                            ++counter;
                            writer.Write(grabResult);
                            Console.WriteLine("------->images written" + counter); 
                            Console.WriteLine("------->empty buffers" + camera.Parameters[PLCameraInstance.NumEmptyBuffers].GetValue()); //how many empty buffers left
                            grabResult.Dispose();
                        }
                        else
                        {
                            Console.WriteLine("Error: {0} {1}", grabResult.ErrorCode, grabResult.ErrorDescription);
                        }
                    }


                    camera.StreamGrabber.Stop();


                    writer.Close();
                }


                camera.Close();
            }
        }
        catch (Exception e)
        {
            Console.Error.WriteLine("Exception: {0}", e.Message);
            exitCode = 1;
        }
        finally
        {

            Console.Error.WriteLine("\nPress enter to exit.");
            Console.ReadLine();
        }

        Environment.Exit(exitCode);
    }

The problem is the following. Under otherwise equal conditions (codec, resolution) the standard pylon application writes frames into avi file 1.5-2 times more effective then AviWriter in the sample. I mean in case of standard pylon application camera can write without filling buffer at all camera buffer in the example will be filled quite quickly. My question is are there any ways to speed up adding frames into avi file using AviWriter object from pylon SDK? Maybe someone faced this problem and resolved it somehow? By the way I have tested C++ sample code also and the problem remains.

0 Answers