Skip to content

Commit 974a677

Browse files
Merge pull request #88 from OctoPrint/feature-optional-mjpeg-streamer-startup
Feature optional mjpeg streamer startup
2 parents f3d6f1e + 3b31acb commit 974a677

File tree

7 files changed

+65
-13
lines changed

7 files changed

+65
-13
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ config/logs
44
config/timelapse
55
config/uploads
66
buildtest
7+
compose.test.yml

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ RUN make install
7272
# Copy services into s6 servicedir and set default ENV vars
7373
COPY root /
7474
ENV CAMERA_DEV /dev/video0
75-
ENV MJPEG_STREAMER_INPUT -y -n -r 640x480
75+
ENV MJPG_STREAMER_INPUT -y -n -r 640x480
7676
ENV PIP_USER true
7777
ENV PYTHONUSERBASE /octoprint/plugins
7878

Makefile

+14
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,17 @@ buildx-camera:
5959
--cache-to ${CACHE} \
6060
--build-arg OCTOPRINT_BASE_IMAGE=1.4.2 \
6161
--progress plain -t octoprint/octoprint:ci-camera -f ./camera/Dockerfile.camera .
62+
63+
test-up:
64+
docker-compose -f compose.test.yml up -d
65+
@docker-compose -f compose.test.yml logs -f octoprint
66+
67+
test-stop:
68+
@docker-compose -f compose.test.yml stop
69+
70+
test-start:
71+
docker-compose -f compose.test.yml start
72+
@docker-compose -f compose.test.yml logs -f octoprint
73+
74+
test-clean:
75+
docker-compose -f compose.test.yml down

README.md

+31-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ same out of the box features as the octopi raspberry-pi machine image, using doc
77

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

10+
- [OctoPrint-docker](#octoprint-docker)
11+
- [Tags](#tags)
12+
- [Usage](#usage)
13+
- [Configuration](#configuration)
14+
- [Enabling Webcam Support with Docker](#enabling-webcam-support-with-docker)
15+
- [Webcam Setup in OctoPrint](#webcam-setup-in-octoprint)
16+
- [Container Environment based configs](#container-environment-based-configs)
17+
- [Editing Config files manually](#editing-config-files-manually)
18+
- [Without docker-compose](#without-docker-compose)
19+
1020
## Usage
1121

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

2333
### Configuration
2434

25-
#### Initial Setup
35+
#### Enabling Webcam Support with Docker
36+
37+
In order to use the webcam, you'll need to make sure the webcam service is enabled.
38+
This is done by setting the environment variable `ENABLE_MJPG_STREAMER=true` in your
39+
`docker run` command, or in the `docker-compose.yml` file.
40+
41+
You'll also need to add `--device /dev/video0:/dev/video0` to your `docker run`, or ensure
42+
it's listed in the `devices` array in your `docker-compose.yml`.
43+
44+
If you map a video device _other_ than `/dev/video0`, you will additionally need to set an
45+
environment variable for `CAMERA_DEV` to match the mapped device mapping.
46+
47+
See [container environment based configs](#container-environment-based-configs) for a full
48+
list of webcam configuration options configured with docker.
49+
50+
#### Webcam Setup in OctoPrint
2651

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

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

35-
### Container Environment based configs
60+
#### Container Environment based configs
3661

3762
There are configuration values that you pass using container `--environment` options.
3863
Listed below are the options and their defaults. These are implicit in example [docker-compose.yml](docker-compose.yml),
@@ -41,10 +66,11 @@ and if you wish to change them, refer to the docker-compose docs on setting envi
4166
| variable | default |
4267
| -------- | ------- |
4368
| `CAMERA_DEV` | `/dev/video0` (see [note](#devices_note)) |
44-
| `MJPEG_STREAMER_INPUT` | `-y -n -r 640x48` |
69+
| `MJPG_STREAMER_INPUT` | `-y -n -r 640x48` |
70+
| `ENABLE_MJPG_STREAMER` | `false` |
4571

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

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

85111
```
86112
docker volume create octoprint
87-
docker run -d -v octoprint:/octoprint --device /dev/ttyACM0:/dev/ttyACM0 --device /dev/video0:/dev/video0 -p 80:80 --name octoprint octoprint/octoprint
88-
113+
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
89114
```
90115

91116
[code-server]: https://github.com/cdr/code-server

docker-compose.yml

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ services:
1111
# - /dev/video0:/dev/video0
1212
volumes:
1313
- octoprint:/octoprint
14+
# uncomment the lines below to ensure camera streaming is enabled when
15+
# you add a video device
16+
#environment:
17+
# - ENABLE_MJPG_STREAMER=true
1418

1519
####
1620
# uncomment if you wish to edit the configuration files of octoprint
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/with-contenv bash
2+
3+
: "${ENABLE_MJPG_STREAMER:=false}"
4+
5+
# disable mjpg-streamer service if not enabled
6+
if ! $ENABLE_MJPG_STREAMER; then
7+
rm -rf /etc/services.d/mjpg-streamer
8+
fi

root/etc/services.d/mjpg-streamer/run

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#!/usr/bin/with-contenv sh
22

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

6-
MJPEG_STREAMER_INPUT=$STREAMER_FLAGS
6+
MJPG_STREAMER_INPUT=$MJPEG_STREAMER_INPUT
77
fi
88

9-
if ! expr "$MJPEG_STREAMER_INPUT" : ".*\.so.*" > /dev/null; then
10-
MJPEG_STREAMER_INPUT="input_uvc.so $MJPEG_STREAMER_INPUT"
9+
if ! expr "$MJPG_STREAMER_INPUT" : ".*\.so.*" > /dev/null; then
10+
MJPG_STREAMER_INPUT="input_uvc.so $MJPG_STREAMER_INPUT"
1111
fi
1212

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

0 commit comments

Comments
 (0)