Re: How to selecting a video4linux camera based on its serial number from gst-launch?
Peter Maersk-Moller via gstreamer-devel <[email protected]> Thu, 29 Feb 2024 21:58:31 +0100
| Newsgroups | gmane.comp.video.gstreamer.devel |
|---|---|
| Message-ID | <CAGf_jGnQ6sXm2Lpwp-HTXt8AfA2-OSyMjesX_9mGr9iu08fU2g@mail.gmail.com> |
Hi Henning. Try take a look into /dev/v4l/by-id/ directory. Maybe you can use the id there to obtain the functionality you want. Regards Peter Maersk-Moeller On Thu, Feb 29, 2024 at 8:39 PM Henning Larsen via gstreamer-devel < [email protected]> 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 > <https://github.com/bluenviron/mediamtx>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?* > > Any hints are appreciated. > Thanks > henning > > > *Should someone need it: This is the python code find_camera_by_sn.py* > import sys > import pyudev > > def find_camera_by_serial(serial): > context = pyudev.Context() > for device in context.list_devices(subsystem='video4linux'): > if 'ID_SERIAL_SHORT' in device.properties: > if device.properties['ID_SERIAL_SHORT'] == serial: > return device.device_node > return None > > if __name__ == '__main__': > # Example: Find camera with serial number 'ABC123' > # manual command to list video4linux cameras > # udevadm info /dev/video0, etc for 0,1,,3 > default_dev = "/dev/video0" > if len(sys.argv) == 2: > camera_device = find_camera_by_serial(sys.argv[1]) > if camera_device: > print(camera_device) > else: > print(default_dev) > else: > print(default_dev) >