Page 1 of 2

PBWebcam - cross-platform camera access!

Posted: Thu Mar 06, 2025 1:24 am
by kenmo
SDL 3 officially released in January, and since then I've been working on wrapping its cross-platform webcam/camera functionality into a single easy-to-use PureBasic includefile!

There were some camera bugfixes and improvements in SDL 3.2.6 released a few days ago, so now I'm ready to share version 1.0 of my code. Testers and feedback welcome! I've been testing it on both Windows and Linux. Should work on Mac too.

PBWebcam project on GitHub
https://github.com/kenmo-pb/PBWebcam

See the front page README and its links. You need three things:
1. Get my SDL3.pbi
2. Get my PBWebcam.pbi - I recommend you just download or clone the repo
3. Get SDL3 for your OS... this is a DLL on Windows, a .so on Linux, etc. You don't need the "devel" package.

Then run "Demo" which lets you choose between your cameras and specs, or "SimplerDemo" to immediately get a webcam view with no configuration. You can have a live webcam in a CanvasGadget in just a few lines of added code!

More about SDL / SDL3... it's great!
https://libsdl.org/
https://github.com/libsdl-org/SDL

Re: PBWebcam - cross-platform camera access!

Posted: Thu Mar 06, 2025 3:00 am
by idle
good to have a cross platform solution. thanks

Re: PBWebcam - cross-platform camera access!

Posted: Thu Mar 06, 2025 2:13 pm
by Quin
Very cool, thanks for sharing! I love SDL :D

Re: PBWebcam - cross-platform camera access!

Posted: Thu Mar 06, 2025 2:43 pm
by pjay
Thanks for sharing this with us Kenmo :)

I've been using Escapi for a while, but its inability to enumerate available resolutions & video formats was causing problems for me.

Re: PBWebcam - cross-platform camera access!

Posted: Sat Apr 26, 2025 8:19 pm
by minimy
Hello, work fantastic here PB6.21 beta6, x86 and x64 over windows 10 and 11. I will try in macOS and linux (ubuntu) soon :mrgreen:
Is nice can count with a multiOS solution integrated in PB for webcam.

Very nice work and many thanks for share Kenmo.

Re: PBWebcam - cross-platform camera access!

Posted: Sat Apr 26, 2025 10:12 pm
by ricardo_sdl
Nice work kenmo! Thanks for sharing.

Re: PBWebcam - cross-platform camera access!

Posted: Thu Jul 03, 2025 10:52 am
by captain_skank
Hi,

Just came across your code as i need to capture a webcam image.

Downloaded all required code, but every time i run the demo i get :

'Could not examine webcams, or none found!'

It's odd becasue i can see the live images from my 2 webcams using the built in windows 11 camera app.

Anybody got any ideas what this could be ?

FYI : i'm running Windows 11 Pro, PureBasic 6.21 (Windows - x64), the latest SDL3.dll and SDL3.pbi

cheers

Re: PBWebcam - cross-platform camera access!

Posted: Sat Jul 05, 2025 4:42 pm
by JHPJHP
Hi captain_skank,

I have the same configuration: Windows 11 Pro, PureBasic 6.21 (Windows - x64)

You may already have done some or all of the following, but it worked for me OOTB.

1. Download: https://github.com/kenmo-pb/SDLx/archiv ... s/main.zip
• Main SDL2/SDL3 wrapper for PureBasic
2. Download: https://github.com/kenmo-pb/PBWebcam/ar ... s/main.zip
• Demo PBWebcam examples
3. Download: https://github.com/libsdl-org/SDL/relea ... 32-x64.zip
• SDL 3.2.16 Assets (this is the one that worked for me)
4. Extract all three downloads to separate folders.

You now have two options to test your webcam:

1. Copy SDL3.dll to \SDLx-main\examples\
2. Execute \SDLx-main\examples\SDL3_Camera.pb
• This is probably the better option as it includes CTRL + S to save a webcam frame.

Or

1. Copy SDL3.dll to \PBWebcam-main\
2. Copy SDL3.pbi to \PBWebcam-main\
3. Execute \PBWebcam-main\PBWebcam_Demo.pb
4. Execute \PBWebcam-main\PBWebcam_SimplerDemo.pb

Re: PBWebcam - cross-platform camera access!

Posted: Mon Jul 07, 2025 8:57 am
by captain_skank
Thanks very much JHPJHP, just goes to show it's who you know not what you know :)

Works perfectly now.

Re: PBWebcam - cross-platform camera access!

Posted: Wed Jul 09, 2025 10:55 pm
by dibor
Here works with PC web camera GOOD.
Thank U!

Possible to use with other cameras?
A have analog camera connected through USB capture device.
Camera is recognised by your VfW Camera program, but this program sometimes caused BSOD


Best Wishes.

Re: PBWebcam - cross-platform camera access!

Posted: Thu Jul 10, 2025 9:18 pm
by JHPJHP
Hi dibor,

Inside the code \SDLx-main\examples\SDL3_Camera.pb (lines 29 to 46) you can check if your camera is recognized.
• If it is recognized set the associated index:

Code: Select all

firstID.SDL_CameraID = *devices\id[0]
Note: If relevant, I made some minor changes to my (outdated) VfW Capture script.

Re: PBWebcam - cross-platform camera access!

Posted: Mon Jul 14, 2025 3:35 am
by dibor
Thank U JHPJHP
I will try.
Can U do VfW window resizable?

Re: PBWebcam - cross-platform camera access!

Posted: Mon Jul 14, 2025 2:20 pm
by JHPJHP
Hi dibor,

I've updated my VfW example, but you should really try to get kenmo's cross-platform PBWebcam working.
• While the window is resizable the resolution is static; the VfW capture screen is just being stretched.

Not wanting to side-track this thread anymore then we already have, please post any future VfW questions to my PM.

Re: PBWebcam - cross-platform camera access!

Posted: Mon Jul 14, 2025 4:49 pm
by dibor
I can not to run PBWebcam example under MacOS :(
Lib., do not find :(
Have put all folders to the right place, as shown in the install.md file and set right path in the source.
Looks like I did something wrong :(

Re: PBWebcam - cross-platform camera access!

Posted: Sun Jul 20, 2025 7:09 pm
by RSrole
This is fantastic! Thanks for doing all that work!