Support for local devices?
Closed this issue · 7 comments
I have a RPI camera and a USB Webcam connected to the device that's running the docker container.
Can I access these?
Hello
Local devices are not supported for now but this is something I'm working on. I'll let you know when it's supported.
So I don't think it's easily possible to handle the local camera; at least, I tried with code, and I wasn't successful.
The issue with the local camera is that the device (usually /dev/video0
) cannot be directly displayed in the browser. You need to go through a streaming server (I recommend ustreamer) that will capture the camera's stream and broadcast it in MJPEG format.
Good news is that ustreamer is available as a docker container, here is how to set it up easily:
- Start by destroying the current
motionui
container (we'll recreate it afterward):
docker rm -f motionui
- Create a dedicated docker network for the
motionui
andustreamer
containers. This network will allow the containers to communicate with each other:
docker network create --driver bridge motionui-network
- Create the
ustreamer
container by adapting the resolution, fps and quality parameters according to your needs.
Here, I'm sharing the/dev/video0
device (local camera) with the container (normally this will also be your device) and I'm integrating the container into themotionui-network
.
docker run -d --restart always --network motionui-network --name ustreamer \
--device /dev/video0:/dev/video0 \
pikvm/ustreamer:latest \
--resolution 1280x720 \
--desired-fps 25 \
--quality 95 \
--format MJPEG \
--device-timeout 2 \
--device-error-delay 1
- Recreate the
motionui
container and also integrate it into themotionui-network
(adapt the FQDN parameter to your needs):
docker run -d --restart always --network motionui-network --name motionui \
-e FQDN=motionui.example.com \
-p 8080:8080 \
-v /etc/localtime:/etc/localtime:ro \
-v /var/lib/docker/volumes/motionui-data:/var/lib/motionui \
-v /var/lib/docker/volumes/motionui-captures:/var/lib/motion \
lbr38/motionui:latest
- Check that the containers are running:
docker ps
- You can also check that both containers are in the same network:
docker network inspect motionui-network
- Now you can add the camera to motion-UI web interface by specifying the URL of the stream
http://ustreamer:8080/stream
and specifying the same resolution as you did for the ustreamer container.
I tested this setup locally with my laptop's camera, and it works fine.
Tell me if this works for you and I'll add it to the documentation as the official way to use a local camera.
More info on ustreamer: https://github.com/pikvm/ustreamer
Thanks. I'm slightly confused as I thought that was the point of Motion? https://raspberry-valley.azurewebsites.net/Streaming-Video-with-Motion/
I'll investigate ustreamer as an alternative though. Thanks for the writeup.
You are right, but using the motion service for streaming would require the motion service to run continuously to obtain the real-time image (on the stream page).
And if the motion service runs continuously, it includes continuous motion detection. I want to give the user the choice to view the stream in real-time without necessarily activating motion detection. That's why I am not inclined to use motion service for streaming.
The fact is that motion-UI is more suitable for use with remote IP cameras that broadcast an MJPEG video stream.
Perhaps I may be missing something, and I might find a simpler solution in the future, but for now, I recommend using ustreamer to turn your local camera into a kind of remote camera.
I'll let you know if I find a better solution in the future ;)
No problem, makes sense. I'll give ustreamer a go.
Have you been able to create a docker network and put both containers in this network?
Because if the ustreamer
container is in the same docker network as the motionui
container then the motionui
container should be able to reach ustreamer without need to know its IP but using its container name (ustreamer
). It's just like an hostname.
ustreamer is streaming through the 8080 port, so motionui should reach the stream at http://ustreamer:8080/stream
just like in my capture.