This simple C# WinForms project allows you to playback video from a live capture device or from an existing video file and blend the video using transparency with the existing Windows desktop. The user can still interact with all other application windows "through" the playing video stream.
A while ago, a group from the University of North Carolina published a paper detailing a system they called FaceTop that makes use of transparent video streams for use in collaboration environments. By using transparent video over the desktop, the participant can view a video stream of the other participant while at the same time being able to read the contents of their desktop and look at items on their desktop that the other participant is referring to.
FaceTop makes use of MacOS X's Quartz composition engine to compose the video stream with the other desktop windows and apply the relevant transparency during composition. Windows has offered support for transparent top-level windows since the release of Windows 2000 using layered windows. For more details on this support for layered windows, see the following MSDN article.
At the time that the FaceTop paper was published, I was working on a video capture and playback system for aerial surveillance work. So my plan was to see how easy it would be to implement some of the basic features of FaceTop, i.e., transparent video playback that would allow you to watch the video and still allow you to see and interact with your desktop at the same time.
The basic setup consists of a C# WinForms application hosting the Windows Media Player control with a couple of specific properties set on the main form and the Media Player control.
To start off the Windows Media Player, the Primary Interop Assembly needs to be installed and referenced. See this MSDN article for details on downloading and installing the Windows Media Player's PIA.
After inserting the Windows Media Player control onto the form, the following three properties need to be set on the control:
None since we don't want the Media Player's controls visible, we only want to see the video stream.
true since we want the Media Player to use the control host's (our main form's) window and not create its own child window in which to render the video. The reason for this is that the layered windows transparency support in the OS that we're making use of only works for top-level windows and not for child windows. See the MSDN article for more details.
URL - source of the video. This can refer to an existing video, e.g. file:///c:/somevideo.wmv or to a video being streamed, e.g. http://somehost/.
Then the following properties need to be set on the form:
Opacity - 0.55 or whatever amount of transparency you'd like to use.
Load event we need to add the
WS_EX_TRANSPARENT extended window style to our form's window in order for input events from the mouse and keyboard to be passed through to the underlying windows.
static extern int GetWindowLong(IntPtr hWnd, int nIndex);
static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
private const int GWL_EXSTYLE = -20;
private const int WS_EX_TRANSPARENT = 0x20;
private void VideoPlayer_Load(object sender, System.EventArgs e)
int exstyle = GetWindowLong(this.Handle, GWL_EXSTYLE);
exstyle |= WS_EX_TRANSPARENT;
SetWindowLong(this.Handle, GWL_EXSTYLE, exstyle);
The sample screenshot at the top of the article shows a live video stream being captured by a DV camera attached to my system which is then being encoded to WMV using Microsoft's Media Encoder software and then being displayed as a transparent video over the desktop using my application by pointing the Media Player to http://localhost:8080/ to pick up the video stream.
Overall there was very little effort required to enable basic transparent video playback over the desktop.