Published by Roman on 09 Oct 2009

How to use windowless Video Mixing Renderer Filter to show video fullscreen

The question is being asked from time to time. Everyone knows what is full screen video. Video renderers implement full screen capability since long ago through their IVideoWindow::put_FullScreenMode property, and even Filter Graph Manager exposes its own IVideoWindow interface to forward calls to filter’s implementation of IVideoWindow interface.

However, for Video Mixing Renderers, version 7 and 9, the preferred and recommended mode is windowless, where no IVideoWindow interface is available.

Note The IVMRWindowlessControl or IVMRWindowlessControl9 interface is now preferred over IVideoWindow. For more information, see Using Windowless Mode.

So in order to implement full screen mode it takes the application to attach Video Mixing Renderer filter to a private frameless window, to its entire client area and expand the window to entire monitor area.

The sample project FullScreenWindowlessVmrSample01 is illustrating this technique.

FullScreenWindowlessVmrSample01 Main Dialog

Continue Reading »

Published by Roman on 08 Oct 2009

How to make a constant frame rate video stream from variable frame rate stream, and rescale it

From a conversation:

I have a video stream with variable frame rate, I want to make this in to a constant  frame rate. Do you know of any filters that could help me with this?

Such filter is actually quite easy. You only need to update time stamps of the media samples that are going through. I am not aware of  an “out of the box” ready filter, but you can even do it without special filter: if you build your graph with Sample Grabber Filter in it in  the place of interest, and initialize it to have a callback for each sample, then in SampleCB method you will be able to update time stamps using methods of IMediaSample interface. This is sufficient to redistribute the frames on the timeline, so that they go at constant frame rate.

In your opinion what is the best way to scale the video?

The best depends on what is the criteria (speed, quality etc). The simplest for me while very efficient – and I did this a number of times – is to use a custom filter which inside it uses StretchBlt function on a per frame basis to scale input RGB video into output RGB video of a different resolution.

Published by Roman on 06 Oct 2009

MediaTools: Fix for Motion JPEG video

A small fix for M-JPEG video streams retrieved by HTTP Stream Source Filter:

  • Username and password contained in URL are honored for Basic HTTP authentication
  • Correctly parsed HTTP response headers with quotes, e.g.:
    Content-Type: multipart/x-mixed-replace; boundary=myboundary

Partial Visual C++ .NET 2008 source code is available from SVN, release binary included.

Published by Roman on 03 Oct 2009

DirectShow Related Bugs: MediaLooks MPEG-2 Video Decoder, Haali Media Splitter (AR)

An attempt to render media file in GraphStudio ended up with an error message:

Protection
A monitor program has been foun drunning in your system. Please unload it from memory and restart your program.

The module which popped up the message chose to not identify itself in a friendly manner, however as nothing goes untraceable it appeared to be MediaLooks MPEG-2 Video Decoder file, Mpeg2DecoderL.dll (version 1.0.3.9). As the message was popped up from a non-GUI thread, there was no way to close the box – the entire application froze…

MediaLooks MPEG-2 Video Decoder Error Message

The problem does not happen in GraphEdit, as the decoder is probably handling this case specifically.

The decoder has an deinstallation batch file located in application directory: C:\Program Files\MediaLooks\Mpeg2Decoder\Uninstall.bat. A curious thing, however, is that running this file in attempt to uninstall the decoder shows the same problem: the decoder refuses to be uninstalled due to mystic “monitor program” running in the system:

MediaLooks MPEG-2 Video Decoder Deinstallation Failure

After closing the message box the application still continues deinstallation script and removes the decoder from system.

Another issue for this file (and hopefully for today) is that another filter Haali Media Splitter (AR) (splitter.ax, version 1.9.42.1) is crashing the hosting process on being removed from the graph.

Haali Media Splitter Crash Haali Media Splitter Crash

Published by Roman on 30 Sep 2009

How to dynamically change resolution for video preview

From a conversation:

Q: I am using Web camera with DirectShow. Camera has only capture pin, so I am looking for the best way to switch resolution on the pin while graph is running. I would like to keep preview with smaller image size and when i would like to capture an image i would like to switch to full resolution. I have to use sample grabber callback since i need access to single image to process them. Is there a way to do that without stopping and starting a graph? This works but very slow between captures.

Is it possible to just reconnect the sample grabber only with new media changes and then resume the graph? Currently i just kill the graph and start it again, but it takes few seconds to do so, so I am looking the way to reduce that time.

There is no way to switch resolution on the running graph. There is a technique to dynamically start/stop individual filters and re-negotiate resolutions (media types), but it does not work for the majority of filters. Additionally to that Sample Grabber Filter cannot change resolution too, as it passes data through.

