AVI and MKV recording
Please read Codec patents first.
The AVI recording is enabled when RecordingMethod = rm_AVI.
The MKV recording is enabled when RecordingMethod = rm_MKV.
MKV: the selected video and audio compressors are used when CompressionMode = cm_CompressOnTheFly, e.g. "H264 GPU (Nvidia)" and "AAC (Microsoft)". Without compression:
- RecordingInNativeFormat = true records an MJPEG source as is and encodes the other sources in H.264 / AAC,
- RecordingInNativeFormat = false records uncompressed video and PCM audio.
The MKV file can be played while it is being recorded, and remains readable after a crash or a power failure.
The recording starts when StartRecording is invoked, and stops when StopRecording is invoked.
The video (with audio when AudioRecording is enabled) can be captured in an "as is" format, or with the video and audio compressors installed on the current platform.
If no video compressor is used, the recorded AVI format is:
- the format of the current video subtype of the video capture device if the frame grabber is disabled,
- the current frame grabber RGB format if the frame grabber is enabled.
After StartRecording is invoked, the RecordingFourCC property returns the FourCC of the format actually stored during the recording.
Saving / restoring the encoder settings
To adjust the compressor settings, invoke ShowDialog(dlg_VideoCompressor) as follows: the settings are saved in the registry and reused for the next recordings, e.g.:
VideoGrabber.RecordingMethod := rm_AVI;
VideoGrabber.CompressionMode := cm_CompressOnTheFly;
VideoGrabber.VideoCompressor := VideoGrabber.VideoCompressorIndex ('MJPEG CPU (Microsoft)');
VideoGrabber.ShowDialog (dlg_VideoCompressor);
See VideoCompressor and VideoCompressorIndex.
E.g. MKV recording in AV1 (the AV1 entries appear in the "video compressors" list only when the GPU has an AV1 encoder):
VideoGrabber.RecordingMethod := rm_MKV;
VideoGrabber.CompressionMode := cm_CompressOnTheFly;
VideoGrabber.VideoCompressor := VideoGrabber.VideoCompressorIndex ('AV1 GPU (Intel)');
VideoGrabber.ShowDialog (dlg_VideoCompressor);
The settings of the Microsoft and GPU encoder entries can also be set programmatically with VideoCompression_SetInt and AudioCompression_SetInt, e.g. VideoCompression_SetInt (vc_RateControl, 1) and VideoCompression_SetInt (vc_DataRate, 8000000) for a constant bit rate of 8 Mb/s. Once a video setting is assigned with VideoCompression_SetInt, the settings saved with ShowDialog (dlg_VideoCompressor) are no longer used, except those loaded with LoadCompressorSettingsFromDataString / LoadCompressorSettingsFromTextFile.
In addition, the SaveCompressorSettings... and LoadCompressorSettings... functions make it possible to reload several sets of compressor settings programmatically, without invoking ShowDialog() anymore, see SaveCompressorSettingsToDataString, SaveCompressorSettingsToTextFile, LoadCompressorSettingsFromDataString and LoadCompressorSettingsFromTextFile.
AVI OpenDML
By default, the AVI recording is made in the OpenDML AVI File format (AVIFormatOpenDML is enabled by default).
- When AVIFormatOpenDML is enabled:
- the AVI clip size may be greater than 1 GB,
- if AVIFormatOpenDMLCompatibilityIndex is enabled, the AVI file includes both an AVI 2.0 index and an AVI 1.0 index (for Video for Windows compatibility, which also makes it possible to get information about the AVI clip by right-clicking it in the file explorer to display its properties). If AVIFormatOpenDMLCompatibilityIndex is disabled, the AVI file contains only an AVI 2.0 index (in this case, the clip properties displayed by right-clicking do not report information).
- When AVIFormatOpenDML is disabled, the AVI clip size is limited to 1 GB.
AVI recording in native format
The frame grabber makes it possible to capture frames, as well as to draw or write text over the video frames.
The frame grabber requires an RGB source on its input pin. So, if the current video subtype of the video source is not RGB (e.g. YUY2), it is converted to RGB format. Therefore, enabling the frame grabber modifies the video subtype, unless RecordingInNativeFormat is enabled, which means: record the video stream "as is", without modifying it.
During recording, there are 2 possibilities:
- either the frame grabber is used on the AVI stream (case A below): drawing over the video frames affects the AVI file, but the AVI video stream is RGB, whatever the video subtype,
- or the frame grabber is not used on the AVI stream (case B below), and the video subtype is preserved in the AVI file (not converted to RGB). In this case, drawing over the video frames affects only the preview, not the video frames saved to the AVI stream.
AVI format when the frame grabber is used on the AVI stream (case A)
With FrameGrabber = fg_CaptureStream or fg_BothStreams, the video stream is saved as 'vids', fourCC = 'DIB ' RGB (*).
(*) The DIB format (Device Independent Bitmap) is RGB8, RGB555, RGB565, RGB24 or RGB32, according to the current display color bit count.
AVI format when the frame grabber is not used on the AVI stream (case B)
With FrameGrabber = fg_PreviewStream or fg_Disabled, the video stream is saved as 'vids', and the fourCC is the subtype selected by the VideoSubtype index in the VideoSubtypes list.
Note
Any listbox that shows the video subtypes of the current video capture device should be refreshed with VideoSubtypes (VideoSubtype is the current index in this list) when the OnVideoDeviceSelected event occurs. See the MainDemo project for sample code.
Modifying the frame rate or the duration of the recorded clip
When the AVI recording ends (and only the video stream is recorded), the OnAVIDurationUpdated event occurs if the AVIDurationUpdated property is enabled. This event returns the name of the clip, the frame count, the frame rate and the duration.
The frame rate or the duration of the AVI clip can be modified from this event. Because these values are linked together, either the duration or the frame rate can be modified, but not both: if the frame rate is modified, the value of the duration is ignored.
Automatic correction of the frame rate
When an AVI clip without audio stream is recorded from a video capture device or from the screen with the frame grabber on the capture stream (FrameGrabber = fg_BothStreams or fg_CaptureStream), the frame rate written in the file is corrected automatically at the end of the recording when the device delivered fewer (or more) frames than its nominal frame rate (difference above 5 % and 300 ms, e.g. a webcam that lowers its frame rate in low light), so that the clip plays at the right speed. A frame rate or a duration modified from OnAVIDurationUpdated is applied instead.
With an audio stream, the frame rate of the video is adjusted to the audio by the AVI multiplexer.