diff options
author | Jonas Smedegaard <dr@jones.dk> | 2017-05-18 09:39:53 +0200 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2017-05-18 09:39:53 +0200 |
commit | cdbf4dee39cdd3dc083299d88d619effc1e72e14 (patch) | |
tree | 9b075856b46cdb4a764791c3d9e2afaa0fdc704b /bin/stream | |
parent | 39bc48eb0e8b9a2b8d43d6f1a612c12d0c70ae23 (diff) |
Generalize encodings as functions.
Diffstat (limited to 'bin/stream')
-rwxr-xr-x | bin/stream | 32 |
1 files changed, 22 insertions, 10 deletions
@@ -178,6 +178,24 @@ filter_split_codec() { heights_webm=$1; heights_mpeg=$2; printf_each "[v%s]split=$codeccount$(printf_each '[v%swebm]' "$heights_webm")$(printf_each '[v%smpeg]' "$heights_mpeg")" "$HEIGHTS" } +encode_opus() { + echo_n "-codec:a libopus -ac $ACHANNELS -ar $AFRAMERATE_OPUS -b:a $ABITRATE_OPUS" +} +encode_aac() { + echo_n "-codec:a aac -strict experimental -ac $ACHANNELS -ar $AFRAMERATE_AAC -b:a $((ACHANNELS*ABITRATE_AAC))" +} +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" +} +encode_x264() { bitrate=$1; speed=$2; + echo_n "-codec:v libx264 -preset $speed -tune zerolatency \ + -maxrate $bitrate -bufsize $((bitrate*2)) -crf 23 \ + -force_key_frames 'expr:gte(t,n_forced*2)'" +} tee_rtp() { stream=$1; pt=$2; port=$3; echo_n "[select=\'$stream\':f=rtp:payload_type=$pt]rtp://$IP:$port?pkt_size=1200" } @@ -207,13 +225,9 @@ ffmpeg -hide_banner -threads auto \ ${HEIGHTS_WEBM:+\ ${HASAUDIO:+-map '0:a' }${HASVIDEO:+$(printf_each ' -map [v%swebm]' "$HEIGHTS_WEBM") } -shortest \ ${HASAUDIO:+\ - -codec:a libopus -ac "$ACHANNELS" -ar "$AFRAMERATE_OPUS" -b:a "$ABITRATE_OPUS" } \ + $(encode_opus) } \ ${HASVIDEO:+\ - -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 tee \ "${HASAUDIO:+\ $(tee_rtp a 111 "$FIRSTPORT")|\ @@ -222,9 +236,7 @@ ffmpeg -hide_banner -threads auto \ ${HEIGHTS_MPEG:+\ ${HASAUDIO:+-map '0:a' }${HASVIDEO:+$(printf_each ' -map [v%smpeg]' "$HEIGHTS_MPEG") } -shortest \ ${HASAUDIO:+\ - -codec:a aac -strict experimental -ac "$ACHANNELS" -ar "$AFRAMERATE_AAC" -b:a $((ACHANNELS*ABITRATE_AAC)) } \ + $(encode_aac) } \ ${HASVIDEO:+\ - -codec:v libx264 -preset "$SPEED_X264" -tune zerolatency \ - -maxrate "$VBITRATE" -bufsize "$((VBITRATE*2))" -crf 23 } \ - -force_key_frames 'expr:gte(t,n_forced*2)' \ + $(encode_x264 "$VBITRATE" "$SPEED_X264") } \ -f rtp_mpegts rtp://$IP:10000 } |