If you only have to use switched resolution for preview, you can use Geraint’s GMFBridge Toolkit to join two graphs, and a filter that changes resolution. Combining all that you will have a running capture graph that [also] renders video to a bridge sink. In the other graph you have another bridge sink that receives video from first graph and then you resize video to the resolution of interest already in the second graph. You can stop and reconfigure only second graph to update resolution and have first graph running and capturing. This is the best you can do, or just stop your single graph and change resolution this simple way.

So a solution, which is used by many, and I can recommend it too, is to use GMFBridge bridging. Additionally, you can find questions and answers on it on MSDN DirectShow Development Forum (search for “bridge” there). With a certain effort you can duplicate this with your own code but this is more or less ready to use solution and, again, the key advantage you have that you have two graphs which you can top independently.

Would it be possible to use smart tee as a splitter on the capture pin, and then use two sample grabbers on capture and preview, one with smaller resolution and the other one with higher one?

With a Smart Tee Filter you will still have 1 graph, so no individual resolution changes without stopping the graph. Additionally to that, Smart Tee Filter will deliver same frame on its output pins, so they will have to have one resolution and no resizing takes place inside.

Also, is it possible to run 2 graphs in the same time? Same device, 2 graphs, 2 sample grabbers.

Most likely no, for only one reason: you won’t be able to have two running filters for the same device, as source filter will exclusively lock the device. So capture filter will be a single filter. You can use Infinite Tee Pin Filter to split stream between 2+ processing lines. And you can use the same bridge to pass data into another graph for further processing.

Published by Roman on 21 Sep 2009

How to overlay a bitmap on top of video with Video Mixing Renderer (VMR-9)

A 100-lines code snippet which illustrates how a bitmap is overlaid over displayed video with Video Mixing Renderer 9 Filter using IVMRMixerBitmap9 interface. A video clip is played (default is Windows clock.avi, but you can replace it with your longer one to see overlay is really in a loop).

http://code.assembla.com/…/VmrMixerBitmapSample01/…

VMR9AlphaBitmap AlphaBitmap;
ZeroMemory(&AlphaBitmap, sizeof AlphaBitmap);
AlphaBitmap.dwFlags = VMR9AlphaBitmap_hDC;
AlphaBitmap.hdc = Dc;
AlphaBitmap.rSrc = CRect(0, 0, 32, 32);
AlphaBitmap.rDest.left = (FLOAT) 0.75;
AlphaBitmap.rDest.top = (FLOAT) 0.75;
AlphaBitmap.rDest.right = (FLOAT) 0.95;
AlphaBitmap.rDest.bottom = (FLOAT) 0.95;
AlphaBitmap.fAlpha = 0.75;
const HRESULT nSetAlphaBitmapResult = pVmrMixerBitmap->SetAlphaBitmap(&AlphaBitmap);
ATLENSURE_SUCCEEDED(nSetAlphaBitmapResult);

With a low FPS clip like clock.avi it is clear that the overlaid image is only updated with the next “main” video frame.

IVMRMixerBitmap9 Usage Sample

Visual C++ .NET 2008 source code is available from SVN, release binary included.

Published by Roman on 28 Aug 2009

Windows Media Codec List

Windows Media Codec List utility uses IWMCodecInfo interface (see also IWMCodecInfo2, IWMCodecInfo3) lists installed Windows Media Codecs and their formats and presents the findings in a convenient way. The utility gives a quick idea what a programmer would obtain through IWMCodecInfo2/IWMCodecInfo3 interfaces and what well known format structures (WM_MEDIA_TYPE, AM_MEDIA_TYPE, WAVEFORMATEX, VIDEOINFOHEADER) correspond to particular format.

For a description of Windows Media video and audio codecs, check article Encoding Audio and Video with Windows Media Codecs.

Windows Media Codec List Screenshot

Copy button copies discovered information into clipboard in comma-separated values (CSV) format (e.g. suitable fo rMicrosoft Excel). Submit button posts the same information to this website for… possibly further aggregation.

Some quick facts immediately visualized by the utility:

  • for a video codec there is exactly one generic codec format listed
  • video codec FOUCCs are: WM Video – WMV1, WMV2, WMV3; WM Video Screen – MSS1, MSS2; WM Video Image – WMVP, WVP2; WM Video Advanced Profile – WVC1
  • for audio codecs there are complete codec formats enumerated, with names/descriptions suitable for GUI
  • audio codecs enumerate different formats in response to enumeration settings (e.g. request for VBR formats)
  • WM Audio Lossless only lists formats for single pass VBR mode
  • audio format tags (wFormatTag) are: WM Audio including Professional and Lossless – 0×0161, 0×0162, 0×0163; WM Audio Voice – 0×000A; ACELP.net – 0×0130

Partial Visual C++ .NET 2008 source code is available from SVN, release binary included.

Continue Reading »

Next »