Webcam hints

It took me a bit to figure out the camera API, so here’s some things that might help if you’re also having troubles.

First off, there is an example in the source files on github. It’s probably the best place to start.

Something that caught me off guard is that you need to add the SDL_INIT_CAMERA flag in SDL_Init().

One other issue I ran into is that I opened the camera with a NULL SDL_CameraSpec. Well, this set the camera up with SDL_PIXELFORMAT_MJPG format when I requested the image. When you update a streaming texture the texture must have the same pixelformat as the surface/data, I was using SDL_PIXELFORMAT_RGBA8888 by default on all my textures. Even though I was getting an image back from the camera all I saw was a blank texture. So either check the returned format of the camera and create your display texture with that, or provide the camera spec from the beginning.

I hope this post saves someone a bit of frustration.