Skip to main content

Getting Started with TS Stream Recorder

To start recording with the TS Stream Recorder SDK, add a reference to TSRecorderWr.dll and include the TSRecorderWr namespace.

using TSRecorderWr;

// Create an instance of TSRecorderWr
CTSRecorderWr m_TsRecorder = new CTSRecorderWr(0, "Recorder-1");

// Set up events
m_TsRecorder.RecorderEvent += new NotifyRecorderEvent(recorder_RecorderEvent);
m_TsRecorder.ErrorEvent += new NotifyError(recorder_ErrorEvent);

// Configure the network source
NetSourcePropsWr netSrc = new NetSourcePropsWr();
netSrc.IP = "227.1.1.1";
netSrc.Port = 1234;

// Configure the target
FileTargetPropsWr fileTrg = new FileTargetPropsWr();
fileTrg.Dir = @"C:\Movie\";
fileTrg.BaseName = "Test.ts";
fileTrg.SegmentationType = FileSegmentationTypeWr.SegmentationType_Duration;
fileTrg.SegmentDuration = TimeSpan.FromSeconds(10);
fileTrg.GopAlignedSegmentation = true;

// Initialize recorder
m_TsRecorder.Init(netSrc, fileTrg);

// Start recording
m_TsRecorder.Start();

// Handle events
void recorder_ErrorEvent(Error_Type e, string err, object context)
{
Console.WriteLine(string.Format("{0}: Error Event: {1} - {2}", DateTime.Now, e.ToString(), err));
}

void recorder_RecorderEvent(Recorder_Event ev, string info, long param, object context)
{
Console.WriteLine(string.Format("{0}: Rec Event: {1} - {2} ({3})", DateTime.Now, ev.ToString(), info, param));
}

Segment Naming

The recorder does not write directly to BaseName.

Instead, it generates the output file name from the base name stem, the current segment index, and a local timestamp:

<stem>_<index>_<YYYY>_<MM>_<DD>_<HH>_<MM>_<SS><extension>

Example:

BaseName: Test.ts
Generated file: Test_0_2026_03_25_14_07_11.ts

This applies even when segmentation is disabled, so a single recorded file still receives the index and timestamp suffix.

For the full naming rules, see Recorder Segment Naming Convention.

Summary

  1. Create a recorder instance.
  2. Attach recorder and error event handlers.
  3. Configure the UDP source.
  4. Configure the output directory, base filename, and segmentation mode.
  5. Initialize the recorder.
  6. Start recording and handle events.