Copyright © 2005-2008 MultiMedia Soft 
Return to Table of contents  
 
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 class and the related DisplayVideoPlayer 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. 
 
At this point you can load a video clip using the VideoPlayer.Load, VideoPlayer.LoadForTempoChange or VideoPlayer.LoadForEAX methods and start its playback using the VideoPlayer.Play method. As for audio streams, you have various methods for controlling playback like VideoPlayer.Pause, VideoPlayer.Resume and VideoPlayer.Stop
 
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. 
 
You can obtain the overall duration of the video clip through the VideoPlayer.GetDuration method and, during playback, you can obtain the current playback position of the video clip through the VideoPlayer.GetPosition method. 
 
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. 
 
 
A sample of use of the VideoPlayer class in Visual C# and Visual Basic.NET can be found inside the following samples installed with the product's setup package: 
- TestVideoPlayer 
 
 
 
 
 
 
 
 
 
 
Copyright © 2005-2008 MultiMedia Soft 
Return to Table of contents