<div dir="ltr"><div>Hi Henning.</div><div><br></div><div>Try take a look into /dev/v4l/by-id/ directory. Maybe you can use the id there to obtain the functionality you want.</div><div><br></div><div>Regards</div><div>Peter Maersk-Moeller<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Feb 29, 2024 at 8:39 PM Henning Larsen via gstreamer-devel <<a href="mailto:gstreamer-devel@lists.freedesktop.org">gstreamer-devel@lists.freedesktop.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">A command like this launches /dev/video0<div><i>gst-launch-1.0 -v v4l2src device=/dev/video0 ! videoconvert ! autovideosink</i><br></div><div>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.</div><div><br></div><div>It is easy to find the serial number including many other properties using the command</div><div><i>$udevadm info /dev/video0</i></div><div>The serial number for example, would be called </div><div>ID_SERIAL_SHORT=12345</div><div><br></div><div><b>How to use this serial number in the gst-launch string instead of the /dev/videoX id?</b></div><div><br></div><div>I tried </div><div><i>gst-launch-1.0 -v v4l2src device=$(python find_camera_by_sn.py 12345) ! videoconvert ! autovideosink</i><br></div><div>And it works - inside a shell, but <b>not </b>inside a <a href="https://github.com/bluenviron/mediamtx" target="_blank">MediaMTX.yml </a>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.</div><div><br></div><div>I would think this must be a fairly common issue so <b>does there exist a plugin/filter for gstreamer to achieve this device selection based on a specific property?</b></div><div><br></div><div>Any hints are appreciated.</div><div>Thanks</div><div>henning</div><div><br></div><div><br></div><div><i>Should someone need it: This is the python code find_camera_by_sn.py</i></div><div>import sys<br>import pyudev<br><br>def find_camera_by_serial(serial):<br> context = pyudev.Context()<br> for device in context.list_devices(subsystem='video4linux'):<br> if 'ID_SERIAL_SHORT' in device.properties:<br> if device.properties['ID_SERIAL_SHORT'] == serial:<br> return device.device_node<br> return None<br><br>if __name__ == '__main__':<br> # Example: Find camera with serial number 'ABC123'<br> # manual command to list video4linux cameras<br> # udevadm info /dev/video0, etc for 0,1,,3<br> default_dev = "/dev/video0"<br> if len(sys.argv) == 2:<br> camera_device = find_camera_by_serial(sys.argv[1])<br> if camera_device:<br> print(camera_device)<br> else: <br> print(default_dev)<br> else:<br> print(default_dev)<br></div></div>
</blockquote></div>