Page 1 of 1

assign webcam/camera module to /dev/video* at boot

Posted: Sat Feb 22, 2014 8:54 pm
by Seiduna
hello all,

I am new to arch, but I can copy and paste well, kheh,
but I can not get the udev rule right...

I have camera board and 2 usb webcam and I want to use motion, to watch my dogs when I am away.

but as I reboot rpi, cameras get assigned in /dev/video* randomly,
which does not match my motion cameras configuration files /dev/video* assignment.

in /etc/modules-load.d/raspberrypi.conf I added bcm2835-v4l2 so my camera board gets its place in /dev/video* on boot

from here I wrote rule (should I have seperate rule file for each camera, or can I put all in one file), in /etc/udev/rules.d/83-webcam.rules :

Code: Select all

KERNEL=="video0", SUBSYSTEM=="video4linux", SUBSYSTEMS=="usb", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="082b", GROUP="video",  SYMLINK+="web_cam0" 
KERNEL=="video1", SUBSYSTEM=="video4linux", SUBSYSTEMS=="usb", ATTRS{idVendor}=="0ac8", ATTRS{idProduct}=="0323", GROUP="video",  SYMLINK+="web_cam1"
KERNEL=="video2", SUBSYSTEM=="video4linux", SUBSYSTEMS=="usb", ATTRS{idVendor}=="0f63", ATTRS{idProduct}=="05d7", GROUP="video",  SYMLINK+="web_cam2" 
but this code is not working always, more chance that without it...

is above code sintax correct?
if so, what now?

kind regards

Re: assign webcam/camera module to /dev/video* at boot

Posted: Mon Feb 24, 2014 9:46 am
by redhawk
If you want to access a specific webcam then replace /dev/video? with /dev/v4l/by-id/ and the "usb-" file that refers to you device ID i.e. /dev/v4l/by-id/usb-046d_08c5_0EE92593-video-index0 (for Logitech Pro 5000).

Richard S.

Re: assign webcam/camera module to /dev/video* at boot

Posted: Tue Feb 25, 2014 8:04 am
by Seiduna
hello there redhawk,

sorry for delayed response, we had sun yesterday, and I went out to see it...

aha, I see, in /dev/v4l/by-id/ I have links to my two cameras, but not camera board,
which is assigned to /dev/video0 on boot since I load the v4l2 driver on boot

ls /dev/v4l/by-id/ -lh
total 0
lrwxrwxrwx 1 root root 12 Jan 1 1970 usb-Vimicro_Corp._USB2.0_Web_Camera-video-index0 -> ../../video2
lrwxrwxrwx 1 root root 12 Jan 1 1970 usb-_Webcam_C170-video-index0 -> ../../video1

when you say: "replace /dev/video? with /dev/v4l/by-id/ and the "usb-" file that refers to you device ID", where (and how) I do that?

kind regards

Re: assign webcam/camera module to /dev/video* at boot

Posted: Tue Feb 25, 2014 12:08 pm
by redhawk
What program are you using to capture webcam images??

I'm using fswebcam for my webcams and to specify the video device I use "-d" option i.e. fswebcam -d /dev/video0
Since my video order swaps around like yours I specify the actual device by it's id rather than /dev/video0 or /dev/video1
So to capture from my Logitech Pro 5000 I use: fswebcam -d /dev/v4l/by-id/usb-046d_08c5_0EE92593-video-index0 -q -S 12 -r 640x480 --jpeg 85 capture.jpg

For your 2 webcam their device paths would be:

If your capture program can specify the video device then replace /dev/video0 and /dev/video1 with the above device paths, if that's not possible then the following bash script should help (it replaces the symbolic links):

Code: Select all

sudo rm -f /dev/v4l/by-id/$cam_0
sudo rm -f /dev/v4l/by-id/$cam_1
sudo ln -s /dev/video0 /dev/v4l/by-id/$cam_0
sudo ln -s /dev/video1 /dev/v4l/by-id/$cam_1
( that's assuming Webcam_C170 will be your primary webcam otherwise rename cam_0= to cam_1= and cam_1= to cam_0= )

Richard S.

Re: assign webcam/camera module to /dev/video* at boot

Posted: Tue Feb 25, 2014 4:58 pm
by Seiduna
hello redhawk,

oh, I see now, instead of /dev/vodeo0 I can use /dev/v4l/by-id/usb-Vimicro_Corp._USB2.0_Web_Camera-video-index0,
so I will try that.

I use motion software (which in term uses ffmpeg to make .avi files)

I'll try your suggestion, in motion config I have to specify the path to camera,
so I'll have a go your way.

I need to plug the rpi on, and it should start monitoring/capturing with right config files for each camera.
As I dig I found out that udev rules should do the trick (assigning cameras to /dev/video*), but I like and understand your point, and will have a go at it.

man, thank you for your time and input, mostly thanks for bash script.

kind regards

Re: assign webcam/camera module to /dev/video* at boot

Posted: Mon Oct 10, 2016 7:36 pm
by start78
My Logitech C510 won't work with motion. It says there is no device at /dev/video0.

How can i identify the path to my camera in order to reassign it at boot?

Re: assign webcam/camera module to /dev/video* at boot

Posted: Thu Oct 13, 2016 4:56 am
by sdjf
@start78: if this is a usb device, the path may change each time unless nothing else is attached over usb.

If you have logging enabled, you could paste in the portion of /var/log/everything.log showing when it got mounted so we could figure out where it is.

Or the relevant portion of output from dmesg command.

the usb-devices command should also show whether it is getting seen by any driver.

Is it showing up in lsusb? Are you sure you have enough power to support it? Which Raspberry Pi Model is this?

Re: assign webcam/camera module to /dev/video* at boot

Posted: Wed Oct 03, 2018 5:12 pm
by eAL
Hey Guys,
i'm Alex, new to Raspies and programming so first of all hi everybody.
I have a similar problem.
I want to shoot a time lapse using 4 webcams (same models). Each webcam is facing the same object (plant) from a different angle and shouldn't be moved. I also want to assign each webcam by it's individual Serial-key to a specific Kernel or Webcam address (i.e. camera 1of4 should always have video0), so every time i reboot my Raspi and restart my time lapse program, the cam address should always be the same again (camera 1of4 = video0, camera 2of4 =video1 and so on). I tried all the steps within this thread and also other threads, i tried modding my udev rules as described and also tried to mess with modules-load.d but didn't achieve what i wanted. So within my OpenCV program written in c++ the camera address stays always the same but since the Raspi randomly assigns different cameras to these addresses at each reboot, it makes stuff very complicated fusing the images to a time lapse video and analysing my data later on. does anyone any have idea how to really set static addresses to these cameras?
Thank you guys in advance

Re: assign webcam/camera module to /dev/video* at boot

Posted: Sun Oct 14, 2018 1:58 pm
by barsznica
On my Pi3, the device "addresses" stay the same, no matter how many reboots (if you leave them pluggen in).
I've had motion running consistently like this for years!

I do like the previous posts refering to the cams 'by-id',

Code: Select all

ls /dev/v4l/by-id/ -lh
I may use this in the future, THANKS!

Re: assign webcam/camera module to /dev/video* at boot

Posted: Tue Dec 18, 2018 11:18 am
by barsznica
Well, well, well; the future is now!
Last night the order of my 3 cameras got muddled-up and I'm back here to admit my misunderstanding!

Thanks @redhawk ;)
What if I was to use 2 or 3 identical-id cameras?

@Seiduna I guess the CSI camera will always be video0 ???