PBWebcam - cross-platform camera access!

Developed or developing a new product in PureBasic? Tell the world about it.
User avatar
kenmo
Addict
Addict
Posts: 2032
Joined: Tue Dec 23, 2003 3:54 am

PBWebcam - cross-platform camera access!

Post 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
User avatar
idle
Always Here
Always Here
Posts: 5834
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: PBWebcam - cross-platform camera access!

Post by idle »

good to have a cross platform solution. thanks
Quin
Addict
Addict
Posts: 1122
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: PBWebcam - cross-platform camera access!

Post by Quin »

Very cool, thanks for sharing! I love SDL :D
pjay
Enthusiast
Enthusiast
Posts: 251
Joined: Thu Mar 30, 2006 11:14 am

Re: PBWebcam - cross-platform camera access!

Post 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.
User avatar
minimy
Enthusiast
Enthusiast
Posts: 551
Joined: Mon Jul 08, 2013 8:43 pm
Location: off world

Re: PBWebcam - cross-platform camera access!

Post 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.
If translation=Error: reply="Sorry, Im Spanish": Endif
ricardo_sdl
Enthusiast
Enthusiast
Posts: 141
Joined: Sat Sep 21, 2019 4:24 pm

Re: PBWebcam - cross-platform camera access!

Post by ricardo_sdl »

Nice work kenmo! Thanks for sharing.
You can check my games at:
https://ricardo-sdl.itch.io/
User avatar
captain_skank
Enthusiast
Enthusiast
Posts: 639
Joined: Fri Oct 06, 2006 3:57 pm
Location: England

Re: PBWebcam - cross-platform camera access!

Post 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
User avatar
JHPJHP
Addict
Addict
Posts: 2250
Joined: Sat Oct 09, 2010 3:47 am

Re: PBWebcam - cross-platform camera access!

Post 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
Last edited by JHPJHP on Thu Jul 24, 2025 6:20 pm, edited 1 time in total.

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
User avatar
captain_skank
Enthusiast
Enthusiast
Posts: 639
Joined: Fri Oct 06, 2006 3:57 pm
Location: England

Re: PBWebcam - cross-platform camera access!

Post by captain_skank »

Thanks very much JHPJHP, just goes to show it's who you know not what you know :)

Works perfectly now.
dibor
Enthusiast
Enthusiast
Posts: 160
Joined: Wed May 20, 2020 5:19 pm
Location: The 3rd planet in the Solar System
Contact:

Re: PBWebcam - cross-platform camera access!

Post 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.
Mac Studio M1Max, PB 6.12 Arm64 and x64.
Macbook Air M2, PB 6.12 Arm64 and x64.
Windows 10, PB 6.12 x64 and x86.
User avatar
JHPJHP
Addict
Addict
Posts: 2250
Joined: Sat Oct 09, 2010 3:47 am

Re: PBWebcam - cross-platform camera access!

Post 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.

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
dibor
Enthusiast
Enthusiast
Posts: 160
Joined: Wed May 20, 2020 5:19 pm
Location: The 3rd planet in the Solar System
Contact:

Re: PBWebcam - cross-platform camera access!

Post by dibor »

Thank U JHPJHP
I will try.
Can U do VfW window resizable?
Mac Studio M1Max, PB 6.12 Arm64 and x64.
Macbook Air M2, PB 6.12 Arm64 and x64.
Windows 10, PB 6.12 x64 and x86.
User avatar
JHPJHP
Addict
Addict
Posts: 2250
Joined: Sat Oct 09, 2010 3:47 am

Re: PBWebcam - cross-platform camera access!

Post 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.

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
dibor
Enthusiast
Enthusiast
Posts: 160
Joined: Wed May 20, 2020 5:19 pm
Location: The 3rd planet in the Solar System
Contact:

Re: PBWebcam - cross-platform camera access!

Post 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 :(
Mac Studio M1Max, PB 6.12 Arm64 and x64.
Macbook Air M2, PB 6.12 Arm64 and x64.
Windows 10, PB 6.12 x64 and x86.
RSrole
User
User
Posts: 71
Joined: Fri Apr 29, 2022 8:27 pm

Re: PBWebcam - cross-platform camera access!

Post by RSrole »

This is fantastic! Thanks for doing all that work!
Post Reply