Preroll recording (Backtimed recording)

Prev

Next

 






































































































Pre-roll recording (starting with a back-timed delay)

Description

Preroll recording

It is possible to record the file with a back-timed amount of video frames (pre-roll). This property 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) and you want to start the recording ofthe AVI file a few moments before this event occurs.
When RecordingBacktimedFramesCount has a value > 0, TVideoGrabber uses a FIFO (first in, first out) memory buffer to store the latest video frames.

This property can be used e.g. with the motion detection features. When a motion is detected and the recording starts, this property allows you to have at the beginning of the recording the few moments before the motion detection event occurs.
By this way recording is shifted back in time and starts at the "current - n" video frame.

When starting the recording, the normal video frames are streamed "normally" until the buffer is filled out. Then, when the buffer is filled out, the OnBacktimedFrameCountReached event occurs to let you know that now current video frames are replaced by back-timed video frames..

Note that when invoking StopRecording the recording stops "as is", this means that the latest video frames in the buffer will be missing (only the backtimed frames are recorded), unless you stop the recording at the desired time + the delay corresponding to the frames in the buffer.

Note: be careful when assigning a number of frames to this property, this means that a corresponding buffer of video frames will be created in memory during recording.
E.g. 100 frames in 320 x 240 x 24 bits = 320 x 240 x 3 x 100 = 22,500 Kb = 22 Mb of memory required during recording.

Requirements
- the Frame grabber must be set to fg_BothStreams
- the RecordingInNativeFormat must be disabled.
- the RecordingMethod must be set to rm_AVI.

Implementation
- to preview the back-timed video stream, set FrameGrabber = fg_BothStream. If you prefer to preview the normal video stream, set FrameGrabber = fg_CaptureStream.
- set RecordingInNativeFormat = false,
- set HoldRecording to true to start recording in preview mode and hold AVI writing,
- call StartRecording to put the recording in preview mode and start to fill the buffer,
- when the OnBacktimedFrameCountReached event occurs (1), the buffer is filled out
- then invoke ResumeRecording to really start the AVI recording.

(1) when this event occurs, back-timed video frames start replacing normal video frames in the captured stream.

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 fillout (e.g. 3 seconds) before clicking
begin
   VideoGrabber.ResumeRecording; 
end;
procedure TForm1.BtnStopRecordingClick(Sender: TObject);
begin
   VideoGrabber.StopRecording;
end;