From 99e84f44327d2df03329267decac05ff020878e5 Mon Sep 17 00:00:00 2001 From: douzeb Date: Wed, 1 Mar 2023 23:31:48 +0100 Subject: [PATCH] W.I.P. --- stream_v4l_device.sh | 61 ++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/stream_v4l_device.sh b/stream_v4l_device.sh index 969c544..accfb32 100755 --- a/stream_v4l_device.sh +++ b/stream_v4l_device.sh @@ -1,11 +1,11 @@ #!/bin/bash -DURATION=300 -RESOLUTION=1280x720 +REPLAY_RESOLUTION=1280x720 +LIVE_RESOLUTION=854x480 VBITRATE=2048 ABITRATE=128 V4LDEVICE=0 -FPS=12 +FPS=10 if [[ $# -lt 3 ]] ; then echo "Not enough arguments supplied" >&2 @@ -13,11 +13,11 @@ if [[ $# -lt 3 ]] ; then echo "first parameter the rtmp port as the second and the streaming key as the third" >&2 echo " " >&2 echo "syntax: " >&2 - echo " $(basename $0) " >&2 + echo " $(basename $0) " >&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 $DURATION $RESOLUTION $VBITRATE $ABITRATE $V4LDEVICE $FPS" >&2 + echo " `basename $0` tube.example.com 1935 69ac2d29-eba4-4d5f-a3a6-6047e6768ffb $REPLAY_RESOLUTION $LIVE_RESOLUTION $FPS $VBITRATE $ABITRATE $V4LDEVICE" >&2 exit 1 fi @@ -25,49 +25,43 @@ URL=rtmp://$1:$2/live/$3 if [[ ! -z "$4" ]] then - DURATION="$4" + REPLAY_RESOLUTION="$4" fi if [[ ! -z "$5" ]] then - RESOLUTION="$5" + LIVE_RESOLUTION="$5" fi if [[ ! -z "$6" ]] then - VBITRATE="$6" + FPS="$6" +fi + +if [[ ! -z "$7" ]] +then + VBITRATE="$7" fi BUFFERSIZE=$(echo "2*${VBITRATE}" | bc) -if [[ ! -z "$7" ]] -then - ABITRATE="$7" -fi - if [[ ! -z "$8" ]] then - V4LDEVICE="$8" + ABITRATE="$8" fi if [[ ! -z "$9" ]] then - FPS="$9" + V4LDEVICE="$9" fi -FILENAME=live-v4l-${1}-cam${V4LDEVICE}-${RESOLUTION}p-${DURATION}s-${VBITRATE}kbps-${ABITRATE}kbps-${2} + +FILENAME=${1}-cam${V4LDEVICE} echo " " -echo Will stream to $URL for $DURATION seconds -echo and save a copy of the data sent to the peertube server to file : +echo Will stream to $URL +echo and save a copy of the data file : echo $FILENAME -echo with : -echo "- $RESOLUTION resolution, " -echo "- $VBITRATE kbit/s constant video bitrate, " -echo "- $BUFFERSIZE kbit video buffer and " -echo "- $ABITRATE kbit/s audio bitrate" -echo " " -$ #-x264opts nal-hrd=cbr:force-cfr=1:vbv-bufsize=${BUFFERSIZE}:bitrate=${VBITRATE}:vbv-maxrate=${VBITRATE} \ #-shortest \ @@ -78,21 +72,28 @@ $ #-re \ #-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" \ +#-t ${DURATION} \ + +#-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" \ +#-f alsa -ac 2 -i hw:CARD=CAMERA,DEV=${V4LDEVICE} \ + ffmpeg \ -loglevel level \ -y \ --f v4l2 -framerate ${FPS} -video_size ${RESOLUTION} -input_format mjpeg -i /dev/video${V4LDEVICE} \ --f alsa -ac 2 -i hw:CARD=CAMERA,DEV=${V4LDEVICE} \ +-f v4l2 -framerate ${FPS} -video_size ${REPLAY_RESOLUTION} -input_format mjpeg -i /dev/video${V4LDEVICE} \ +-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]scale='size=${RESOLUTION}',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'" \ +-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 fast \ -x264opts nal-hrd=cbr:force-cfr=1:vbv-bufsize=${BUFFERSIZE}:bitrate=${VBITRATE}:vbv-maxrate=${VBITRATE} \ -c:a aac -b:a ${ABITRATE}k \ -g 1 -segment_format_options movflags=+frag_keyframe+empty_moov+default_base_moof -segment_time 5 -f segment \ --t ${DURATION} \ -flags +global_header \ --f tee -map 0:v -map 1:a "[f=matroska]${FILENAME}.mkv|[f=flv]${URL}" +-map '[out1]' -s ${LIVE_RESOLUTION} -map 1:a -f flv ${URL} \ +-map '[out2]' -s ${REPLAY_RESOLUTION} -map 1:a -f matroska \ +-f segment -segment_time 10:00 -reset_timestamps 1 \ +-strftime 1 "${FILENAME}_%Y-%m-%d_%H-%M-%S.mkv"