Tutorial 3 – Simple AVI Export

Requirements:
Tutorial 2 – Getting Camera Information


From the previous tutorial, we left off with the ability to get information about cameras in the system.

In this tutorial we’ll actually export an AVI from them.

First, add the following Reference to your .NET application from the SDK folder:

  • AxHeimdallLib.dll

Also, add the following system References to your .NET application:

  • System.Windows.Forms

The main component that we’ll be dealing with throughout this tutorial is AxAuga. AxAuga is the streaming/transcoding/exporting part of the SDK. It actually has quite a bit of functionality, but in this tutorial, we’ll focus on its ability to export video.

First off, we need to create an instance of AxAuga:

AxAuga is an ActiveX Control that can be used as a Control for a Windows Form. So, the next step will be to create a Windows Form for the AxAuga Control to be hosted in:

This Windows Form will be hidden and used for its Window Handle as well as its Windows message pump integration. Here’s how we’ll hide the initial display of the Form:

Now that we have a Form and a Control, let’s do some setup once the Form’s Shown event is fired. It’s important to note that all exporting work with an AxAuga instance must be done after calling Application.Run as we’ll see later. Here’s the AxAuga initialization code during Shown:

On Shown we add the AxAuga instance as a Control to the video Form. This makes it so AxAuga is included to receive Windows messages. Then we call Init on the AxAuga instance to set timer hooks into the Form’s Window message loop as well as set it up for exporting. Init takes one argument, which is the monitor ID, to display on for rendering. In our case, we’ll give it an empty string because we will not be using AxAuga for display.

Now that we have added the Control and Init’d it, let’s setup connection to the NVR, which is associated with a camera. To export, AxAuga must be connected directly to the NVR:

OCCamera’s GetDynamicLiveURL will initiate a connection to the associated NVR and will return a valid URL when that connection has been made; so we wait until it’s non-null before continuing.

Once we have streaming privileges, we need to give AxAuga the privileges to stream, like so:

SetCameraIDispatch takes the ID of the camera, and the camera’s IDispatch interface. This gives AxAuga direct access to the camera for privileges to stream.

After we establish a connection to the NVR that we’ll export from, let’s start the export:

AxAuga’s StartAVIExport method takes the following: a video URL to export from, an unused meta data string, a audio URL to export audio from, an integer representing , a preamble string that will be inserted into each encoded video frame, a bool indicating whether to embed the timestamp into the AVI, a bool indicated whether to embed the camera name into the AVI, the filename to place the AVI, the year, month, day, hour, minute, second, millisecond start and stop times ( all in UTC ), a rectangular crop area defined by left, top, right, and bottom to crop the exported AVIs and a quality parameter with 0 representing the lowest quality and 10000 representing the highest quality.

At the end of the Shown event handler:

Setting the Visible property of the Form to false makes sure that the Form won’t be shown.

We’ve done everything that needs to be done during the Form Shown. During Form Closing we need to do some cleanup so that we don’t leak AxAuga’s resources:

When the Closing event is sent to the Form we call AxAuga’s Shutdown method on the instance. Shutdown frees all of the resources we needed to stream and export the video.

The final thing to do is to run our Form:

Screenshots of the final program:
Series-4-Tutorial-3-1
Series-4-Tutorial-3-2

That’s about it, so now we can export AVIs for a video segment.


Next:
Tutorial 4 – AVI Export Status