Search code examples
c++inputchannelv4l2

Choosing input channel with V4L2 API


I want to choose the input channel of my VideoCamera device. I can select it in VLC over the "Settings-Dialog". In Advanced Settings I can switch 'input' to 3 and my camera works. Now I want to do this in my C++ Application. I cannot find the write method to do this. At the moment my pictures are just black. I need to choose the S-Video Channel of my device.


Solution

  • You should have a look at the source code of v4l2-ctl which is part of v4l-utils. This tool is written in C++/Qt and should provide you with all information you need to do it yourself. Changing the input for a device is handled in v4l2-ctl-io.cpp

    void io_set(int fd)
    {
        if (options[OptSetInput]) {
            if (doioctl(fd, VIDIOC_S_INPUT, &input) == 0) {
                struct v4l2_input vin;
    
                printf("Video input set to %d", input);
                vin.index = input;
                if (test_ioctl(fd, VIDIOC_ENUMINPUT, &vin) >= 0)
                    printf(" (%s: %s)", vin.name, status2s(vin.status).c_str());
                printf("\n");
            }
        }
        // snip...
    }
    

    Hope this helps.

    Edit: Just found the relevant part in the official API documentation here. They have some examples on that page how to change the video input.