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.
To be able to record in MKV the Matroska muxer filter must be installed. Then to be able to play the MKV clip the Matroska splitter (or the Haali Media Splitter) filter must be installed. The Matroska home page: http://www.matroska.org/ Matroska muxer: http://sourceforge.net/project/showfiles.php?group_id=82303&package_id=85124 Haali Media Splitter: http://haali.cs.msu.ru/mkv/MatroskaSplitter.exe or Matroska Splitter http://sourceforge.net/project/showfiles.php?group_id=82303&package_id=84361&release_id=208995
The recording starts by invoking StartRecording, and stop 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 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 ('Xvid MPEG-4 Codec')
- VideoGrabber.ShowDialog (dlg_VideoCompressor)
Additionally it is possible to invoke use the SaveCompressorSettings... and LoadCompressorSettings... functions to reload programmatically 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 if 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 compatiblity, allowing also 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 if AVIFormatOpenDML is disabled, the AVI clip size is limited to 1 Gb. AVI recording in native format The frame grabber allows to capture frames as well as to draw or write text over video frames.
The frame grabber requires 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, that 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 (except for native DV), - either 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)
a) The video source is NOT DV (IsDigitalVideoIn returns false): The video stream is saved as 'vids', fourCC = 'DIB ' RGB (*)
b) The video source is DV (IsDigitalVideoIn returns true): - if RecordingInNativeFormat is disabled, the DV stream is saved as 'vids', fourCC = 'DIB ' RGB (*) - if RecordingInNativeFormat is enabled, see the "DV recording in native format" chapter below
B. AVI FORMAT WHEN THE FRAME GRABBER IS NOT USED ON THE AVI STREAM (FrameGrabber = fg_PreviewStream or fg_Disabled)
a) The video source is NOT DV (IsDigitalVideoIn returns false): the video stream is saved as 'vids', fourCC is the subtype selected by the VideoSubtype index in the VideoSubtypes list.
b) the video source is DV (Digital Video): - if RecordingInNativeFormat is disabled, the DV stream is saved as 'vids', fourCC = YUY2 - if RecordingInNativeFormat is enabled, see the "DV recording in native format" chapter below
DV RECORDING IN NATIVE FORMAT (RecordingInNativeFormat is enabled)
- case of the DV video capture device that includes audio
-
if AudioRecording is enabled and DVRecordingInNativeFormatSeparatesStreams is enabled, the video stream is saved as 'dvsd', 'dvhd', or 'dvsl', and the audio stream is saved as 'auds' (PCM). In this case it is possible to ajust the audio format with the AudioFormat property.
-
if AudioRecording is enabled and DVRecordingInNativeFormatSeparatesStreams is disabled, the DV stream is saved as native 'iavs' (interleaved audio and video stream).
-
case of the DV video capture device that does not have audio
- the video stream is saved as 'dvsd', 'dvhd', or 'dvsl'.
(*) 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 OnUpdateAVIDurationAndFrameRate event occurs if the UpdateAVIDurationEvent 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, either the frame rate, but not both. If the frame rate is modified, the value of the duration will be ignored. huge preallocated capture file for AVI recording If being recording a large video size with high frame rate to an uncompressed AVI, this will generate a data flow to disk. It is possible to use an huge preallocated file to prevent the operating system to allocate disk blocks during AVI capture, this can help to preserve the disk access time and therefore to prevent dropping frames.
This is NOT required if being compressing on the fly or if being recording to WMV (ASF) files, because the amount of data to write to disk is in this case definitely smaller. Activation of the huge preallocated capture fileTo use of the preallocated capture file, enable PreallocCapFileEnabled before invoking StartRecording. When recording is stopped, the OnCopyPreallocDataStarted event occurs and TVideoGrabber starts copying AVI data to the final AVI file. During file copy, the OnCopyPreallocDataProgress event occurs periodically, until copy ends and the OnCopyPreallocDataCompleted event occurs.
Location of the preallocated capture fileThe preallocated file will be created at the location (full qualified path and file name) specified by PreallocCapFileName. If this property is left blank, the file is named "prealloc.avi" and placed in the current app's directory.
Size of the preallocated capture file The size of the preallocated capture file to create is specified by PreallocCapFileSizeInMb. If preallocated file exists at the PreallocCapFileName location, it will be automatically recreated if its size is smaller than the size specified.
How to create a preallocated capture file beforehandTo create a preallocated capture file, set PreallocCapFileName and PreallocCapFileSizeInMb, and then invoke CreatePreallocatedFile. The OnCreatePreallocFileStarted event occurs when the creation begins. Then the OnCreatePreallocFileProgress event occurs periodically until the preallocated file is created and the OnCreatePreallocFileCompleted event occurs.
When invoking StartRecording, if PreallocCapFileEnabled is enabled and the preallocated file does not exist or it size is smaller than the size specified by PreallocCapFileSizeInMb, it is automatically recreated.