.NET Video Tips

Just a few useful .NET tips:

  • To render preview image of Flash movies, cast result of AxHost.GetOcx() to IViewObject then invoke its Draw method. This works even if Flash control AxHost is not visible or clipped. You can use the same trick to make webpage thumbnails but it'll work reliably only if you do so from within a timer event callback.
  • For QuickTime movies, above trick doesn't work so you'll have to scrap the bits off screen via GetWindowDC, BitBlt. Works only if QuickTime control AxHost is fully visible.
  • For WMP-supported movie formats, you can use DirectShow's Media Detector object (samples) or, if you are using WPF, build a MediaPlayer with a MediaTimeline pointing to target movie then pass into DrawingContext.DrawVideo to grab preview images.
  • If you only need thumbnails of WMP-supported movies and don't care what size, you can use Shell's thumbnail extraction extensions (IExtractImage2). Don't ask me for the code because this option was not attractive enough for me to dig.

There are two hardcore alternative solutions if you don't mind keeping your hands in the sewer pipe for the whole duration of your product's lifecycle.
First solution is to patch key API calls to intercept bits in transit. Yes, this can get ugly, particularly through .NET InterOp layer, but then be thankful that you only have to patch in-process and in memory only (i.e. inject jumpers into loaded DLL image import table). But then, thanks to DRM arms race, you'll find yourself deeper and deeper into the pit over time. Isn't that nice?
Second solution is to decode and render movies yourself since physical bits are not protected. There are plenty of open source video codecs out there to get the job done so the real problems are legal and maintenance issues.

Tags: , , ,
Advertisements