Software compression by using codecs
Software compression The video and audio codecs available on the current platform can be used for AVI compression on the fly or after capture, according to CompressionMode.
video and/or audio compression Codecs can be applied on the video stream and/or the audio stream, according to CompressionType: - if CompressionType = ct_Video or ct_AudioVideo, a VideoCompressor must be chosen in the VideoCompressors list, that contains VideoCompressorsCount items, - if CompressionType = ct_Audio or ct_AudioVideo, an AudioCompressor must be chosen in 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, 'Microsoft Windows Media Video 9', 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 in account by many codecs) VideoCompression_DataRate VideoCompression_KeyFrameRate (accepted e.g. by MPEG encoders like the "Microsoft Vid'e9o 1" codec)VideoCompression_PFramesPerKeyFrame (accepted by 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 of the video compressor, not all of them can 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 is can be specified for this video compressor.
To know the capabilities and default values for the current compressor, proceed as follows:
- select a video capture device (set VideoDevice = index of a video capture device in the VideoDevices list
- identify the index of the video compressor in the VideoCompressors list and assign its index to the VideoCompressor property, e.g. by using VideoCompressor = VideoCompressorIndex ("compressor name")
- set RecordingMethod = rm_AVI
then, it is possible to: 1) - either invoke GetVideoCompressionSettings () that returns the capabilities and default values of the compressor
2) - either 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 of the codec capabilites, 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. Codecs dialogs Most of 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. - the Microsoft's MPEG-4 codec is available from the following URL: http://www.microsoft.com/windows/windowsmedia/format/codecdownload.aspx (Windows Media codecs 8 package).