diff --git a/box/box.md b/box/box.md index c311867b43..4e126c28d7 100644 --- a/box/box.md +++ b/box/box.md @@ -84,6 +84,18 @@ export RTMP_OUTPUT=rtmp://rtmp.livepeer.com/live/$STREAM_KEY 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. +### Video Input + +By default, `box-stream` uses a generated test pattern. You can use a video file or webcam instead: + +```bash +# Use a video file +export INPUT_VIDEO=/path/to/video.mp4 + +# Or use a webcam (Linux) +export INPUT_WEBCAM=/dev/video0 +``` + ### Docker If you want to run the box in a docker container, set the `DOCKER` env var: ```bash diff --git a/box/box.sh b/box/box.sh index cc6fe58876..f190ed1094 100755 --- a/box/box.sh +++ b/box/box.sh @@ -4,14 +4,14 @@ set -e DOCKER=${DOCKER:-false} FRONTEND=${FRONTEND:-false} -if [ "$FRONTEND" = "true" && "$DOCKER" = "false" ]; then +if [[ "$FRONTEND" = "true" && "$DOCKER" = "false" ]]; then echo "Running the box with FRONTEND=true requires DOCKER=true" exit 1 fi # Ensure backgrounded services are stopped gracefully when this script is interrupted or exits. cleanup() { - if [ "$DOCKER" = "true" ]; then + if [[ "$DOCKER" = "true" ]]; then echo "Stopping dockerized services..." docker stop orchestrator --time 15 >/dev/null 2>&1 || true docker stop gateway --time 15 >/dev/null 2>&1 || true @@ -51,7 +51,7 @@ gateway & orchestrator & mediamtx & -if [ "$FRONTEND" = "true" ]; then +if [[ "$FRONTEND" = "true" ]]; then supabase & frontend & fi diff --git a/box/stream.sh b/box/stream.sh index 7ccc72f530..3c80b77a05 100755 --- a/box/stream.sh +++ b/box/stream.sh @@ -7,6 +7,7 @@ STREAM_ID="my-stream-id" RTMP_OUTPUT=${RTMP_OUTPUT:-""} FPS=${FPS:-30} INPUT_VIDEO=${INPUT_VIDEO:-""} +INPUT_WEBCAM=${INPUT_WEBCAM:-""} case "$1" in start) @@ -22,7 +23,11 @@ case "$1" in INPUT_FLAGS="-f lavfi -i testsrc=size=1280x720:rate=${FPS},format=yuv420p" if [ -n "$INPUT_VIDEO" ]; then + echo "Using video file: ${INPUT_VIDEO}" INPUT_FLAGS="-stream_loop -1 -i ${INPUT_VIDEO}" + elif [ -n "$INPUT_WEBCAM" ]; then + echo "Using webcam: ${INPUT_WEBCAM}" + INPUT_FLAGS="-f v4l2 -framerate ${FPS} -video_size 1280x720 -i ${INPUT_WEBCAM}" fi ffmpeg -re ${INPUT_FLAGS} \