From cdbf4dee39cdd3dc083299d88d619effc1e72e14 Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Thu, 18 May 2017 09:39:53 +0200 Subject: Generalize encodings as functions. --- bin/loop+encode+stream | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'bin/loop+encode+stream') diff --git a/bin/loop+encode+stream b/bin/loop+encode+stream index 3906552..5893ed3 100755 --- a/bin/loop+encode+stream +++ b/bin/loop+encode+stream @@ -55,6 +55,17 @@ elif [ $BITS -le 921600 ]; then # 720p → 921600 SPEED_VP8=15 fi +encode_opus() { + echo_n "-codec:a libopus -ac $ACHANNELS -ar $AFRAMERATE_OPUS -b:a $ABITRATE_OPUS" +} +encode_vp8() { bitrate=$1; speed=$2; + echo_n "-codec:v vp8 -quality realtime -deadline 1000000 -cpu-used $speed \ + -b:v $bitrate -minrate $bitrate -maxrate $bitrate \ + -undershoot-pct 95 -bufsize $((6000*bitrate/1000)) -rc_init_occupancy $((4000*bitrate/1000)) \ + -max-intra-rate 0 \ + -qmin 4 -qmax 56" +} + # based on http://www.webmproject.org/docs/encoder-parameters/#real-time-cbr-encoding-and-streaming # + Add 1s latency (deadline) # + Use same RTP payload types as GStreamer @@ -62,12 +73,8 @@ ffmpeg -hide_banner -threads auto -re \ -stream_loop -1 -i "$INPUT" \ -vf format=pix_fmts=yuv420p \ -map '0:a' \ - -codec:a libopus -ac "$ACHANNELS" -ar "$AFRAMERATE_OPUS" -b:a "$ABITRATE_OPUS" \ + $(encode_opus) \ -f rtp -payload_type 111 "rtp://$IP:$FIRSTPORT?pkt_size=1200" \ -map '0:v' \ - -codec:v vp8 -quality realtime -deadline 1000000 -cpu-used "$SPEED_VP8" \ - -b:v "$VBITRATE" -minrate "$VBITRATE" -maxrate "$VBITRATE" \ - -undershoot-pct 95 -bufsize $((6000*VBITRATE/1000)) -rc_init_occupancy $((4000*VBITRATE/1000)) \ - -max-intra-rate 0 \ - -qmin 4 -qmax 56 \ + $(encode_vp8 "$VBITRATE" "$SPEED_VP8") \ -f rtp -payload_type 100 "rtp://$IP:$((FIRSTPORT+2))?pkt_size=1200" -- cgit v1.2.3