Sign in to follow this  
Followers 0

WebcamDS (DirectShow webcam)

47 posts in this topic

Posted (edited)

I wrote a Udf to manage webcams with Direct Show instead of using avicap and dll32 dll.

Advantages vs the other Webcam UDF based on avicap32 and user32 dll:

- doesn't request to choose which webcam from list dropdown box

- you can precisely set: width, height, (bitplane ?? doesn't seem to work )

- you can set the video source resolution prior to scale it to the GUI and you can go up to 1920x1080 while with avicap you are limited at 640x480

- you can choose video compression in saving video and save the audio too (but uncompressed at the moment)

- you can use renderer you want, now VMR7 or VMR9

- you can make a zoom of some parts of the pic (also consecutive zoom of an area)

- you can go fullscreen EDIT: to exit from fullscreen press F1

- tested in W7 32-64bit and XP SP2

;------TODO: (don't know if and when)

; ---- TODO: take snapshot

; ---- TODO: windowless render preview, EVR ?

; ---- TODO: compress the audio?

; ---- TODO: more webcams in a single GUI

; ---- TODO: display rectangle on GUI during zoom selection

; ---- TODO: make more precise zoom selection in the bottomright border (due to border GUI, I think)

; ---- TODO: webcam controls luminosity, contrast, etc

- known problem: when returning from fullscreen, the gui doesn't display the webcam, but it's sufficient to press the reset to ripristinate

Besides, I upload some DirectShow interfaces that could be useful for other DS work.

Basically, to use this, you must call

_WebcamDS_Init()

at the beginning (it creates objects and fills some arrays you can use to populate your GUI, documented in the UDF).

Then you create your GUI, and you call

_WebcamDS_RenderWebcam(1,1,$hGUI,1,640,480,24)

this line means: webcamNumber 1, with audioPreview from Mic1, handleGUI ,rescale to the GUI, 640width, 480height, 24bpp

In my uploaded example, in the GUI there is from left: webcamList, audio micList, audio previewBox,CompressorList, audioCaptureBox,framerate, Save-Stop Buttons, resetPic, fullscreen(F1 to exit)

You can also see the video from one webcam and the audio from another one, ie:

_WebcamDS_RenderWebcam(1,2,$hGUI,1,640,480,24)

to change a webcam select it from the first combobox. If you want another audioMic, select the audio you want from the MicList, check the audioPrevBox and then select the webcam you want or press reset.

to zoom to a part of the pic, drag a rectangle with the mouse inside the pic, draw again if you want zoomIn. Press reset to return to normal pic.

to Save a video, you must select a video compressor from combobox and select the AudioCapture if you want (there must be also the same previewAudio), then press save (adjust the filename in the script). Stop when finished.

It's my first Direct Show attempt so I'm happy of the result ;)

EDIT:

it needs at least autoit beta 3.3.9.1

it's better to use in 32bit because there are more codecs

don't use DMO compressor (I have not implemented DMO), use the others:

for example DIVX or ffdshow (you set the parameters in their panel and then you can use them to record videos)

you need both UDF and interfaces files in the same dir (or adjust the paths).

I tried with 3 webcams: Microsoft LifeCam Studio (1920x1080), Logitech HD Pro C910 (1920x1080) and Philips 900NC (640x480)

Corrected example file to work well also with one webcam only.

version 1.0:

DirectShow_Interfaces.au3

WebcamDS_UDF.au3

WebcamDS_ExampleUDF.au3

Edited by frank10

Share this post


Link to post
Share on other sites



Posted

lol, it rebooted my windows xp...

Share this post


Link to post
Share on other sites

Posted (edited)

I only tried in W7 32-64bit ... Maybe it's something different with Direct Show?

I had no time to check for @error codes in my script to exit code nicely... sorry.

Edited by frank10

Share this post


Link to post
Share on other sites

Posted

it only work when i change it to full screen.. but nice example.. and udf.. ;)

Share this post


Link to post
Share on other sites

Posted

What happens before fullscreen?

Do you have the pic black?

