I have a WPF app where I need to handle DHAV (.dav)
video stream on runtime from a Digital Video Recorder (DVR)
. I'm using an SDK that can be found here Dahua SDK search
SDK: General_NetSDK_Eng_Win64_IS_V3.052.0000002.0.R.201103
I need to handle every single frame from the video stream, convert it to a BitmapImage
and then displays it in a WPF Image control
. Something like: MJPEG Decoder
The problem is that I can't find any documentation on how to handle that data and the samples from the SDK doesn't show that either, instead they are built with WinForms and they only pass the Window Handle of the PictureBox's control to an exported DLL function and 'magically' shows the video stream:
[DllImport(LIBRARYNETSDK)]
public static extern IntPtr CLIENT_RealPlayEx(IntPtr lLoginID, int nChannelID, IntPtr hWnd, EM_RealPlayType rType);
OBS: 'hWnd' param is the Window Handle to display the video in.
The problem with this approach is that I don't have any control over the video stream.
I have tried many FFMPEG wrappers for .NET but they only parse the data if I first write it to disk and only then I can convert it to some type I can handle.
This is the callback function that is called contantly during the application's runtime with the data I need to handle:
private void RealDataCallback(IntPtr lRealHandle, uint dwDataType, IntPtr pBuffer, uint dwBufSize, IntPtr param, IntPtr dwUser)
{
switch (dwDataType)
{
case 0: // original data
break;
case 1: // frame data
HandleFrameData(lRealHandle, dwDataType, pBuffer, dwBufSize, param, dwUser);
break;
case 2: // yuv data
break;
case 3: // pcm audio data
break;
}
}
private void HandleFrameData(IntPtr lRealHandle, uint dwDataType, IntPtr pBuffer, uint dwBufSize, IntPtr param, IntPtr dwUser)
{
// The pBuffer parameter format is DHAV (.dav)
byte[] buff = new byte[dwBufSize];
Marshal.Copy(pBuffer, buff, 0, (int)dwBufSize);
using (var ms = new MemoryStream(buff))
{
}
}
UPDATE
I'm able to convert the YUV data provided in the callback funcion to RGB but that is not the ideal solution. It would be so much better (and faster) if I can convert the original (.dav) data.
The RealDataCallback
, in fact, only returns 1 frame per callback, but I don't know how to convert that frame to Bitmap. Any help would be appreciated.