Video overlay part II - An introduction to hypervideo

-->

Table of contents

1. Why this article ?
2. Requirements
3. The program and source code
4. General MFC SDI application for high performance and versatile Video playback
5. A sample showing hypervideo
6. Download section

 

1. Why this article ?

 

This article brings executables and VC++ projects to extoll high performance video playback using the Microsoft DirectShow API. While the DirectShow SDK includes a couple of samples, most of them are written in pure low level Win32. One of the only examples written using MFC is a playback routine that simply opens a video file then apply a render to an automatically constructed filter graph. This filter graph builds itself the window and shows the video, thus allowing poor interaction with the user. The aim of what I show is to :

1. bring a sample using DirectShow written in MFC using the SDI class architecture
2. bring a couple of versatile routines so that you can customize almost everything, including user interaction, video display, windowing and so on...All these things bring full control over the video, and this is relevant if you consider applications featuring something else than a simple (non-interactive) playback.
3. bring a couple of ideas in the construction of a generic video class that would feature every aspect needed by a coder in a multimedia application that uses video in different ways. For example, the application could switch between fullscreen mode and window mode, the application could synchronize two or more videos, the application could allow the user to click on the video and launch an hypermedia link, the application could change dynamically the size of the video window or move it, the application could play video segments instead of whole videos, and so on....

 

2. Requirements

 

To run the executable programs, you need at least the DirectShow run-time, no matter the version. You can download the run-time (4Mb) at the following address http://www.microsoft.com/directX/download.asp.

To build the source code, you need the DirectShow SDK, no matter the version. You can download the SDK (90Mb) at the following address http://www.microsoft.com/directX/download.asp.

DirectShow is an SDK from Microsoft corporation.

 

3. The program and source code

 

Then, what's the hot stuff ? There are 4 things to download. I show and explain two samples :

The first sample is a MFC SDI application which playbacks a video. The video can be played, paused and stopped. These are basic controls. You can download the executable program and the source code.

The second sample is a MFC SDI application which brings a new form of interactivity to video : while simply performing video overlay using the GDI, it lets you move and stretch a hotspot live onto the video. You can download the executable program and the source code.

The idea behind this second sample is to track manually the actors and characters in the video while it's playing, using the mouse. This sequence of hotspots through time makes an actor sequence. This sequence, or set of sequences if required, can be saved on disk for future use. A player could read this data file in the context of an authoring software (or in a simple hand-written application), and then test whatever mouse-clic in the video, and launch something, a web page for example, when the mouse clic is performed inside the hotspot. This association between an actor and the launched links is what we call an hypervideo link. The concept itself is the hypervideo clip, which is video + interactive link content. It has a lot at stake in the field of online video streaming, and offline course-based training for example. This sample is thus the root for an hypervideo generator. Contact me for more details.

 

4. General MFC SDI application for high performance and versatile Video playback

4.1 Introduction

This sample is based on an existing DirectShow sample taken from the SDK, which wasn't inside the samples directory, but actually in the documentation itself. So let me remind you what to do :

First you will have to copy/paste the source code from the DirectShow documentation. Starting at the default page, go to the Application Developer's guide, then How to... then Play a Movie in a Window Using DirectDrawEx and Multimedia Streaming. This program is an extension of the simple ShowStream sample provided in the SDK.

4.2 Elements

The sample is a standard SDI application. The WinAPP instance opens fire and creates a standard FrameWindow + Document + View. In our case, the FrameWindow and the Document are almost useless. The WinApp calls a RenderToSurface() routine on idle, provoking the display of the current video sample in the client area of the view.

The video engine is inside the view class. It performs the elementary steps : show a file dialog to select the video file, init the directdraw surfaces hence preparing display and offscreens, init the multimedia stream by adding a video stream and an audio stream to the filter graph, and call the magical render routine to automatically build up a compatible filter graph that will parse, multiplex and then render both video and sound to the approriated devices on your machine.

The MovieView class pumps messages while the video is playing, allowing you to pause the video by pressing the space key, and restart it, and allowing you to stretch the main window, or even to switch to "fullscreeen" by double-clicking on the title bar.

The classes MovieApp, Mainframe, MovieDoc and MovieView are a good reusable set of classes.

The RenderToSurface() routine is a specific routine. In order to allow future interaction the backbuffer which receives the video sample is not necessarily simply blitted to the primary visible surface into the view. In fact, the routine is much like RenderToSurface(BOOL bSimpleBlit=TRUE). When the bSimpleBlit is set to FALSE, the sample-backbuffer is blitted to a copy-backbuffer, and then the copy-backbuffer is stretch-blitted to the visible surface. This allows you to apply filters, effects, GDI overlay, and so on the copy-backbuffer before it is blitted. Why not directly on the sample-backbuffer sir ? Because if the video is turned in PAUSE mode, the sample-backbuffer is not refreshed and any applied image processing results in dull traces.

