Skip to content

Recording

Invoke e.g.:

DatasteadRTSPSourceConfig.SetStr(RTSP_Source_RecordingFileName_str, "c:\folder\filename.mp4")

before opening the URL.

The extension of the file name determines the format of the video clip (mp4, flv, mov, avi, mkv...).

The filter records the native frames received (H264, H265/HEVC, AAC, etc...) without transcoding by default. If a new file name is specified during the recording, it closes the previous file and opens the new file without losing frames between the 2 files.

Generating a new file on the fly

To generate a new file name during the recording, invoke, e.g.:

DatasteadRtspSourceConfig.Action(RTSP_Action_RecordToNewFileNow, "c:\folder\newfilename3.mp4");

To pause the recording, pass a "nul" file name with the same extension:

DatasteadRtspSourceConfig.Action(RTSP_Action_RecordToNewFileNow, "nul.mp4");

Starting the recording in "ready to record" mode (not writing immediately to the file)

To start the recording but not write immediately to the file (e.g. to record in .mp4), set nul.mp4 (without path) as recording file name:

DatasteadRTSPConfigHelper.SetStr(RTSP_Source_RecordingFileName_str, "nul.mp4")

Then run the graph.

While the graph is running (therefore only previewing), when it's time to begin writing to the file, invoke Action(RTSP_Action_RecordToNewFileNow) with the real file name to use:

DatasteadRTSPConfigHelper.Action(RTSP_Action_RecordToNewFileNow, "c:\myfolder\myrealfilename.mp4")

Pausing/resuming the recording

To pause the recording of the current file, while the preview keeps running:

DatasteadRtspSourceConfig.Action (RTSP_Action_PauseRecording, "");

To resume the recording:

DatasteadRtspSourceConfig.Action (RTSP_Action_ResumeRecording, "");

Synchronizing the beginning of the recording with the first frames displayed

By default the recording starts immediately while the filter is analyzing the streams and buffering, so the beginning of the recording may be usually 1 or 2 seconds before the first frames displayed.

To start the recording with the first frames displayed, enable RTSP_VideoStream_Sync_Start_Recording_bool (or add >syncstart=1 at the end of the URL).

Starting the recording synchronized implies to recompress the video stream. By default the video stream is recompressed with the same codec, however it is possible to specify a different codec with RTSP_VideoEncoder_Codec_str (or by adding e.g. >vcodec=hevc at the end of the URL).

It is possible to recompress through the GPU by setting RTSP_VideoStream_GPUEncoder_int (or by adding >gpuenc=n at the end of the URL).

Backtimed recording (pre-roll recording)

It is possible to specify a number of seconds that must be included at the beginning of the recording, BEFORE the "start recording" action was invoked.

This is designed to additionally include in the video clip the few seconds of video just before the user decided to start the recording.

To use this feature the filter must be configured with the recording in a "paused" mode by invoking (e.g. for an additional pre-roll duration of 5 seconds):

DatasteadRTSPSourceConfig.SetStr(RTSP_Source_RecordingFileName_str, "c:\folder\filename.mp4")
DatasteadRTSPSourceConfig.Action(RTSP_Action_PauseRecording, "")
DatasteadRTSPSourceConfig.SetInt (RTSP_Source_RecordingBacktimedStartSeconds_int, 5)

Then run the graph, so the filter is for now previewing and ready to record.

While the graph is running, when it's time to start the recording, you can invoke:

DatasteadRTSPSourceConfig.Action(RTSP_Action_ResumeRecording, "")

to start writing to the file previously specified by RTSP_Source_RecordingFileName_str.

When the graph is stopped, the clip will contain the duration of the recording plus, at the beginning, the specified number of seconds of pre-roll.

Note: to pause the recording in order to resume later to a different file name, invoke:

DatasteadRTSPSourceConfig.Action(RTSP_Action_RecordToNewFileNow, "nul.mp4")

(nul.mp4 is a reserved keyword that tells the filter to close the current recording and prepare the next one)

then to resume the recording to the different file name, invoke:

DatasteadRTSPSourceConfig.Action(RTSP_Action_RecordToNewFileNow, "c:\folder\thenewfilename.mp4")

File writer callback

A callback mechanism lets receive the bytes being written to the recording file.

This can be useful:

  1. to re-stream the video data being recorded — in this case it is necessary to record to a streamable video format: .ts file for video or audio/video, or .h264 for H264 video only,
  2. to write the file being recorded to a 2nd path at the same time.

The sample code is included in the "OpenURLForm.cs" of the demo project, search for "set to true to enable the file writer callback".