Skip to content

Commit

Permalink
consistent use of mjpg-streamer
Browse files Browse the repository at this point in the history
  • Loading branch information
LongLiveCHIEF committed Sep 20, 2020
1 parent d645c29 commit 3b31acb
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ RUN make install
# Copy services into s6 servicedir and set default ENV vars
COPY root /
ENV CAMERA_DEV /dev/video0
ENV MJPEG_STREAMER_INPUT -y -n -r 640x480
ENV MJPG_STREAMER_INPUT -y -n -r 640x480
ENV PIP_USER true
ENV PYTHONUSERBASE /octoprint/plugins

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ launch of OctoPrint using docker.
#### Enabling Webcam Support with Docker

In order to use the webcam, you'll need to make sure the webcam service is enabled.
This is done by setting the environment variable `ENABLE_MJPEG_STREAMER=true` in your
This is done by setting the environment variable `ENABLE_MJPG_STREAMER=true` in your
`docker run` command, or in the `docker-compose.yml` file.

You'll also need to add `--device /dev/video0:/dev/video0` to your `docker run`, or ensure
Expand Down Expand Up @@ -66,11 +66,11 @@ and if you wish to change them, refer to the docker-compose docs on setting envi
| variable | default |
| -------- | ------- |
| `CAMERA_DEV` | `/dev/video0` (see [note](#devices_note)) |
| `MJPEG_STREAMER_INPUT` | `-y -n -r 640x48` |
| `ENABLE_MJPEG_STREAMER` | `false` |
| `MJPG_STREAMER_INPUT` | `-y -n -r 640x48` |
| `ENABLE_MJPG_STREAMER` | `false` |

**note:** You will still need to declare the `device` mapping in your docker-compose file or docker command,
even if you explicitly declare the `CAMERA_DEV`. The value of `CAMERA_DEV` is used in starting the mjpeg-streamer
even if you explicitly declare the `CAMERA_DEV`. The value of `CAMERA_DEV` is used in starting the mjpg-streamer
service, whereas the `devices` mapping is used by docker to make sure the container has access to the device.

For example, if you change the `CAMERA_DEV` to be `/dev/video1`, you would also need to map `/dev/video1:/dev/video1`
Expand Down Expand Up @@ -110,7 +110,7 @@ on the host, and then start your container:

```
docker volume create octoprint
docker run -d -v octoprint:/octoprint --device /dev/ttyACM0:/dev/ttyACM0 --device /dev/video0:/dev/video0 -e ENABLE_MJPEG_STREAMER=true -p 80:80 --name octoprint octoprint/octoprint
docker run -d -v octoprint:/octoprint --device /dev/ttyACM0:/dev/ttyACM0 --device /dev/video0:/dev/video0 -e ENABLE_MJPG_STREAMER=true -p 80:80 --name octoprint octoprint/octoprint
```

[code-server]: https://github.com/cdr/code-server
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ services:
# uncomment the lines below to ensure camera streaming is enabled when
# you add a video device
#environment:
# - ENABLE_MJPEG_STREAMER=true
# - ENABLE_MJPG_STREAMER=true

####
# uncomment if you wish to edit the configuration files of octoprint
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/with-contenv bash

: "${ENABLE_MJPEG_STREAMER:=false}"
: "${ENABLE_MJPG_STREAMER:=false}"

# disable mjpg-streamer service if not enabled
if ! $ENABLE_MJPEG_STREAMER; then
if ! $ENABLE_MJPG_STREAMER; then
rm -rf /etc/services.d/mjpg-streamer
fi
Empty file.
12 changes: 6 additions & 6 deletions root/etc/services.d/mjpg-streamer/run
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/usr/bin/with-contenv sh

if [ -n "$STREAMER_FLAGS" ]; then
echo "Deprecation warning: the environment variable '\$STREAMER_FLAGS' was renamed to '\$MJPEG_STREAMER_INPUT'"
if [ -n "$MJPEG_STREAMER_INPUT" ]; then
echo "Deprecation warning: the environment variable '\$MJPEG_STREAMER_INPUT' was renamed to '\$MJPG_STREAMER_INPUT'"

MJPEG_STREAMER_INPUT=$STREAMER_FLAGS
MJPG_STREAMER_INPUT=$MJPEG_STREAMER_INPUT
fi

if ! expr "$MJPEG_STREAMER_INPUT" : ".*\.so.*" > /dev/null; then
MJPEG_STREAMER_INPUT="input_uvc.so $MJPEG_STREAMER_INPUT"
if ! expr "$MJPG_STREAMER_INPUT" : ".*\.so.*" > /dev/null; then
MJPG_STREAMER_INPUT="input_uvc.so $MJPG_STREAMER_INPUT"
fi

exec mjpg_streamer \
-i "/usr/local/lib/mjpg-streamer/$MJPEG_STREAMER_INPUT -d $CAMERA_DEV" \
-i "/usr/local/lib/mjpg-streamer/$MJPG_STREAMER_INPUT -d $CAMERA_DEV" \
-o "/usr/local/lib/mjpg-streamer/output_http.so -w /usr/local/share/mjpg-streamer/www -p 8080"

0 comments on commit 3b31acb

Please sign in to comment.