I had this issue while setting up two webcams with a Raspberry Pi and Motion.
I ended up with the conclusion that this is due to the naming in /dev/ (video0, video1, video2, video3, …)
After a reboot, or after unplug/plug of a USB webcam, its device naming may change, therefore Motion configuration becomes incorrect.
In Motion .conf files, each camera shall be called by its device name, for example:
videodevice /dev/video0
In addition, in my setup I have 2 names per webcam, and only one of them is valid for Motion.
raspberrypi:~ $ ls /dev/video*
/dev/video0 /dev/video1 /dev/video10 /dev/video11 /dev/video12 /dev/video2 /dev/video3
Plug/unplug your camera to know what are its identifiers.
The solution I found is to use a static naming of those webcams, fortunately in /dev/v4l devices can be called with their id and path.
For example:
pi@raspberrypi:~ $ ls /dev/v4l/by-id
usb-xxxxxx_xxxxxx_xxxxxx-video-index0 usb-yyyyyy_yyyyyy_yyyyyy-video-index0
usb-xxxxxx_xxxxxx_xxxxxx-video-index1 usb-yyyyyy_yyyyyy_yyyyyy-video-index1
The xxxxxx and yyyyyy are the manufacturer name, product name and serial number, you can see them by using dmesg:
dmesg | grep usb
Now in the motion .conf files, call the camera by its id, for example:
videodevice /dev/v4l/by-id/usb-xxxxxx_xxxxxx_xxxxxx-video-index0
I tested it by unplugging and plugging again, and by doing a reboot, it works with no issue.
I read about another workaround to define a rule in udev, but I’m not doing it for the moment.
If you have any question or remark feel free to add a comment.
You ROCK! I’m not using a RasPi, but this gave me the information I needed to find my use-case solution!
I’m using an Orange Pi Zero SBC as a standalone controller to power/utilize a USB webcam for security, running Armbian with MotionEye installed, later to stream to a home server.
Should anyone else see this, the workaround I used was: instead of using the path “/dev/v4l/by-id” (didn’t work) use “/dev/v4l/by-path”. Also — and this turned out to be important — when configuring the camera (the “Add Camera…” box) MotionEye still wouldn’t work with the default V4L camera. I had to use the drop-down box to choose the “integrated camera” option. To be fair, this last wrinkle may not have been the fault of the Orange Pi or Armbian, as the webcam was purchased from AliExpress…
Orange Pi Zero (H2 quad core)
Armbian 21.02.2 Buster
IMC Network webcam
Motion version 4.3.2
Glad that this post helps at least someone else than me 🙂
Hi! I’m doing all that you wrote in the article however I can’t get see the second video signal
Disconnect the second camera and see its ID to be sure you use the correct one.
Thanks for this. I had the same problem, caused by finicky fragile USB cable, and I remember I used to solve it by a cron script with a custom C program that reset the usb hub driver. Today I was determined to find a better solution and yours worked, even when the camera disconnects, it can come back after a couple of seconds. So I agree, you ROCK!
By the way, do you know what is the difference between index0 and index1?
I’m note sure about them but I think they are offering some camera features other than video capture (microphone interface?).
My camera turns grey every so often after running for a bit and renaming camera with v4l ID fixed it. Thanks!
I’m glad this short post that I put as sidenote for myself still has value for others!
Just came across this today. I have spent countless hours trying to solve the “unable to open device” message in Motioneye. This solved it for me. Had to follow the update by JP and use the “by-path” directory. To add a camera I selected Local v4l2 camera as Camera Type and MML Service 16.1 for Camera. Thanks so much for the post.
I’m glad this tiny blogpost is still relevant and helpful!