summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/decode+edit+encode14
-rwxr-xr-xbin/decode+edit+loop+encode+stream14
-rwxr-xr-xbin/encodevideo+loop+stream14
-rwxr-xr-xbin/loop+encode+stream19
-rwxr-xr-xbin/stream32
5 files changed, 62 insertions, 31 deletions
diff --git a/bin/decode+edit+encode b/bin/decode+edit+encode
index deb732a..0b11a7e 100755
--- a/bin/decode+edit+encode
+++ b/bin/decode+edit+encode
@@ -29,6 +29,14 @@ elif [ $HEIGHT -le 720 ]; then # 720p → 921600
VBITRATE=3000000
fi
+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"
+}
+
mkdir -p $(dirname "$OUTPUT")
# based on http://www.webmproject.org/docs/encoder-parameters/#real-time-cbr-encoding-and-streaming
@@ -42,9 +50,5 @@ ffmpeg -hide_banner -threads auto -y -re \
"[0:v]format=pix_fmts=yuv420p,scale=iw*sar*$HEIGHT/ih:$HEIGHT,setsar=1[bg];
[bg][1:v]overlay=main_w-overlay_w-20:main_h-overlay_h-20[v]" \
-map '[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 webm "$OUTPUT"
diff --git a/bin/decode+edit+loop+encode+stream b/bin/decode+edit+loop+encode+stream
index 6e65697..8dba934 100755
--- a/bin/decode+edit+loop+encode+stream
+++ b/bin/decode+edit+loop+encode+stream
@@ -54,6 +54,14 @@ elif [ $BITS -le 921600 ]; then # 720p → 921600
SPEED_VP8=15
fi
+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
# + loop-in-filter trick based on http://video.stackexchange.com/a/16933
# + scale+watermark trick based on http://stackoverflow.com/a/10937357
@@ -67,9 +75,5 @@ ffmpeg -hide_banner -threads auto -re \
"[0:v]format=pix_fmts=yuv420p,scale=iw*sar*$HEIGHT/ih:$HEIGHT,setsar=1[bg];
[bg][1:v]overlay=main_w-overlay_w-20:main_h-overlay_h-20[v]" \
-map '[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"
diff --git a/bin/encodevideo+loop+stream b/bin/encodevideo+loop+stream
index b054782..ceded76 100755
--- a/bin/encodevideo+loop+stream
+++ b/bin/encodevideo+loop+stream
@@ -49,6 +49,14 @@ elif [ $BITS -le 921600 ]; then # 720p → 921600
SPEED_VP8=15
fi
+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
@@ -56,9 +64,5 @@ ffmpeg -hide_banner -threads auto -re \
-stream_loop -1 -i "$INPUT" \
-vf format=pix_fmts=yuv420p \
-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"
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"
diff --git a/bin/stream b/bin/stream
index ce90206..6e3ecdb 100755
--- a/bin/stream
+++ b/bin/stream
@@ -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 }