Skip to content

Commit

Permalink
Merge pull request #88 from OctoPrint/feature-optional-mjpeg-streamer…
Browse files Browse the repository at this point in the history
…-startup

Feature optional mjpeg streamer startup
  • Loading branch information
LongLiveCHIEF authored Sep 20, 2020
2 parents f3d6f1e + 3b31acb commit 974a677
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ config/logs
config/timelapse
config/uploads
buildtest
compose.test.yml
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
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,17 @@ buildx-camera:
--cache-to ${CACHE} \
--build-arg OCTOPRINT_BASE_IMAGE=1.4.2 \
--progress plain -t octoprint/octoprint:ci-camera -f ./camera/Dockerfile.camera .

test-up:
docker-compose -f compose.test.yml up -d
@docker-compose -f compose.test.yml logs -f octoprint

test-stop:
@docker-compose -f compose.test.yml stop

test-start:
docker-compose -f compose.test.yml start
@docker-compose -f compose.test.yml logs -f octoprint

test-clean:
docker-compose -f compose.test.yml down
37 changes: 31 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ same out of the box features as the octopi raspberry-pi machine image, using doc

- `latest`, `1.4.2`, `1.4`, `1` ([Dockerfile](Dockerfile))

- [OctoPrint-docker](#octoprint-docker)
- [Tags](#tags)
- [Usage](#usage)
- [Configuration](#configuration)
- [Enabling Webcam Support with Docker](#enabling-webcam-support-with-docker)
- [Webcam Setup in OctoPrint](#webcam-setup-in-octoprint)
- [Container Environment based configs](#container-environment-based-configs)
- [Editing Config files manually](#editing-config-files-manually)
- [Without docker-compose](#without-docker-compose)

## Usage

We recommend you use docker-compose to run octoprint via docker, and have included
Expand All @@ -22,7 +32,22 @@ launch of OctoPrint using docker.

### Configuration

#### Initial Setup
#### 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_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
it's listed in the `devices` array in your `docker-compose.yml`.

If you map a video device _other_ than `/dev/video0`, you will additionally need to set an
environment variable for `CAMERA_DEV` to match the mapped device mapping.

See [container environment based configs](#container-environment-based-configs) for a full
list of webcam configuration options configured with docker.

#### Webcam Setup in OctoPrint

Use the following values in the webcam & timelapse settings screen of the initial setup:

Expand All @@ -32,7 +57,7 @@ Use the following values in the webcam & timelapse settings screen of the initia
| Snapshot URL | `http://localhost:8080/?action=snapshot` |
| Path to FFMPEG | `/usr/bin/ffmpeg` |

### Container Environment based configs
#### Container Environment based configs

There are configuration values that you pass using container `--environment` options.
Listed below are the options and their defaults. These are implicit in example [docker-compose.yml](docker-compose.yml),
Expand All @@ -41,10 +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` |
| `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 @@ -84,8 +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 -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
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ services:
# - /dev/video0:/dev/video0
volumes:
- octoprint:/octoprint
# uncomment the lines below to ensure camera streaming is enabled when
# you add a video device
#environment:
# - ENABLE_MJPG_STREAMER=true

####
# uncomment if you wish to edit the configuration files of octoprint
Expand Down
8 changes: 8 additions & 0 deletions root/etc/cont-init.d/01-mjpg-streamer-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/with-contenv bash

: "${ENABLE_MJPG_STREAMER:=false}"

# disable mjpg-streamer service if not enabled
if ! $ENABLE_MJPG_STREAMER; then
rm -rf /etc/services.d/mjpg-streamer
fi
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 974a677

Please sign in to comment.