I guess it's time to test the sample.

 

5. A sample showing hypervideo

 

The second sample is an extension of the first sample. The RenderToSurface() is a good place to perform overlay, hence I draw a square hotspot using the GDI and stretch-blit everything towards the visible surface.

Now let me tell you that I also check mouse buttons and moves. If the user clicks with the left button inside the hotspot, and then drags the mouse, then the hotspot moves. If the user clicks with the right button and then drags the mouse, then it stretches the hotspot.

The user can play/pause the video using the space key. The user can show hatches inside the hotspot by pressing the S key alternatively.

When I capture the mouse, the coordinates are given in screen coordinates. If I use the GDI to get the DC from a DirectDraw surface, I must remember that such a DC is basically given in a raw MM_TEXT mode. Thus I have to manage a system of physical / logical coordinates in order to show the hotspot where it should be seen !!! This explains the somewhat couple of calculations.

 

This MovieView class is left open. I have implemented in this release only a couple of helper functions. There are so many to implement that it requires quite a lot of articles, discussion with you and of course...fun !!

 

6. Download section

 

Video playback : executable MoviePlay.exe (26Kb), source code VC++ project MoviePlay.zip (30Kb).

Interactive video playback : executable MovieMFC.exe (28Kb), source code VC++ project MovieMFC.zip (33Kb).

 



Date Last Updated: February 3, 1999



