Skip to content

Software compression by using codecs

Software compression
The video and audio codecs listed in VideoCompressors / AudioCompressors can be used for compression on the fly or after capture, according to CompressionMode.
These lists include the Microsoft and GPU codecs, e.g. "H264 (Auto)", "H264 GPU (Nvidia)", "H264 GPU (Intel)", "H264 CPU (Microsoft)", "MJPEG CPU (Microsoft)", "AAC (Microsoft)", "MP3 (Microsoft)" (the list depends on the GPUs and drivers of the computer).

video and/or audio compression Codecs can be applied to the video stream and/or the audio stream, according to CompressionType:
- if CompressionType = ct_Video or ct_AudioVideo, a VideoCompressor must be chosen from the VideoCompressors list, that contains VideoCompressorsCount items,
- if CompressionType = ct_Audio or ct_AudioVideo, an AudioCompressor must be chosen from the AudioCompressors list, that contains AudioCompressorsCount items.

The name of the current VideoCompressor is reported by VideoCompressorName.
The name of the current AudioCompressor is reported by AudioCompressorName.
Note: VideoCompressors, VideoCompressorsCount, AudioCompressors and AudioCompressorsCount are also available as global variables in Delphi and C++Builder.
It is possible to select a compressor programmatically by its name (as it appears in the VideoCompressors or AudioCompressors list) by using the FindIndexInListByName function, e.g.:

procedure TfrmMainForm.Button1Click(Sender: TObject);
 var
 i: LongInt;
 begin
 i:= VideoGrabber1.FindIndexInListByName (VideoGrabber1.VideoCompressors, 'H264 GPU (Nvidia)', false, true);
 if i > -1 then begin // if this compressor has been found...
 VideoGrabber.VideoCompressor:= i;
 end;
 end;
 end;

Refreshing the VideoCompressors and AudioCompressors lists when installing/removing codecs. When the application starts, the VideoCompressors and AudioCompressors lists are populated with the codecs currently installed.
To refresh the compressor lists after installing/uninstalling codecs without exiting/restarting the application, invoke RefreshDevicesAndCompressorsLists.

General video compression properties
General video compression properties can be set with:
VideoCompression_Quality (this is the most common property taken into account by many codecs)
VideoCompression_DataRate
VideoCompression_KeyFrameRate (accepted e.g. by MPEG encoders like the "Microsoft Video 1" codec) VideoCompression_PFramesPerKeyFrame (accepted e.g. by MPEG2 and MPEG4 encoders)
VideoCompression_WindowSize
Look at each property for more information.

Each of these properties is activated if the value is <> -1.

Depending on the video compressor, not all of them may be available.

Determining the default values and capabilities for each video compressor
When binding the video compressor, the OnVideoCompressionSettings event queries it and returns CanKeyFrameRate, CanPFramesPerKeyFrame, CanQuality, CanWindowSize and CanSpecifyDataRate. These parameters return "true" if the corresponding VideoCompression_... property can be specified for this video compressor.

To know the capabilities and default values for the current compressor, proceed as follows:

then, it is possible to:
1) - either invoke GetVideoCompressionSettings () that returns the capabilities and default values of the compressor

2) - or create the OnVideoCompressionSettings event (write the code to log the values returned by the event, e.g. display them into a memo, assign them to variables or add ShowMessage...)
- and then invoke StartRecording: when the recording starts, the OnVideoCompressionSettings event occurs and returns the capabilities and default values.

Depending on the codec capabilities, it is possible to set the corresponding "VideoCompression_..." settings.

It is possible to assign the VideoCompression_... settings from the OnVideoCompressionSettings event that occurs when invoking StartRecording.

Recompressing video clips separately
The StartReencoding function makes it possible to recompress video clips separately. See How to reencode video clips for more information.
Codec dialogs
Most video compressors expose custom dialogs. They can be invoked by calling ShowDialog (dlg_Compressor).
The new codec settings are automatically saved/retrieved by TVideoGrabber.

Notes:
- not all the video and audio codecs can be used. When a codec cannot be used, usually invoking StartRecording fails.