With one webcam made this sometimes (I don't know why): try to press reset button until you get the pic.

Share this post


Link to post
Share on other sites

Posted

I tried XP and it works well also there.

I didn't see the reboot, but I discovered that with one webcam only there is a problem with an infinite loop.

I wrote the script with three webcam attached: one of them filled the array to build the combobox with two lines instead of one and so I wrote the code to adapt to this.

Now I corrected that line, now it should work as expected.

This is the new version:

WebcamDS_ExampleUDF.au3

Share this post


Link to post
Share on other sites

Posted

What happens before fullscreen?

Do you have the pic black?

With one webcam made this sometimes (I don't know why): try to press reset button until you get the pic.

yeah, i get black screen.. thanks, when i press reset, it will work

Share this post


Link to post
Share on other sites

Posted

Just tried it again.

When I run it, a huge gui shows up, about 2-3 seconds into the script, it causes a blue screen of death and the system restarts.

Share this post


Link to post
Share on other sites

Posted

Do you have XP SP2?

Do you have latest DirectX installed? Have you installed DirectX 9.0? (it's not sufficient install directly the 11)

Which webcam do you use?

Which resolution do you use for desktop? I have tried with a desktop of 1920x1080 and 1440 resolution, so I made a GUI of 1280x720, but you can change the GUI res as you want: try making 640x480.

You could also change the second parameter regarding audioPreview to 0, just to test video only, and also the 4° parameter to not scale to GUI:

_WebcamDS_RenderWebcam(1,0,$hGUI,0,640,480,24)

Anyway I don't know what could cause a bluescreen ;)

I think is DirectShow or hardware related.

Share this post


Link to post
Share on other sites

Posted (edited)

yeah, i get black screen.. thanks, when i press reset, it will work

Do you start the script always with black pic?

Try changing the last parameter to 16 or 12:

_WebcamDS_RenderWebcam(1,1,$hGUI,1,640,480,16)

Some webcams do not use all bpp. Try also 320x240 res. It depends on the webcam hardware.

EDIT:

Try also without audioPreview.

Edited by frank10

Share this post


Link to post
Share on other sites

Posted

So, does nobody else tried it?

The compressed saving or zooming part?

Share this post


Link to post
Share on other sites

Posted (edited)

It works fine with a Logitech C310 HD camera.

How can I use 2 cameras at the same time?

I'm going to use this udf a lot. Thanks for sharing it with us.

Edited by adolfito121

Share this post


Link to post
Share on other sites

Posted

I'm glad it works well. ;)

I had no time to try multiple webcams, but I'm interested in it.

I think it could be possible making two GUI, but the problem is that it's necessary to create multiple DS objects for the two GUIs.

At this moment the UDF doesn't take care of this.

I started creating an array of objects starting with the capture object but then I stopped.

Also because $ovideoWindow and $obasicVideo how do they refer to a capture object instead of another?

Or it could be multiple pic in the same GUI: it's surely possible, but it involves multiple graphs at the same time.

I know it's possible, but I didn't search it: if someone knows something or has some links of code examples, post it.

Maybe the other DS guys: trancexx or ProgAndy or Monoceres or...

Share this post


Link to post
Share on other sites

Posted

Alternatively, at the moment you can launch two instances of the script with different webcam settings.

This will create two GUI with two different webcams.

Share this post


Link to post
Share on other sites

Posted (edited)

Hi Frank, I used it and it is wroking very well. Thanks for share this code.

I didnt test saving yet, but will do so soon.

I know that you didnt any camera control, like bright, contrast, etc.

A meanwile suggestion would be to do like skype, wen you select a camera , and click in configurations it opens the camera driver adjustment screen. As I have 2 cameras (Logitech HD c270 and Acer Cristal eye, depending on the webcam selected, it opens the specific adjustment screen

*ps: how I can determine the place at the gui where the webcam will be?

Thanks again

Jose

Edited by joseLB

Share this post


Link to post
Share on other sites

Posted

Yes, it could be useful having the panel settings opened, I don't know how to make it popup.

Instead I have the opposite problem only with my Logitech C910: when I select it, the panel pops up every time, but I do not want it! I don't know how to prevent it from popping up.

*ps: how I can determine the place at the gui where the webcam will be?

I don't understand this. Could you reformulate?

Share this post


Link to post
Share on other sites

Posted (edited)

I don't understand this. Could you reformulate?

OK,

Probably it´s very simple and I couldnt seee.

On your example, I couldnt see where you specify the X,Y position where the webcam will be placed. On your example, there are some fields at top and the webcam screen comes just under them, left side. Where you specified it´s place?

Thnaks

Jose

* I had no problems selecting any of mine webcams... win 7 - 64bits, I5... they just appear, as expected.

** there are some parameters at _WebcamDS_RenderWebcam that you didn´t described (after bpp parameter)

Edited by joseLB

Share this post


Link to post
Share on other sites

Posted (edited)

I get this fatal system error!

post-30451-0-76058200-1334772401_thumb.j

Edited by DCCD

Share this post


Link to post
Share on other sites

Posted (edited)

On your example, I couldnt see where you specify the X,Y position where the webcam will be placed. On your example, there are some fields at top and the webcam screen comes just under them, left side. Where you specified it´s place?

I wrote the code to always place the webcam under the buttons line of the GUI, adding 26px:

EDIT: line 313-314 of UDF

It should be better to adapt them at different GUI...

If autoit could determine automatically where the GUI's free space begins. Is it possible to detect this?

If someone knows how to do this, I will change it.

Or it could be added as another two parameters, but I avoided that because there are a lot already...

** there are some parameters at _WebcamDS_RenderWebcam that you didn´t described (after bpp parameter)

In my version I have the description (I think it's the same I uploaded):

;                 $ibpp     - bitplane (if you put strange values it doesn't seem to change it..) normal: 12-16-24
;                 $iZoomX  - rectangle Zoom offsetX (0 = noZoom)
;                               - if you use it manually, be careful to put values that are inside the original width-height of
;                                   webcam otherwise it doesn't work
;                               - it's better to use the Setrect func drawing the rectangle with mouse directly on the GUI
;                 $iZoomY       - rectangle Zoom offsetY (0 = noZoom)
;                 $iZoomW     - rectangle Zoom Width (0 = noZoom)
;                 $iZoomH       - rectangle Zoom Heigth (0 = noZoom)
Edited by frank10

Share this post


Link to post
Share on other sites

Posted (edited)

I get this fatal system error!

Which OS and autoit version do you use?

Do you have latest DirectX installed? Have you installed DirectX 9.0? (it's not sufficient install directly the 11)

EDIT:

Do you have latest video drivers installed? which graphic card?

Edited by frank10

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.