Skip to content

Commit 7ce5478

Browse files
rickstaaclaude
andauthored
box: add webcam input and fix bash conditionals (#3882)
Add INPUT_WEBCAM env var to stream.sh for using a webcam (e.g. /dev/video0) as video input via v4l2. Document both video file and webcam input options in box.md. --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ad7d5e4 commit 7ce5478

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

box/box.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@ export RTMP_OUTPUT=rtmp://rtmp.livepeer.com/live/$STREAM_KEY
8484

8585
This one is only required for the `box-stream` command. It is useful when you cannot use the `box-playback` command to play the stream, for example when you are using a remote non-UI machine.
8686

87+
### Video Input
88+
89+
By default, `box-stream` uses a generated test pattern. You can use a video file or webcam instead:
90+
91+
```bash
92+
# Use a video file
93+
export INPUT_VIDEO=/path/to/video.mp4
94+
95+
# Or use a webcam (Linux)
96+
export INPUT_WEBCAM=/dev/video0
97+
```
98+
8799
### Docker
88100
If you want to run the box in a docker container, set the `DOCKER` env var:
89101
```bash

box/box.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ set -e
44
DOCKER=${DOCKER:-false}
55
FRONTEND=${FRONTEND:-false}
66

7-
if [ "$FRONTEND" = "true" && "$DOCKER" = "false" ]; then
7+
if [[ "$FRONTEND" = "true" && "$DOCKER" = "false" ]]; then
88
echo "Running the box with FRONTEND=true requires DOCKER=true"
99
exit 1
1010
fi
1111

1212
# Ensure backgrounded services are stopped gracefully when this script is interrupted or exits.
1313
cleanup() {
14-
if [ "$DOCKER" = "true" ]; then
14+
if [[ "$DOCKER" = "true" ]]; then
1515
echo "Stopping dockerized services..."
1616
docker stop orchestrator --time 15 >/dev/null 2>&1 || true
1717
docker stop gateway --time 15 >/dev/null 2>&1 || true
@@ -51,7 +51,7 @@ gateway &
5151
orchestrator &
5252
mediamtx &
5353

54-
if [ "$FRONTEND" = "true" ]; then
54+
if [[ "$FRONTEND" = "true" ]]; then
5555
supabase &
5656
frontend &
5757
fi

box/stream.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ STREAM_ID="my-stream-id"
77
RTMP_OUTPUT=${RTMP_OUTPUT:-""}
88
FPS=${FPS:-30}
99
INPUT_VIDEO=${INPUT_VIDEO:-""}
10+
INPUT_WEBCAM=${INPUT_WEBCAM:-""}
1011

1112
case "$1" in
1213
start)
@@ -22,7 +23,11 @@ case "$1" in
2223

2324
INPUT_FLAGS="-f lavfi -i testsrc=size=1280x720:rate=${FPS},format=yuv420p"
2425
if [ -n "$INPUT_VIDEO" ]; then
26+
echo "Using video file: ${INPUT_VIDEO}"
2527
INPUT_FLAGS="-stream_loop -1 -i ${INPUT_VIDEO}"
28+
elif [ -n "$INPUT_WEBCAM" ]; then
29+
echo "Using webcam: ${INPUT_WEBCAM}"
30+
INPUT_FLAGS="-f v4l2 -framerate ${FPS} -video_size 1280x720 -i ${INPUT_WEBCAM}"
2631
fi
2732

2833
ffmpeg -re ${INPUT_FLAGS} \

0 commit comments

Comments
 (0)