@@ -145,14 +145,14 @@ function stop_recording() {
145145  stop_ffmpeg
146146  echo  " $( date -u +" ${ts_format} " ) ${process_name} ] - Video recording stopped" 
147147  recorded_count=$(( recorded_count +  1 )) 
148+   recording_started=" false" 
148149  if  [[ " ${VIDEO_UPLOAD_ENABLED} " =  " true" &&  [[ -n  " ${UPLOAD_DESTINATION_PREFIX} " ;  then 
149150    upload_destination=${UPLOAD_DESTINATION_PREFIX} /${video_file_name} 
150151    echo  " $( date -u +" ${ts_format} " ) ${process_name} ] - Add to pipe a signal Uploading video to $upload_destination " 
151152    echo  " $video_file  ${UPLOAD_DESTINATION_PREFIX} " >> ${UPLOAD_PIPE_FILE}  & 
152153  elif  [[ " ${VIDEO_UPLOAD_ENABLED} " =  " true" &&  [[ -z  " ${UPLOAD_DESTINATION_PREFIX} " ;  then 
153154    echo  " $( date -u +" ${ts_format} " ) ${process_name} ] - Upload destination not known since UPLOAD_DESTINATION_PREFIX is not set. Continue without uploading." 
154155  fi 
155-   recording_started=" false" 
156156}
157157
158158function  check_if_ffmpeg_running()  {
@@ -237,28 +237,29 @@ else
237237
238238  wait_for_api_respond
239239  while  curl --noproxy " *" " Authorization: Basic ${BASIC_AUTH} " ${NODE_STATUS_ENDPOINT}  > /tmp/status.json;  do 
240-     session_id=$( jq -e  " ${JQ_SESSION_ID_QUERY} "   ||   echo   " null " ) 
240+     session_id=$( jq -r  " ${JQ_SESSION_ID_QUERY} " ) 
241241    if  [[ " $session_id " !=  " null" &&  " $session_id " !=  " " &&  " $session_id " !=  " reserved" &&  " $recording_started " =  " false" ;  then 
242242      echo  " $( date -u +" ${ts_format} " ) ${process_name} ] - Session: $session_id  is created" 
243243      return_list=($( bash ${VIDEO_CONFIG_DIRECTORY} /video_graphQLQuery.sh " $session_id " ) 
244244      caps_se_video_record=" ${return_list[0]} " 
245245      video_file_name=" ${return_list[1]} .mp4" 
246246      endpoint_url=" ${return_list[2]} " 
247247      /opt/bin/validate_endpoint.sh " ${endpoint_url} " " true" 
248-       echo  " $( date -u +" ${ts_format} " ) ${process_name} ] - Start recording: $caps_se_video_record , video file name: $video_file_name " 
249-       log_node_response
250-     fi 
251-     if  [[ " $session_id " !=  " null" &&  " $session_id " !=  " " &&  " $session_id " !=  " reserved" &&  " $recording_started " =  " false" &&  " $caps_se_video_record " =  " true" ;  then 
252-       video_file=" ${VIDEO_FOLDER} /$video_file_name " 
253-       echo  " $( date -u +" ${ts_format} " ) ${process_name} ] - Starting to record video" 
254-       ffmpeg -hide_banner -loglevel warning -flags low_delay -threads 2 -fflags nobuffer+genpts -strict experimental -y -f x11grab \
255-         -video_size ${VIDEO_SIZE}  -r ${FRAME_RATE}  -i ${DISPLAY}  ${SE_AUDIO_SOURCE}  -codec:v ${CODEC}  ${PRESET}  -pix_fmt yuv420p " $video_file " & 
256-       FFMPEG_PID=$! 
257-       if  ps -p $FFMPEG_PID  > /dev/null;  then 
258-         recording_started=" true" 
248+       if  [[ " $caps_se_video_record " =  " true" ;  then 
249+         echo  " $( date -u +" ${ts_format} " ) ${process_name} ] - Start recording: $caps_se_video_record , video file name: $video_file_name " 
250+         log_node_response
251+         video_file=" ${VIDEO_FOLDER} /$video_file_name " 
252+         echo  " $( date -u +" ${ts_format} " ) ${process_name} ] - Starting to record video" 
253+         ffmpeg -hide_banner -loglevel warning -flags low_delay -threads 2 -fflags nobuffer+genpts -strict experimental -y -f x11grab \
254+           -video_size ${VIDEO_SIZE}  -r ${FRAME_RATE}  -i ${DISPLAY}  ${SE_AUDIO_SOURCE}  -codec:v ${CODEC}  ${PRESET}  -pix_fmt yuv420p " $video_file " & 
255+         FFMPEG_PID=$! 
256+         if  ps -p $FFMPEG_PID  > /dev/null;  then 
257+           recording_started=" true" 
258+           prev_session_id=$session_id 
259+         fi 
260+         echo  " $( date -u +" ${ts_format} " ) ${process_name} ] - Video recording started" 
261+         sleep ${poll_interval} 
259262      fi 
260-       echo  " $( date -u +" ${ts_format} " ) ${process_name} ] - Video recording started" 
261-       sleep ${poll_interval} 
262263    elif  [[ " $session_id " !=  " $prev_session_id " &&  " $recording_started " =  " true" ;  then 
263264      stop_recording
264265      if  [[ $max_recorded_count  -gt  0 ]] &&  [[ $recorded_count  -ge  $max_recorded_count  ]];  then 
@@ -268,10 +269,8 @@ else
268269    elif  [[ $recording_started  =  " true" ;  then 
269270      echo  " $( date -u +" ${ts_format} " ) ${process_name} ] - Video recording in progress" 
270271      sleep ${poll_interval} 
271-     else 
272-       sleep ${poll_interval} 
273272    fi 
274-     prev_session_id=$session_id 
275273  done 
274+   stop_if_recording_inprogress
276275  echo  " $( date -u +" ${ts_format} " ) ${process_name} ] - Node API is not responding now, exiting..." 
277276fi 
0 commit comments