How to selecting a video4linux camera based on its serial number from gst-launch?
Henning Larsen
henning.e.larsen at gmail.com
Thu Feb 29 19:39:14 UTC 2024
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)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20240229/f25af77a/attachment.htm>
More information about the gstreamer-devel
mailing list