@@ -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() {
@@ -182,7 +182,6 @@ function wait_for_file_integrity() {
182182function stop_if_recording_inprogress() {
183183 if [[ " $recording_started " = " true" ]] || check_if_ffmpeg_running; then
184184 stop_recording
185- wait_for_file_integrity
186185 fi
187186}
188187
@@ -223,7 +222,6 @@ if [[ "${VIDEO_UPLOAD_ENABLED}" != "true" ]] && [[ "${VIDEO_FILE_NAME}" != "auto
223222 if ps -p $FFMPEG_PID > /dev/null; then
224223 wait $FFMPEG_PID
225224 fi
226- wait_for_file_integrity
227225
228226else
229227 trap graceful_exit_force SIGTERM SIGINT EXIT
@@ -247,34 +245,32 @@ else
247245 video_file_name=" ${return_list[1]} .mp4"
248246 endpoint_url=" ${return_list[2]} "
249247 /opt/bin/validate_endpoint.sh " ${endpoint_url} " " true"
250- echo " $( date -u +" ${ts_format} " ) [${process_name} ] - Start recording: $caps_se_video_record , video file name: $video_file_name "
251- log_node_response
252- fi
253- if [[ " $session_id " != " null" && " $session_id " != " " && " $session_id " != " reserved" && " $recording_started " = " false" && " $caps_se_video_record " = " true" ]]; then
254- video_file=" ${VIDEO_FOLDER} /$video_file_name "
255- echo " $( date -u +" ${ts_format} " ) [${process_name} ] - Starting to record video"
256- ffmpeg -hide_banner -loglevel warning -flags low_delay -threads 2 -fflags nobuffer+genpts -strict experimental -y -f x11grab \
257- -video_size ${VIDEO_SIZE} -r ${FRAME_RATE} -i ${DISPLAY} ${SE_AUDIO_SOURCE} -codec:v ${CODEC} ${PRESET} -pix_fmt yuv420p " $video_file " &
258- FFMPEG_PID=$!
259- if ps -p $FFMPEG_PID > /dev/null; then
260- 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}
261262 fi
262- echo " $( date -u +" ${ts_format} " ) [${process_name} ] - Video recording started"
263- sleep ${poll_interval}
264263 elif [[ " $session_id " != " $prev_session_id " && " $recording_started " = " true" ]]; then
265264 stop_recording
266- wait_for_file_integrity
267265 if [[ $max_recorded_count -gt 0 ]] && [[ $recorded_count -ge $max_recorded_count ]]; then
268266 echo " $( date -u +" ${ts_format} " ) [${process_name} ] - Node will be drained since max sessions reached count number ($max_recorded_count )"
269267 exit
270268 fi
271269 elif [[ $recording_started = " true" ]]; then
272270 echo " $( date -u +" ${ts_format} " ) [${process_name} ] - Video recording in progress"
273271 sleep ${poll_interval}
274- else
275- sleep ${poll_interval}
276272 fi
277- prev_session_id=$session_id
278273 done
274+ stop_if_recording_inprogress
279275 echo " $( date -u +" ${ts_format} " ) [${process_name} ] - Node API is not responding now, exiting..."
280276fi
0 commit comments