feat: make streamer images user customizable

create a volume and allow custom images to be "streamed" by webcamd

Signed-off-by: Dominik Willner th33xitus@gmail.com
This commit is contained in:
th33xitus 2022-06-18 14:29:23 +02:00
parent bdcce5291a
commit 520d5062db
5 changed files with 75 additions and 27 deletions

View File

@ -112,6 +112,7 @@ COPY --from=builder --chown=printer:printer /build/simulavr ./simulavr
COPY --from=builder --chown=printer:printer /build/simulavr.elf ./simulavr.elf COPY --from=builder --chown=printer:printer /build/simulavr.elf ./simulavr.elf
COPY --from=builder --chown=printer:printer /build/mjpg-streamer/mjpg-streamer-experimental ./mjpg-streamer COPY --from=builder --chown=printer:printer /build/mjpg-streamer/mjpg-streamer-experimental ./mjpg-streamer
# Copy example configs and dummy streamer images
COPY ./example-configs/ ./example-configs/ COPY ./example-configs/ ./example-configs/
COPY ./mjpg_streamer_images/ ./mjpg_streamer_images/ COPY ./mjpg_streamer_images/ ./mjpg_streamer_images/

View File

@ -9,12 +9,12 @@
### Setup Instructions: ### Setup Instructions:
1. Clone this repository 1. Clone this repository
2. Open a terminal in the cloned folder 2. Open a terminal in the cloned folder
3. Run `docker-compose up -d` to build the docker image and start the container afterwards in detached mode 3. Run `docker-compose up -d` to build the docker image and start the container in detached mode
--- ---
### Configure a Dummy-Webcam: ### Configure a Dummy-Webcam:
To configure a dummy-webcam, use the following URLs: \ To configure a dummy-webcam, use the following URLs:
* Stream: `http://localhost:8110/?action=stream` * Stream: `http://localhost:8110/?action=stream`
* Snapshot: `http://localhost:8110/?action=snapshot` * Snapshot: `http://localhost:8110/?action=snapshot`

View File

@ -46,7 +46,7 @@ autorestart=true
redirect_stderr=true redirect_stderr=true
[program:webcamd] [program:webcamd]
command=/home/printer/mjpg-streamer/mjpg_streamer -i "input_file.so -e -d 0.8 -f /home/printer/mjpg-streamer/images" -o "output_http.so -w /home/printer/mjpg-streamer/www" command=/home/printer/mjpg-streamer/mjpg_streamer -i "input_file.so -e -d 0.8 -f /home/printer/webcam_images" -o "output_http.so -w /home/printer/mjpg-streamer/www"
user=printer user=printer
process_name=webcamd process_name=webcamd
directory=/home/printer directory=/home/printer

View File

@ -10,7 +10,7 @@ services:
- ./printer_storage/gcode_files:/home/printer/gcode_files:delegated - ./printer_storage/gcode_files:/home/printer/gcode_files:delegated
- ./printer_storage/klipper_config:/home/printer/klipper_config:delegated - ./printer_storage/klipper_config:/home/printer/klipper_config:delegated
- ./printer_storage/klipper_logs:/home/printer/klipper_logs:delegated - ./printer_storage/klipper_logs:/home/printer/klipper_logs:delegated
- ./printer_storage/webcam_images:/home/printer/mjpg-streamer/images:delegated - ./printer_storage/webcam_images:/home/printer/webcam_images:delegated
ports: ports:
- "7125:7125" - "7125:7125"
- "8110:8080" - "8110:8080"

View File

@ -1,31 +1,78 @@
#!/bin/bash #!/usr/bin/env bash
[ ! -e /bin/systemctl ] && sudo -S ln -s /bin/true /bin/systemctl
cd ~ || exit #=======================================================================#
[ ! -d ~/klipper_config ] && mkdir klipper_config # Copyright (C) 2022 mainsail-crew <https://github.com/mainsail-crew> #
[ ! -d ~/klipper_logs ] && mkdir klipper_logs # Author: Dominik Willner <th33xitus@gmail.com> #
[ ! -d ~/gcode_files ] && mkdir gcode_files # #
[ ! -d ~/webcam_images ] && mkdir webcam_images # This file is part of virtual-klipper-printer #
[ ! -d ~/.moonraker_database ] && mkdir .moonraker_database # https://github.com/mainsail-crew/virtual-klipper-printer #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
if find ~/klipper_config -type d -empty; then set -e
cd ~/example-configs || exit 1
sudo cp -r ./* ~/klipper_config
fi
if find ~/webcam_images -type d -empty; then REQUIRED_FOLDERS=(
cd ~/mjpg_streamer_images || exit 1 "${HOME}/klipper_config"
sudo cp -r ./* ~/webcam_images "${HOME}/klipper_logs"
fi "${HOME}/gcode_files"
"${HOME}/webcam_images"
"${HOME}/.moonraker_database"
)
sudo chown -R printer:printer ~/klipper_config function status_msg() {
sudo chown -R printer:printer ~/klipper_logs echo "###[$(date +%T)]: ${1}"
sudo chown -R printer:printer ~/gcode_files }
sudo chown -R printer:printer ~/webcam_images
sudo chown -R printer:printer ~/.moonraker_database ######
# Test for correct ownership of all required folders
###
function check_folder_perms() {
status_msg "Check folders permissions ..."
for folder in "${REQUIRED_FOLDERS[@]}"; do
if [[ $(stat -c "%U" "${folder}") != "printer" ]]; then
status_msg "chown for user: 'printer' on folder: ${folder}"
sudo chown printer:printer "${folder}"
fi
done
status_msg "OK!"
}
######
# Copy example configs if ~/klipper_config is empty
###
function copy_example_configs() {
if [[ ! "$(ls -A "${HOME}/klipper_config")" ]]; then
status_msg "Directory ${HOME}/klipper_config is empty!"
status_msg "Copy example configs ..."
cp -R ~/example-configs/* ~/klipper_config
status_msg "OK!"
fi
}
######
# Copy dummy images if ~/webcam_images is empty
###
function copy_dummy_images() {
if [[ ! "$(ls -A "${HOME}/webcam_images")" ]]; then
status_msg "Directory ${HOME}/webcam_images is empty!"
status_msg "Copy dummy images ..."
cp -R ~/mjpg_streamer_images/*.jpg ~/webcam_images
status_msg "OK!"
fi
}
#===================================================#
#===================================================#
[[ ! -e /bin/systemctl ]] && sudo -S ln -s /bin/true /bin/systemctl
check_folder_perms
copy_example_configs
copy_dummy_images
sudo -S rm /bin/systemctl sudo -S rm /bin/systemctl
sudo -S ln -s /bin/service_control /bin/systemctl sudo -S ln -s /bin/service_control /bin/systemctl
cd ~ && echo "Everything is ready ... Starting ..." cd ~ && status_msg "Everything is ready! Starting ..."
/usr/bin/supervisord /usr/bin/supervisord