AVI and MKV recording
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 by invoking StartRecording, and stops by invoking StopRecording.
It is possible to capture the video (with audio when AudioRecording is enabled) in an "as is format", or by using the video and audio compressors installed on the current platform.
If no video compressor is used, the recorded AVI format will be:
- 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 invoking StartRecording, the FourCC of the format really stored during recording is returned by the RecordingFourCC property.
Saving / restoring the encoder settings
To adjust the compressor settings, invoke ShowDialog(dlg_VideoCompressor) as follows, the settings will be 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)
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)
Additionally it is possible to use the SaveCompressorSettings... and LoadCompressorSettings... functions to programmatically reload several sets of compressor settings without having to invoke ShowDialog() anymore, as explained in the Saving and restoring compressor settings programmatically chapter
AVI OpenDML
By default the AVI recording is made in OpenDML AVI File format if AVIFormatOpenDML is enabled.
- 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 on its properties with the file explorer). If AVIFormatOpenDMLCompatibilityIndex is disabled the AVI file contains only an AVI 2.0 index (in this case right-clicking on the clip properties does not report information). - when AVIFormatOpenDML is disabled, the AVI clip size is limited to 1 GB.
AVI recording in native format
The frame grabber allows you to capture frames as well as to draw or write text over video frames.
The frame grabber requires an RGB source on its input pin. So, if the current video subtype of the video source is compressed (e.g. YUY2), it will be uncompressed into 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), so drawing over video frames will affect the AVI file, but the AVI video stream will be 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 video frames will affect only the preview, not the video frames saved to the AVI stream.
A. AVI FORMAT WHEN THE FRAME GRABBER IS USED ON THE AVI STREAM
(FrameGrabber = fg_CaptureStream or fg_BothStreams)
The video stream is saved as 'vids', fourCC = 'DIB ' RGB (*)
B. AVI FORMAT WHEN THE FRAME GRABBER IS NOT USED ON THE AVI STREAM
(FrameGrabber = fg_PreviewStream or fg_Disabled)
The video stream is saved as 'vids', fourCC is the subtype selected by the VideoSubtype index in the VideoSubtypes list.
(*) DIB format (Device Independent Bitmap) will be RGB8, RGB555, RGB565, RGB24 or RGB32 according to the current display colour bit count.
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.
AVI frame size
By default, the recording is made in the current video size (see the Video sizes chapter).
However it is possible to record at half size or quarter size of the preview size (e.g. to keep a high resolution for the frame capture while recording a smaller AVI clip) by modifying RecordingSize.
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, frame rate and the duration.
From this event it is possible to modify the frame rate or the duration of the AVI clip.
Because these values are linked together, it is possible to modify either the duration or the frame rate, but not both.
If the frame rate is modified, the value of the duration will be ignored.