summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/stream31
1 files changed, 20 insertions, 11 deletions
diff --git a/bin/stream b/bin/stream
index 4b2f3e7..536e4d6 100755
--- a/bin/stream
+++ b/bin/stream
@@ -78,22 +78,31 @@ ACHANNELS=2
AFRAMERATE=48000
ABITRATE=32000
-HEIGHT=360
+HEIGHTS_WEBM=360
+HEIGHTS_MPEG=360
VBITRATE=256000
+HEIGHTS=$(echo "$HEIGHTS_WEBM $HEIGHTS_MPEG" | tr ' ' '\012' | sort -u)
+HEIGHTCOUNT=$(echo "$HEIGHTS" | wc --words)
+
# FIXME: support multiple heights
-HEIGHTCOUNT=1
-height=$HEIGHT
-MKWEBM="[v${height}webm]"
-MKMPEG="[v${height}mpeg]"
+height=$HEIGHTS
VCODECCOUNT=
-[ -z "$MKWEBM" ] || VCODECCOUNT=$((VCODECCOUNT+1))
-[ -z "$MKMPEG" ] || VCODECCOUNT=$((VCODECCOUNT+1))
+[ -z "$HEIGHTS_WEBM" ] || VCODECCOUNT=$((VCODECCOUNT+1))
+[ -z "$HEIGHTS_MPEG" ] || VCODECCOUNT=$((VCODECCOUNT+1))
[ -z "${SAVEDIR:-}" ] || SAVESTEM="${SAVEDIR:-}/$(date +%Y%m%d-%H%M%S)"
[ -z "${SAVEDIR:-}" ] || export FFREPORT=file="$SAVESTEM.log"
+# shellcheck disable=SC2048,SC2059
+printf_each() {
+ skel=$1; shift
+ for height in $*; do
+ printf "$skel" "$height"
+ done
+}
+
# * scale+watermark trick based on http://stackoverflow.com/a/10937357
# * routing based on http://trac.ffmpeg.org/wiki/Creating%20multiple%20outputs#Teepseudo-muxer
# * VP8 encoding based on http://www.webmproject.org/docs/encoder-parameters/#real-time-cbr-encoding-and-streaming
@@ -107,16 +116,16 @@ ffmpeg -hide_banner -threads auto -re \
${VFILE:+-i "$VFILE"} \
${LOGO:+-i "$LOGO"} \
${HASVIDEO:+-filter_complex \
- "[$VSTREAMINDEX:v]split=$HEIGHTCOUNT[s$height];
+ "[$VSTREAMINDEX:v]split=$HEIGHTCOUNT$(printf_each '[s%s]' "$HEIGHTS");
[s$height]scale=-2:$height${WATERMARK:-[v$height]}${WATERMARK:+[bg$height]${LOGO:+;
[bg$height][$((VSTREAMINDEX+1)):v]overlay=main_w-overlay_w-20:main_h-overlay_h-20[v$height]}};
- [v$height]split=$VCODECCOUNT$MKWEBM$MKMPEG" } \
+ [v$height]split=$VCODECCOUNT$(printf_each '[v%swebm]' "$HEIGHTS_WEBM")$(printf_each '[v%smpeg]' "$HEIGHTS_MPEG")" } \
${SAVEDIR:+-map '0:' ${TWOSOURCES:+-map '1:'} \
-codec copy \
-f segment -segment_format matroska -segment_format_options live=1:reserve_index_space=512kB \
-segment_list "$SAVESTEM.ffconcat" -segment_list_flags live \
-segment_time 600 -segment_atclocktime 1 -strftime 1 "$SAVESTEM-%H%M.mkv"} \
- ${MKWEBM:+\
+ ${HEIGHTS_WEBM:+\
${HASAUDIO:+-map '0:a' } ${HASVIDEO:+-map "[v${height}webm]" } \
${HASAUDIO:+\
-codec:a libopus -ac "$ACHANNELS" -ar "$AFRAMERATE" -b:a "$ABITRATE" } \
@@ -130,7 +139,7 @@ ffmpeg -hide_banner -threads auto -re \
-f tee \
"${HASAUDIO:+[select=\'a\':f=rtp:payload_type=111]rtp://$IP:$FIRSTPORT?pkt_size=1200| \
}${HASVIDEO:+[select=\'v\':f=rtp:payload_type=100]rtp://$IP:$((FIRSTPORT+2))?pkt_size=1200}" } \
- ${MKMPEG:+\
+ ${HEIGHTS_MPEG:+\
${HASAUDIO:+-map '0:a' } ${HASVIDEO:+-map "[v${height}mpeg]" } \
${HASAUDIO:+\
-codec:a aac -strict experimental -ac "$ACHANNELS" -ar 44100 -b:a $((ACHANNELS*64))k } \