Webcam/camera access in PureBasic via SDL3
- Get the latest
PBWebcam.pbifrom this repo - Get the latest
SDL3.pbifrom my SDLx repo - Get the latest
libSDL3binary for your operating system
You can find the latest SDL 3.x.y release on GitHub.
On Windows, you need SDL3.dll but pay attention to x86 or x64 to match your PureBasic compiler.
On Linux, you need libSDL3.so, but you may prefer to build it from SDL source using these simple CMake instructions.
In PB, you may encounter SDL3 definitions conflicting with existing SDL1 or SDL2 definitions!
One easy fix is to temporarily move sdl.res out of your purebasic/residents/ folder.
Let's call them "Webcams" because PureBasic already has a "Camera" library for the 3D engine.
ExamineWebcams(),CountWebcams(),WebcamName()to inspect available webcamsCountWebcamFormats()andWebcamFormatName()to inspect their supported specsOpenWebcam()to open a webcam by index, orOpenWebcamBestFramerate(),OpenWebcamBestResolution(),OpenWebcamClosestResolution(),WebcamIndexFromName()to simplify itWebcamWidth(),WebcamHeight(),WebcamFramerate(),WebcamDriver()to inspect the currently open webcamFlipWebcam()to mirror it horizontally (common) or flip it verticallyWaitWebcamFrame()to wait for the first frame, with timeoutGetWebcamFrame()to prepare a new frameDrawWebcamImage()to draw the frame to a 2DDrawing output like any other PB imageDrawWebcamToCanvasGadget()to simplify it even furtherSaveWebcamImage()to save the frame to a file like any other PB imageCloseWebcam()andFinishWebcams()when you're done!
GetWebcamFrame() and WaitWebcamFrame() cannot be called from within a StartDrawing()/StopDrawing() block.
Download or git clone this repo, and run PBWebcam_Demo.pb!
It should enumerate your available webcams and their formats, give you a live view (mirroring and flipping optional), and let you save images.
Or, run PBWebcam_SimplerDemo.pb to immediately get a live view of the default webcam!
(You still need to get SDL3.pbi and libSDL3 separately, see Requirements above.)