Change encoding to be compatible with owncast passthrough mode

This commit is contained in:
douzeb 2023-03-02 12:03:02 +01:00
parent c18e5b46d7
commit 5502ca423c

View file

@ -2,58 +2,36 @@
REPLAY_RESOLUTION=1280x720
LIVE_RESOLUTION=854x480
VBITRATE=2048
LIVE_AVBR=1024
LIVE_MVBR=1280
REPLAY_AVBR=2048
REPLAY_MVBR=3072
ABITRATE=128
V4LDEVICE=0
FPS=10
if [[ $# -lt 3 ]] ; then
if [[ $# -lt 4 ]] ; then
echo "Not enough arguments supplied" >&2
echo "You need to pass at least the PeerTube server name as the " >&2
echo "first parameter the rtmp port as the second and the streaming key as the third" >&2
echo "You need to pass the PeerTube server name as the " >&2
echo "first parameter the rtmp port as the second, the" >&2
echo "streaming key as the third and the v4l2 device as the fourth" >&2
echo " " >&2
echo "syntax: " >&2
echo " $(basename $0) <peertube-server> <rtmp port> <streaming-key> <replay resolution> <live resolution> <frames per seconds> <video-bitrate-kbps> <audio-bitrate-kbps> <v4ldevice>" >&2
echo " $(basename $0) <peertube-server> <rtmp port> <streaming-key> <v4ldevice>" >&2
echo " " >&2
echo "other parameters are optional and will default to the " >&2
echo "values in the following example :" >&2
echo " `basename $0` tube.example.com 1935 69ac2d29-eba4-4d5f-a3a6-6047e6768ffb $REPLAY_RESOLUTION $LIVE_RESOLUTION $FPS $VBITRATE $ABITRATE $V4LDEVICE" >&2
echo "Example :" >&2
echo " `basename $0` tube.example.com 1935 69ac2d29-eba4-4d5f-a3a6-6047e6768ffb 0" >&2
exit 1
fi
URL=rtmp://$1:$2/live/$3
if [[ ! -z "$4" ]]
then
REPLAY_RESOLUTION="$4"
fi
V4LDEVICE=$4
if [[ ! -z "$5" ]]
then
LIVE_RESOLUTION="$5"
fi
if [[ ! -z "$6" ]]
then
FPS="$6"
fi
if [[ ! -z "$7" ]]
then
VBITRATE="$7"
fi
KEYFRAMEINTERVAL=$(echo "2*${FPS}" | bc)
BUFFERSIZE=$(echo "2*${VBITRATE}" | bc)
if [[ ! -z "$8" ]]
then
ABITRATE="$8"
fi
if [[ ! -z "$9" ]]
then
V4LDEVICE="$9"
fi
@ -69,6 +47,12 @@ echo $FILENAME
# A la ligne 76, utiliser cette ligne pour avoir le son de la caméra :
#-f alsa -ac 2 -i hw:CARD=CAMERA,DEV=${V4LDEVICE} \
#-x264opts nal-hrd=cbr:force-cfr=1:vbv-bufsize=${BUFFERSIZE}:bitrate=${VBITRATE}:vbv-maxrate=${VBITRATE} \
#-codec:v libx264 \
#-preset superfast \
#-pixel_format yuv420p \
ffmpeg \
-loglevel level \
-y \
@ -76,19 +60,15 @@ ffmpeg \
-f lavfi -i aevalsrc="(1-min(1\,mod(floor(5*t)\,50)))*0.1*sin(8*PI*(360-2.5/2)*t)+0.1*sin(2*PI*(360-2.5/2)*t)|(1-min(1\,mod(floor(5*t)\,50)))*0.1*sin(8*PI*(360+2.5/2)*t)+0.1*sin(2*PI*(360+2.5/2)*t):sample_rate=48000" \
-channel_layout stereo \
-ar 48000 \
-pixel_format yuv420p \
-filter_complex "[1:a]volume=-10dB;[0:v]drawtext='font=DejaVuSansMono:text=%{pts}: fontcolor=white: fontsize=h/12: box=1: boxcolor=black@0.43: boxborderw=5: x=mod(floor(t/10+1)\,2)*mod(t*(w-text_w)/10\,w-text_w)+mod(floor(t/10)\,2)*(w-text_w-mod(t*(w-text_w)/10\,w-text_w)): y=text_h/2', drawtext='font=DejaVuSansMono:text=%{localtime}: fontcolor=white: fontsize=h/20: box=1: boxcolor=black@0.43: boxborderw=5: x=text_h: y=h-3*text_h/2', split=2[out1][out2]" \
-codec:v libx264 \
-preset superfast \
-x264opts nal-hrd=cbr:force-cfr=1:vbv-bufsize=${BUFFERSIZE}:bitrate=${VBITRATE}:vbv-maxrate=${VBITRATE} \
-c:a aac -b:a ${ABITRATE}k \
-flags +global_header \
-map '[out1]' -s ${LIVE_RESOLUTION} -c:v libx264 -b:v 1024k -maxrate:v 1280k -g:v 48 \
-keyint_min:v 48 -r:v 24 -x264-params:v scenecut=0:open_gop=0 -bufsize:v 1280k -profile:v high \
-map 1:a -f flv ${URL} \
-map '[out2]' -s ${REPLAY_RESOLUTION} -c:v libx264 -b:v 2048k -maxrate:v 3072k -g:v 48 \
-keyint_min:v 48 -r:v 24 -x264-params:v scenecut=0:open_gop=0 -bufsize:v 3072k -profile:v high \
-map 1:a -f matroska \
-map '[out1]' -s ${LIVE_RESOLUTION} -c:v libx264 -b:v ${LIVE_AVBR}k -maxrate:v ${LIVE_MVBR}k -g:v ${KEYFRAMEINTERVAL} \
-keyint_min:v ${KEYFRAMEINTERVAL} -r:v ${FPS} -x264-params:v scenecut=0:open_gop=0 -bufsize:v 1280k -profile:v high \
-map 1:a -pix_fmt yuv420p -f flv ${URL} \
-map '[out2]' -s ${REPLAY_RESOLUTION} -c:v libx264 -b:v ${REPLAY_AVBR}k -maxrate:v ${REPLAY_MVBR}k -g:v ${KEYFRAMEINTERVAL} \
-keyint_min:v ${KEYFRAMEINTERVAL} -r:v ${FPS} -x264-params:v scenecut=0:open_gop=0 -bufsize:v 3072k -profile:v high \
-map 1:a -pix_fmt yuv420p -f matroska \
-f segment -segment_time 10:00 -reset_timestamps 1 \
-strftime 1 "${FILENAME}_%Y-%m-%d_%H-%M-%S.mkv"