diff options
author | Jonas Smedegaard <dr@jones.dk> | 2017-05-07 00:54:29 +0200 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2017-05-07 00:55:25 +0200 |
commit | ad977a6874a78f41a04ea4deb1e258fc2d1e376d (patch) | |
tree | 4680de2ad058536136cf559a620cb16c4dfb55dd | |
parent | 3da59131e3e74d493c9e28589d79569a3dad668d (diff) |
Generalize filters.
-rwxr-xr-x | bin/stream | 45 |
1 files changed, 33 insertions, 12 deletions
@@ -78,6 +78,7 @@ ACHANNELS=2 AFRAMERATE=48000 ABITRATE=32000 +# FIXME: support multiple heights HEIGHTS_WEBM=360 HEIGHTS_MPEG=360 VBITRATE=256000 @@ -96,20 +97,40 @@ printf_each() { uniqwords() { echo "$@" | tr ' ' '\012' | sort -u } +valuedargcount() { + nonempty= + while [ $# -gt 0 ]; do + [ -z "$1" ] || nonempty=$((nonempty+1)) + shift + done + echo_n "$nonempty" +} HEIGHTS=$(uniqwords "$HEIGHTS_WEBM $HEIGHTS_MPEG") -HEIGHTCOUNT=$(echo "$HEIGHTS" | wc --words) - -# FIXME: support multiple heights -height=$HEIGHTS - -VCODECCOUNT= -[ -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" +filter_split_height() { + heightcount=$(echo "$HEIGHTS" | wc --words) + echo_n "[$VSTREAMINDEX:v]split=$heightcount" + printf_each '[s%s]' "$HEIGHTS" +} +filter_scale() { outstem=${1:-v}; + for height in $HEIGHTS; do + echo_n "[s$height]scale=-2:$height[$outstem$height]" + done +} +filter_watermark() { + for height in $HEIGHTS; do + echo_n "[bg$height][$((VSTREAMINDEX+1)):v]overlay=main_w-overlay_w-20:main_h-overlay_h-20[v$height]" + done +} +filter_split_codec() { heights_webm=$1; heights_mpeg=$2; + codeccount=$(valuedargcount "$@") + printf_each "[v%s]split=$codeccount$(printf_each '[v%swebm]' "$heights_webm")$(printf_each '[v%smpeg]' "$heights_mpeg")" "$HEIGHTS" +} + tee_rtp() { stream=$1; pt=$2; port=$3; echo_n "[select=\'$stream\':f=rtp:payload_type=$pt]rtp://$IP:$port?pkt_size=1200" } @@ -127,10 +148,10 @@ ffmpeg -hide_banner -threads auto -re \ ${VFILE:+-i "$VFILE"} \ ${LOGO:+-i "$LOGO"} \ ${HASVIDEO:+-filter_complex \ - "[$VSTREAMINDEX:v]split=$HEIGHTCOUNT$(printf_each '[s%s]' "$HEIGHTS"); - [s$height]scale=-2:$height${WINPUT:+[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$(printf_each '[v%swebm]' "$HEIGHTS_WEBM")$(printf_each '[v%smpeg]' "$HEIGHTS_MPEG")" } \ + "$(filter_split_height); + $(filter_scale "${WINPUT:+bg}")${WINPUT:+${LOGO:+; + $(filter_watermark)}}; + $(filter_split_codec "$HEIGHTS_WEBM" "$HEIGHTS_MPEG")" } \ ${SAVEDIR:+-map '0:' ${TWOSOURCES:+-map '1:'} \ -codec copy \ -f segment -segment_format matroska -segment_format_options live=1:reserve_index_space=512kB \ |