From 363f4d522d8ef47dd30537371e7d7ebc53730a48 Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Wed, 17 May 2017 08:44:33 +0200 Subject: Vary x264 speed based on height, and make not on doing same for vpx. --- bin/capture+encode+serve | 46 +++++++++++++++++++++++++++++--------- bin/decode+edit+encode | 1 + bin/decode+edit+loop+encode+stream | 1 + bin/encodevideo+loop+stream | 1 + bin/loop+encode+stream | 1 + bin/stream | 17 ++++++++------ 6 files changed, 50 insertions(+), 17 deletions(-) (limited to 'bin') diff --git a/bin/capture+encode+serve b/bin/capture+encode+serve index e87310f..29688f1 100755 --- a/bin/capture+encode+serve +++ b/bin/capture+encode+serve @@ -47,18 +47,44 @@ my $HEIGHT = 240; my $FRAMERATE = 25; my $AUDIORATE = 48000; -my $SPEED_VPX = 15; -my $SPEED_X264 = 'ultrafast'; - -my $VBITRATE; +# TODO: Vary vpx quality based on height +my $SPEED_VPX = 15; # inspired by Apple HLS recommendations -if ( $HEIGHT le 234 ) { $VBITRATE = 145000 } -elsif ( $HEIGHT le 270 ) { $VBITRATE = 365000 } -elsif ( $HEIGHT le 360 ) { $VBITRATE = 730000 } -elsif ( $HEIGHT le 432 ) { $VBITRATE = 1100000 } -elsif ( $HEIGHT le 540 ) { $VBITRATE = 2000000 } -elsif ( $HEIGHT le 720 ) { $VBITRATE = 3000000 } +# TODO: Externalize to site-specific configfile +my ( $VBITRATE, $SPEED_X264, $SPEED_X264_ALONE ); +if ( $HEIGHT le 234 ) { + $VBITRATE = 145000; + $SPEED_X264 = 'slow'; + $SPEED_X264_ALONE = 'fast'; +} +elsif ( $HEIGHT le 270 ) { + $VBITRATE = 365000; + $SPEED_X264 = 'faster'; + $SPEED_X264_ALONE = 'fast'; +} +elsif ( $HEIGHT le 360 ) { + $VBITRATE = 730000; + $SPEED_X264 = 'faster'; + $SPEED_X264_ALONE = 'fast'; +} +elsif ( $HEIGHT le 432 ) { + $VBITRATE = 1100000; + $SPEED_X264 = 'veryfast'; + $SPEED_X264_ALONE = 'fast'; +} +elsif ( $HEIGHT le 540 ) { + $VBITRATE = 2000000; + $SPEED_X264 = 'toofast'; + $SPEED_X264_ALONE = 'veryfast'; +} +elsif ( $HEIGHT le 720 ) { + $VBITRATE = 3000000; + $SPEED_X264 = 'toofast'; + $SPEED_X264_ALONE = 'ultrafast'; +} +unless ($HEIGHTS_WEBM) { $SPEED_X264 = $SPEED_X264_ALONE } +if ( toofast == $SPEED_X264 ) die "Not enough CPU - reduce size or streams"; my $VCAPS = "video/x-raw,height=$HEIGHT"; my $ACAPS = "audio/x-raw,rate=$AUDIORATE,channels=2,depth=16"; diff --git a/bin/decode+edit+encode b/bin/decode+edit+encode index a0eb208..73f4a68 100755 --- a/bin/decode+edit+encode +++ b/bin/decode+edit+encode @@ -10,6 +10,7 @@ OUTPUT=../tmp/omni/show0/earth.webm HEIGHT=360 +# TODO: Vary vpx quality based on height SPEED_VPX=4 # inspired by Apple HLS recommendations diff --git a/bin/decode+edit+loop+encode+stream b/bin/decode+edit+loop+encode+stream index ba70b02..a620eb1 100755 --- a/bin/decode+edit+loop+encode+stream +++ b/bin/decode+edit+loop+encode+stream @@ -21,6 +21,7 @@ ITERATIONS=${3-0} # endless by default HEIGHT=360 +# TODO: Vary vpx quality based on height SPEED_VPX=15 # inspired by Apple HLS recommendations diff --git a/bin/encodevideo+loop+stream b/bin/encodevideo+loop+stream index 94ea765..a8a5f76 100755 --- a/bin/encodevideo+loop+stream +++ b/bin/encodevideo+loop+stream @@ -16,6 +16,7 @@ FIRSTPORT=${2:-5002} # even number - next 3 ports used too # TODO: resolve this or resize based on it HEIGHT=360 +# TODO: Vary vpx quality based on height SPEED_VPX=15 # inspired by Apple HLS recommendations diff --git a/bin/loop+encode+stream b/bin/loop+encode+stream index a4c84be..567ca82 100755 --- a/bin/loop+encode+stream +++ b/bin/loop+encode+stream @@ -22,6 +22,7 @@ ABITRATE_OPUS=48000 # TODO HEIGHT=360 +# TODO: Vary vpx quality based on height SPEED_VPX=15 # inspired by Apple HLS recommendations diff --git a/bin/stream b/bin/stream index 71b6713..ac5135f 100755 --- a/bin/stream +++ b/bin/stream @@ -88,17 +88,20 @@ HEIGHT=270 HEIGHTS_WEBM="$HEIGHT" HEIGHTS_MPEG="$HEIGHT" +# TODO: Vary vpx quality based on height SPEED_VPX=15 -SPEED_X264=ultrafast # inspired by Apple HLS recommendations - if [ $HEIGHT -le 234 ]; then VBITRATE=145000; -elif [ $HEIGHT -le 270 ]; then VBITRATE=365000; -elif [ $HEIGHT -le 360 ]; then VBITRATE=730000; -elif [ $HEIGHT -le 432 ]; then VBITRATE=1100000; -elif [ $HEIGHT -le 540 ]; then VBITRATE=2000000; -elif [ $HEIGHT -le 720 ]; then VBITRATE=3000000; +# TODO: Externalize to site-specific configfile + if [ $HEIGHT -le 234 ]; then VBITRATE=145000; SPEED_X264=slow; SPEED_X264_ALONE=fast; +elif [ $HEIGHT -le 270 ]; then VBITRATE=365000; SPEED_X264=faster; SPEED_X264_ALONE=fast; +elif [ $HEIGHT -le 360 ]; then VBITRATE=730000; SPEED_X264=faster; SPEED_X264_ALONE=fast; +elif [ $HEIGHT -le 432 ]; then VBITRATE=1100000; SPEED_X264=veryfast; SPEED_X264_ALONE=fast; +elif [ $HEIGHT -le 540 ]; then VBITRATE=2000000; SPEED_X264=toofast; SPEED_X264_ALONE=veryfast; +elif [ $HEIGHT -le 720 ]; then VBITRATE=3000000; SPEED_X264=toofast; SPEED_X264_ALONE=ultrafast; fi +[ -n "$HEIGHTS_WEBM" ] || SPEED_X264="$SPEED_X264_ALONE" +[ toofast != "$SPEED_X264" ] || exit1 "Not enough CPU - reduce size or streams" # shellcheck disable=SC2048,SC2059 echo_n() { -- cgit v1.2.3