Recent

Author Topic: BGRAVirtualScreen & Webcam  (Read 9216 times)

TheBlackSheep

  • Jr. Member
  • **
  • Posts: 93
BGRAVirtualScreen & Webcam
« on: April 22, 2012, 07:08:03 pm »
Hi All,

I'm trying to write a component to handle mplayer as an external "player" specifically in this case to use a webcam in both Linux and Windows (possibly OSX too) although potentially there are lots of uses of this I'm sure.  This sort of gets around platform variances on hardware and supporting code -  there are instances of a Linux component that does this on the CCR and there is a similar derivative class someone wrote a long time go to do the same on Windows (cmplayer.pas).

Anyway, the point is I'm trying to use the "-wid" option to avoid opening an external window and therefore need the relevant widgetset handle to pass on the command line to player.

In Windows this is the BGRAVirtualScreen.Handle but in Linux the following code appears to get the handle of the container window and not the component

GDK_WINDOW_XWINDOW(GetControlWindow(PGtkWidget(BGRAVirtualScreen1.Handle)));

I've attached a simple test program to show the problem - works in windows and semi-works in Linux but overlays the whole window rather than just the virtual bitmap area so what's the code to get the equivalent of the BGRAVirtualScreen handle on Linux (and ideally on OSX)?

To run the example in Linux you'll need to install mplayer via your package manager (sudo apt-get install mplayer orwhatever your distro requires etc and it's assuming the path is in "/usr/bin").  In Windows the command is pointing to mplayer.exe in a "mplayer" subfolder of the project folder (if it's not there you'll get an utf8 process exception unless you change the path to wherever you've extracted it after downloading it).

TheBlackSheep

Edit: I forgot to mention, depending on the specific's of the webcam you might need to change the command line options to mplayer - these work with mine (a really cheap webcam from PCWorld) but they're fairly generic.  You can test them by just playing around with the cmdline from a terminal in Linux (or command prompt in Win32) until it works for you (and Google is of course your friend here). 

Also, there are plenty of other commands to allow mplayer to operate "behind the scenes" without any visible representation (other than the view window) - so you can play all manner of video's, audio etc. directly from a Lazarus application. 

For Win32 - you don't need the GUI "SMPlayer" (that sort of defeats the point of doing this) - just download the binaries here;

http://oss.netfarm.it/mplayer-win32.php

just choose the appropriate version for your processor (AMD, Intel - P3 or P4 etc) at the bottom of the initial page before scrolling down this page - where it currently says   "Build (r34401)"

Have fun!
« Last Edit: April 23, 2012, 10:48:56 am by TheBlackSheep »

TheBlackSheep

  • Jr. Member
  • **
  • Posts: 93
Re: BGRAVirtualScreen & Webcam
« Reply #1 on: April 23, 2012, 03:27:21 pm »
Hi All,

For anyone interested to get this embedded in a BGRAVirtualScreen you'd use the following;

GDK_WINDOW_XID(GetControlWindow(GetFixedWidget(PGtkWidget(BGRAVirtualScreen1.Handle))))

Just need a Mac version now.

I'm going to put this into a component (although not sure how this will need to handle the different external dependencies)

I've been playing around with sending the "screenshot 0" command and this appears to work fine (albeit it has a fixed naming convention). 

Ideally what I'd like to do is create an "onion skin" operation - i.e. take a screenshot and then overlay/blend that on the webcam image somehow (anyone any ideas?) - it's extremely useful for animation to see the changes in movement between a live view and the last image (for stop motion animation (Claymation) anyway) - ideally to be able to "scrub" through a series of previous images and the live view.

I managed to do this on the "dspack" components in Delphi but couldn't get these to work in Lazarus and obviously these only support Win32 so I thought this mplayer comboined with the excellent BGRABitmap/BGRAControls might be the solution.

Any help would be appreciated.

TheBlackSheep

circular

  • Hero Member
  • *****
  • Posts: 4220
    • Personal webpage
Re: BGRAVirtualScreen & Webcam
« Reply #2 on: April 23, 2012, 05:16:27 pm »
Hello BlackSheep.

I'm not sure if I understand what you are explaining. In fact you could use any handle to render the image. Why do you need something specific ? You also draw it using the OnRedraw event ?
Conscience is the debugger of the mind

TheBlackSheep

  • Jr. Member
  • **
  • Posts: 93
Re: BGRAVirtualScreen & Webcam
« Reply #3 on: April 23, 2012, 06:21:28 pm »
Hi circular

I think you're suggesting I wouldn't need to use the BGRAVirtualScreen component and could use any window that offered a handle - I was hoping to be able to use features within the BRGABitmap family to blend in another image (i.e. a previous snapshot image that I alluded to in my previous email).

Is that what you meant?

TheBlacksheep

circular

  • Hero Member
  • *****
  • Posts: 4220
    • Personal webpage
Re: BGRAVirtualScreen & Webcam
« Reply #4 on: April 23, 2012, 09:07:30 pm »
Yes. There are two reasons why this cannot work :
- BGRAVirtualScreen has a memory bitmap which is drawn everytime the window is updated. It is not blended, it completely overwrites what is in the component (unless you put a component inside it for example).
- Mplayer like most players replace the window content. The standard drawing become completely invisible, and I suppose that you can try to draw anything on the window, it won't appear.

If you want to blend Mplayer output with something else, you need to receive the image as bitmap data, draw it in BGRAVirtualScreen or anything else, add other content, and then render it by yourself. Or maybe you can add a secondary input to Mplayer that you supply. This needs more interdependance between your software and Mplayer.
Conscience is the debugger of the mind

TheBlackSheep

  • Jr. Member
  • **
  • Posts: 93
Re: BGRAVirtualScreen & Webcam
« Reply #5 on: April 24, 2012, 01:02:13 am »
There are some overlay features within mplayer which initally looked promising except they don't appear to work on Win32 and the they look complicated (you seem to have to setup some kind of buffer to which you send your image that would appear as an overlay) - the platform restriction and the complicates process makes this probably unusable.

In theory all I need is to show a transparent image over the top of the mplayer output - perhaps using another virtualscreen component (same coordinates but which is higher z-layer). 

I think I just need to load the bitmap and then draw this transparently to the virtualscreen component (loading the bitmap and calling the repaint/invalidate didnt work - so need to do some research on drawing on the virtualscreen). 

I suppose the danger is unless I can make this second "overlay" virtualscreen (or whatever) semi-transparent then it'll just obliterate the mplayer feed and I'm no further forward.

TheBlackSheep


TheBlackSheep

  • Jr. Member
  • **
  • Posts: 93
Re: BGRAVirtualScreen & Webcam
« Reply #6 on: April 24, 2012, 08:47:46 am »
realised this isn't going to work now so need to rethink - perhaps slow the feed-down and update an overlay image faster than the feed or push the feed into an offscreen buffer and then merge the single snapshot image with individual frames from the offscreen buffer and then display the result.

circular

  • Hero Member
  • *****
  • Posts: 4220
    • Personal webpage
Re: BGRAVirtualScreen & Webcam
« Reply #7 on: April 24, 2012, 09:41:34 pm »
Basically, either you send your data to Mplayer, either you receive Mplayer frames in some buffer that you handle by yourself, merge and show. I don't think that putting a component over it will work. I've tried on Windows 7 with a transparent component, it does not appear at all, and with an opaque component, it flickers.
Conscience is the debugger of the mind

TheBlackSheep

  • Jr. Member
  • **
  • Posts: 93
Re: BGRAVirtualScreen & Webcam
« Reply #8 on: April 25, 2012, 12:32:09 am »
Yeah that's what I realised - it's a shame - I've got a similar application using the DSPack components (on googlecode) using Delphi - DirectShow media components. 

In there there's a component called VMRBitmap and it will allow a combination of the video feed and an image - unfortunately I can't get it to install in Lazarus (compiles but won't install for some reason)  and of course it's only win32 and I'd like to be able to support Linux too. 

Gstreamer is probably a better bet but it's a lot more complicated and I'd need to spend a long time converting the C++ headers for that one and I'd rather be developing the stop-motion app instead.

Oh well, thanks for the advice anyway.

btw I'd like to commend you on the BGRA classes and components - they really are excellent.

TheBlackSheep   

circular

  • Hero Member
  • *****
  • Posts: 4220
    • Personal webpage
Re: BGRAVirtualScreen & Webcam
« Reply #9 on: April 28, 2012, 07:43:02 pm »
Thanks. Well I wish you good luck for your project.
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018