How to play video files through DirectShow
DirectShow is a multimedia framework and API produced by Microsoft for software developers to perform various operations with media files or streams. Based on the Microsoft Windows Component Object Model (COM) framework, DirectShow provides a common interface for media across many programming languages, and is an extensible, filter-based framework that can render or record media files on demand.
By default, DirectShow includes a limited number of filters for decoding some common media file formats such as MPEG-1, MP3, Windows Media Audio, Windows Media Video, MIDI, media containers such as AVI, ASF, WAV, some splitters/demultiplexers, multiplexers, source and sink filters and some static image filters. However, DirectShow's standard format repertoire can be easily expanded by means of a variety of commercial and open source filters. Such filters enable DirectShow to support virtually any container format and any audio or video codec. One of the best packages containing most audio and video codecs for DirectShow is
K-Lite Codec Pack and can be downloaded for free from the following
link.
Active DJ Studio, through the embedded
VideoPlayer COM object and the related
VideoPlayer property, leverages DirectShow technology in order to render video frames and to process content of audio frames, giving the possibility to apply special effects to audio frames of video clips; see the
How to apply special effects to a playing sound tutorial for more details about available special effects.
Video clips are rendered over a graphical surface provided by an existing window, form or dialog box: you can create, position and size this graphical surface using the
VideoPlayer.Create method then you can move the graphical surface using the
VideoPlayer.Move method or hide/show it using the
VideoPlayer.Show method. You can obtain the native dimensions in pixels of the video clip through the
VideoPlayer.GetNativeSize method.
With certain codecs, and only if
VideoPlayer.IsSeekable returns "true", there is the possibility to change the current playback position through the
VideoPlayer.Seek method: note that seeking a video is far more CPU heavy than seeking a simple audio stream so, if for example you should need to change the playback position using a trackbar or a scrollbar, avoid calling the
VideoPlayer.Seek method each time the position of the trackbar's thumb is changed and call it only when the thumb is released on its final destination. The same should apply to playback rate changes obtained through calls to
SetTempoPerc or the
SetRatePerc methods.
When the video clip is no more needed, you can discard it from memory calling the
VideoPlayer.Close method.
NOTE ABOUT TEMPO AND PLAYBACK RATE CHANGE: It's important to note that not all of the video codecs are able to manage playback rate change correctly: for example certain kind of AVI codecs will loose synchronism between audio and video when calling the
SetTempoPerc or the
SetRatePerc methods: this is not a limitation of our control but a defect of the codec when running the video at a speed different than normal. Furthermore, other video codecs are not fast enough in order to provide enough PCM sound data for tempo and/or playback rate change so you could experience "stuttering" during playback: when dealing with codecs that cause stuttering during playback it would be a better solution avoiding the use of the
VideoPlayer.LoadForTempoChange method and to prefer the use of the
VideoPlayer.Load method.
A sample of use of the VideoPlayer object in Visual Basic 6 and Visual C++ 6 can be found inside the following samples installed with the product's setup package:
- TestVideoPlayer