-#!/bin/sh
+#:/usr/bin/env bash
-# Start TeleCaster video channel
+set -e
-VIDEO_ID=0
-AUDIO_CHANNELS=2
+# Default TeleCaster video parameters
+
+# v4l2
+V4L2_ID=0
+V4L2_ZOOM=140
# C920
-#WIDTH=864
-#HEIGHT=480
+#VIDEO_WIDTH=864
+#VIDEO_HEIGHT=480
+#VIDEO_FRAMERATE=24
# C922
-WIDTH=848
-HEIGHT=480
+VIDEO_WIDTH=848
+VIDEO_HEIGHT=480
+VIDEO_FRAMERATE=24
-#WIDTH=1280
-#HEIGHT=720
+# Audio
+AUDIO_CHANNELS=2
+AUDIO_OPUS_BITRATE=96000
-FRAMERATE=24
+if [ -f .env ]; then
+ source .env
+fi
-v4l2-ctl -d $VIDEO_ID -c power_line_frequency=1
-v4l2-ctl -d $VIDEO_ID -c zoom_absolute=140
-v4l2-ctl -d $VIDEO_ID -c focus_auto=0
-v4l2-ctl -d $VIDEO_ID -c focus_absolute=1
-v4l2-ctl -d $VIDEO_ID -c sharpness=128
+v4l2-ctl -d $V4L2_ID -c power_line_frequency=1
+v4l2-ctl -d $V4L2_ID -c zoom_absolute=$V4L2_ZOOM
+v4l2-ctl -d $V4L2_ID -c focus_auto=0
+v4l2-ctl -d $V4L2_ID -c focus_absolute=1
+v4l2-ctl -d $V4L2_ID -c sharpness=128
# ! queue ! videoflip method=rotate-180 \
-gst-launch-1.0 v4l2src device=/dev/video$VIDEO_ID ! video/x-raw, format=YUY2, width=$WIDTH, height=$HEIGHT, framerate=$FRAMERATE/1 \
+gst-launch-1.0 v4l2src device=/dev/video$V4L2_ID ! video/x-raw, format=YUY2, width=$VIDEO_WIDTH, height=$VIDEO_HEIGHT, framerate=$VIDEO_FRAMERATE/1 \
! queue ! videoflip method=rotate-180 \
! queue ! videoconvert \
! queue ! vp8enc threads=4 deadline=2 \
! queue ! rgvolume pre-amp=12.0 \
! queue ! rglimiter \
! queue ! audioconvert \
- ! queue ! opusenc bitrate=96000 \
+ ! queue ! opusenc bitrate=$AUDIO_OPUS_BITRATE \
! queue ! muxout. \
webmmux streamable=true name=muxout \
! queue ! tcpserversink host=127.0.0.1 port=9000 blocksize=65536 sync-method=1 \