| Cinema software |
Source code & API

Multicast UDP recorder

Library that captures high bandwidth MPEG-TS or MPEG-TS over (RTP/HTTP) to a file.

I wrote this small library because I couldn't capture high bandwidth multicast traffic in a C# application without packet loss.

If some packets are still dropped, use function SetBuffers(UINT ChunkSize, UINT MaxRecvBuf) and set higher MaxRecvBuf and optionally higher ChunkSize. MaxRecvBuf is a socket buffer (hardware buffer) and it's default size is 5264000 bytes.
Defualt size of ChunkSize is 65800 bytes.

In current version RTP headers are just stripped and packets are not reordered !

Download Multicast Recorder Dll 0.98.6

Older releases

Download Multicast Recorder Dll 0.98.5
Download Multicast Recorder Dll 0.98.0

Example of using this library in a C# application:

 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using MulticastRecorderLib;
using System.Runtime.InteropServices;
using System.Net;

namespace MulticastRecorderExample2
{
    class Program
    {
        static void Main(string[] args)
        {
            MulticastRecorder recorder = new MulticastRecorder();
            IMulticastRecorder recInterface = (IMulticastRecorder) recorder;
            IPAddress multIp = IPAddress.Parse("232.4.201.1");
            IPAddress nicIp = IPAddress.Any;
            uint nicIndex = 0XFFFFFFFF; // If index is 0xffffffff, appropriate NIC will be determined only by the ipv4 address.
            ushort port = 5003;
            
            // Set multicast related data.
            recInterface.SetMulticastGroup(BitConverter.ToUInt32(multIp.GetAddressBytes(), 0),port,BitConverter.ToUInt32(nicIp.GetAddressBytes(), 0),nicIndex);
            
            // Set capture file.
            recInterface.SetCaptureFile("test.mpg.ts");
            
            // Set recording length and handle of this form.
            recInterface.SetRecordingLength(10, IntPtr.Zero); // It is a console application, so no window handle.

            // Set id. If you set recording time greater than 0, object sends a message with this id when it stops 
            //recording. Application can receive that message by overriding WndProc.
            recInterface.SetId(0);

            // Start recording.
            recInterface.Start();

            Thread.Sleep(11000);
            
			// Stop recording.
            recInterface.Stop(); 
			
			// Clean.
            Marshal.ReleaseComObject(recInterface); 
            recInterface = null;
            Marshal.ReleaseComObject(recorder);
            recorder = null;
        }
    }
}

Example of using this library in a C++ application:

//#include "stdafx.h"
#include <tchar.h>
#include <stdio.h>
#include "IMulticastRecorder_h.h"
#include "IMulticastRecorder_i.c"
#include <comip.h> 

int _tmain(int argc, TCHAR* argv[])
{
	CoInitializeEx(NULL,COINIT_APARTMENTTHREADED);

	_com_ptr_t<_com_IIID<IMulticastRecorder,&IID_IMulticastRecorder>> pRec;  // Smart pointer to IMulticastRecorder.
	 CoCreateInstance(CLSID_MulticastRecorder, NULL, CLSCTX_INPROC_SERVER, IID_IMulticastRecorder, reinterpret_cast<void**> (&pRec));
	 
	 char mip[16];
	 char nicip[16];
	 TCHAR file[261];
	 USHORT port =5002;        // Listen on port 5002
	
	 strcpy(mip,"232.4.1.1");  // Multicast address to capture.
	 strcpy(nicip, "0.0.0.0"); // Any ip address.
	 _tcscpy_s(file,_countof( file),L"testing.mpg\0");

	 pRec->SetMulticastGroup(inet_addr(mip),port,inet_addr(nicip),0XFFFFFFFF); // If index is 0xffffffff, appropriate NIC will be determined only by the ipv4 address.
	 pRec->SetCaptureFile(file);
	 pRec->Start();

	 SleepEx(10000,TRUE);

	 // Stop recording after 10s.
	 pRec->Stop();

	 pRec = NULL;

	 CoUninitialize();

	return 0;
}