How to selecting a video4linux camera based on its serial number from gst-launch?

James Linder jam at tigger.ws
Thu Feb 29 21:29:33 UTC 2024



> On Mar 1, 2024, at 03:39, Henning Larsen via gstreamer-devel <gstreamer-devel at lists.freedesktop.org> wrote:
> 
> A command like this launches /dev/video0
> gst-launch-1.0 -v v4l2src device=/dev/video0 ! videoconvert ! autovideosink
> But when you have multiple cameras and they are enumerated in a random order you usually need to be able to identify each camera on - say its serial number.
> 
> It is easy to find the serial number including many other properties using the command
> $udevadm info /dev/video0
> The serial number for example, would be called 
> ID_SERIAL_SHORT=12345
> 
> How to use this serial number in the gst-launch string instead of the /dev/videoX id?
> 
> I tried 
> gst-launch-1.0 -v v4l2src device=$(python find_camera_by_sn.py 12345) ! videoconvert ! autovideosink
> And it works - inside a shell, but not inside a MediaMTX.yml configuration file, and I need it to work there. I suspect it is because it does not support the shell command. In any case it is not an elegant method - better to stick with what is provided by gstreamer - if possible.
> 
> I would think this must be a fairly common issue so does there exist a plugin/filter for gstreamer to achieve this device selection based on a specific property?

I’d totally isolate the problem by using udev to ensure camera A was always video0, B was (whatever is next ie video1, video4)
Then gstreamer always uses videoN

James

PS udev rules allow you to choose SN or Bus ID or ...


More information about the gstreamer-devel mailing list