Skip to content

Preroll recording (Backtimed recording)

The file can be recorded with a back-timed number of video frames (pre-roll). This feature is activated by specifying a RecordingBacktimedFramesCount value greater than 0.

This feature is useful when the recording is started by an event (e.g. motion detected, see the motion detection features) and the recording of the AVI file must start a few moments before this event occurs, to include the few moments preceding it: the recording is shifted back in time and starts at the "current - n" video frame.

When RecordingBacktimedFramesCount has a value greater than 0, TVideoGrabber uses a FIFO (first in, first out) memory buffer to store the latest video frames.

When the recording starts, the video frames are streamed normally until the buffer is full. Then the OnBacktimedFramesCountReached event occurs, to indicate that the current video frames are now replaced by back-timed video frames.

When StopRecording is invoked, the recording stops "as is": the latest video frames in the buffer are missing (only the back-timed frames are recorded), unless the recording is stopped at the desired time plus the delay corresponding to the frames in the buffer.

Note

Be careful when assigning a number of frames to RecordingBacktimedFramesCount, because a corresponding buffer of video frames is created in memory during recording. E.g. 100 frames in 320 x 240 x 24-bit = 320 x 240 x 3 x 100 = 22,500 KB = 22 MB of memory required during recording.

Requirements

Implementation

  • To preview the back-timed video stream, set FrameGrabber = fg_BothStreams. To preview the normal video stream, set FrameGrabber = fg_CaptureStream.
  • Set RecordingInNativeFormat = false.
  • Set HoldRecording to true, to start the recording in preview mode and hold the AVI writing.
  • Invoke StartRecording to put the recording in preview mode and start filling the buffer.
  • When the OnBacktimedFramesCountReached event occurs, the buffer is full: from this moment, back-timed video frames start replacing normal video frames in the captured stream.
  • Then invoke ResumeRecording to really start the AVI recording.

Quick test code:

procedure TForm1.BtnPrepareRecordingClick(Sender: TObject);
begin
  VideoGrabber.OnRecordingReadyToStart:= nil;
  VideoGrabber.FrameGrabber:= fg_BothStreams;
  VideoGrabber.FrameRate:= 10; // 10 fps
  VideoGrabber.RecordingBacktimedFramesCount:= 30; // 30 frames = e.g. 3 seconds at 10 fps or 1 second at 30 fps
  VideoGrabber.RecordingInNativeFormat:= False;
  VideoGrabber.HoldRecording:= True;
  VideoGrabber.StartRecording;
end;

procedure TForm1.BtnStartRecordingClick(Sender: TObject); // wait for the buffer to fill (e.g. 3 seconds) before clicking
begin
  VideoGrabber.ResumeRecording;
end;

procedure TForm1.BtnStopRecordingClick(Sender: TObject);
begin
  VideoGrabber.StopRecording;
end;