Comments

  • Detecting Source.?

    Posted by Legacy on 08/04/2003 12:00am

    Originally posted by: Dillip

    Hi there.,
    In my application , there are 3 video source attached . One is from Webcam connected to USB and other one is from TV-Tuner card which sends 2 sources i,e. (a) S-Video ,(b) Composite Video (Composite line). But, when I detect, it shows me only 2 sources in the list . I tested with your application also.. but I receive the same ..only 2 sources .. 1. Webcam & other one is either S-Video or Composite Video . How can I detect these 2 sources(S-Video & Composite Video) comming from TV tuner card ..?

    Thanks in Advance.!~

    Best Regards,
    DILLIP.

    • j3_k'll

      Posted by bjoon on 09/12/2007 09:18pm

      j3_k'll

      Reply
    Reply
  • How to burn a DVD?

    Posted by Legacy on 07/03/2003 12:00am

    Originally posted by: Krishna Seetharaman

    I am writing an application to burn DVDs using Visual C++. Is there any way to burn a DVD using Visual C++ 6.0 EnterPrise Edition? I have a DVD-R media to burn. What I need to do is to first format them so that they can fit any data and then burn them with data from my harddisk. How can this be done? Are there any functions to do that? I know of mciSendCommand and DeviceIoControl. Can DVD burning be accomplished by using these 2 functions? If so can you just briefly go over the procedure involved(i.e.., what functions do I need to use for the important steps involved) to burn a DVD given that I have a DVD-R and data to be burnt in my hard disk.
    Can you help me on this? Any code samples and examples are welcome.

    Thanks a Lot...


    Reply
  • Compilation error:

    Posted by Legacy on 06/08/2003 12:00am

    Originally posted by: Meenakshi Sundaram D

    i can't compile this source. Always come as 'waveformattag redefinition'.
    Anybody help me for this?...
    Thanks.

    Deleting intermediate files and output files for project 'MoviePlay - Win32 Debug'.
    --------------------Configuration: MoviePlay - Win32 Debug--
    Compiling resources...
    Compiling...
    StdAfx.cpp
    Compiling...
    MainFrame.cpp
    MovieApp.cpp
    MovieDoc.cpp
    MovieView.cpp
    d:\program files\microsoft visual studio\vc98\include\mmsystem.h(694) : error C2011: 'waveformat_tag' : 'struct' type redefinition
    d:\program files\microsoft visual studio\vc98\include\mmsystem.h(706) : error C2011: 'pcmwaveformat_tag' : 'struct' type redefinition
    d:\program files\microsoft visual studio\vc98\include\mmsystem.h(774) : error C2061: syntax error : identifier 'LPCWAVEFORMATEX'
    d:\program files\microsoft visual studio\vc98\include\mmsystem.h(830) : error C2061: syntax error : identifier 'LPCWAVEFORMATEX'
    C:\Windows\Desktop\June8\MoviePlay\MovieView.cpp(314) : error C2248: 'AddRef' : cannot access private member declared in class 'ATL::_NoAddRefReleaseOnCComPtr<struct IAMMultiMediaStream>'
    d:\program files\microsoft visual studio\vc98\atl\include\atlbase.h(419) : see declaration of 'AddRef'
    Generating Code...
    Error executing cl.exe.

    MoviePlay.exe - 5 error(s), 0 warning(s)

    • To compile do following changes

      Posted by paijwar on 10/03/2007 11:17am

      Replace 
      pAMStream->AddRef();
      
      with
      (*pAMStream).AddRef();

      Reply
    Reply
  • Using RenderFile and MFC

    Posted by Legacy on 04/16/2003 12:00am

    Originally posted by: Asa M. Andrews

    I am trying to retreive a file from another computer on the net. I am doing some other things to the file, and I am then wanting to display the resulting file (a movie file of various formats) as a movie. I have used, in the past RenderFile(..) and that works just fine, except that the way that I am spooling data to the "Render Engine" is via a file. This file has to be closed for the the RenderFile(..) procedure to function.

    Ultimately I need a way to spool into the file (make shift streem) into a render filter that would allow me to play the file formats that I need. File Formats : Mp3, Mpeg-4, MPeg, AVI, Wav, and VOB. If we assume that the CODECS are installed how do I do this?

    As I stated, the program works fine if the spooler Task is running on its own, the RenderFile() works also so long as the spooler task does not have the file open, in fact RenderFile will not start if the file is open.

    Thanks
    Asa

    Reply
  • Need transform directshow directx filter

    Posted by Legacy on 11/24/2002 12:00am

    Originally posted by: Stepan

    please, send me where can i find empty or not empty directx directshow filter which overrided from CTransformFilter class in visual C++

    Reply
  • DVD (.VOB) Player

    Posted by Legacy on 11/13/2002 12:00am

    Originally posted by: Sun Jiang

    Help me please, how to program a DVD player (*.VOB file)?

    Reply
  • Strmbase.lib or Strmbasd.lib

    Posted by Legacy on 09/13/2002 12:00am

    Originally posted by: Vin

    Hi folks, I'm trying to compile some of these sample programs. I've got the Directx 8.1 SDK but I seem to be missing the file strmbase.lib or strmbasd.lib. Can someone please tell me how to get these files. I read somewhere about compiling .... something ;) that would result in these lib files. Please help...

    Thanks

    Reply
  • Compilation error under VC++ 6.0 and DIRECTX 8

    Posted by Legacy on 06/20/2002 12:00am

    Originally posted by: Loic


    Does anyone get these errors?
    Any idea how to solve them?


    c:\program files\microsoft visual studio\vc98\include\mmsystem.h(695) : error C2011: 'waveformat_tag' : 'struct' type redefinition
    c:\program files\microsoft visual studio\vc98\include\mmsystem.h(709) : error C2011: 'pcmwaveformat_tag' : 'struct' type redefinition
    c:\program files\microsoft visual studio\vc98\include\mmsystem.h(777) : error C2061: syntax error : identifier 'LPCWAVEFORMATEX'
    c:\program files\microsoft visual studio\vc98\include\mmsystem.h(833) : error C2061: syntax error : identifier 'LPCWAVEFORMATEX'

    Reply
  • Play 2 movies in the same window?

    Posted by Legacy on 04/11/2002 12:00am

    Originally posted by: Drill

    Hello!

    I would like to create an application which can play 2 videos in the same time and in the same window? it's possible with Directshow??

    thanks

    Reply
  • DirectShow Filters

    Posted by Legacy on 03/15/2002 12:00am

    Originally posted by: Turulo Manco

    I've been looking for info about writing DirectShow Filters, I'm trying to do a filter that for the standard renderer that show the video in scanlines like emulating a TV. Where can I find some leads to it?

    Thanks in advance...

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • The impact of a data loss event can be significant. Real-time data is essential to remaining competitive. Many companies can no longer afford to rely on a truck arriving each day to take backup tapes offsite. For most companies, a cloud backup and recovery solution will eliminate, or significantly reduce, IT resources related to the mundane task of backup and allow your resources to be redeployed to more strategic projects. The cloud - can now be comfortable for you – with 100% recovery from anywhere all …

  • Download the Information Governance Survey Benchmark Report to gain insights that can help you further establish business value in your Records and Information Management (RIM) program and across your entire organization. Discover how your peers in the industry are dealing with this evolving information lifecycle management environment and uncover key insights such as: 87% of organizations surveyed have a RIM program in place 8% measure compliance 64% cannot get employees to "let go" of information for …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds