Video capture uses contexts for storing and communicating information, such as frame properties.

About contexts

Contexts are used by the video capture framework to store and communicate device and processing properties. They are created by calling capture_create_context(), which returns a pointer to the context.

A video capture device can have one or more sources (or inputs). You can create multiple contexts, but you can have only one operational context for each device-source combination. For example, you can have an operational context for Device 1, Source 1, and another operational context for Device 1, Source 2, but you can't have a second operational context for either of these.

If you create more than one context for a device-source combination, the first context that enables capturing will be the context used by capture_get_frame(). Attempts to use the other contexts for that device-source combination will fail when capture_update() is called to apply instructions to the device.

Destroying contexts at exit

Your application must call capture_destroy_context() to destroy all contexts before it releases the capture buffers and exits. You can't count on the OS being able to adequately clean up after your application exits if the application doesn't destroy all the contexts it created for video capture.

Failure to destroy a context before exiting can lead to memory corruption and unpredictable system behavior.