From 915210008d16a6ad56f40c2d5b32515c02b87d82 Mon Sep 17 00:00:00 2001 From: Viet Nguyen Duc Date: Sat, 7 Jun 2025 02:35:00 +0700 Subject: [PATCH] Docker: Fix video recording in Node consume high CPU Signed-off-by: Viet Nguyen Duc --- Video/video.sh | 18 +++++++++++++----- tests/docker-compose-v3-dev-arm64.yml | 2 ++ tests/docker-compose-v3-get-started-arm64.yml | 8 ++------ tests/get_started.py | 2 +- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/Video/video.sh b/Video/video.sh index 2c2657d8e..ac2596739 100755 --- a/Video/video.sh +++ b/Video/video.sh @@ -14,7 +14,7 @@ VIDEO_CONFIG_DIRECTORY=${VIDEO_CONFIG_DIRECTORY:-"/opt/bin"} UPLOAD_DESTINATION_PREFIX=${UPLOAD_DESTINATION_PREFIX:-$SE_UPLOAD_DESTINATION_PREFIX} UPLOAD_PIPE_FILE_NAME=${SE_UPLOAD_PIPE_FILE_NAME:-"uploadpipe"} SE_SERVER_PROTOCOL=${SE_SERVER_PROTOCOL:-"http"} -poll_interval=${SE_VIDEO_POLL_INTERVAL:-1} +poll_interval=${SE_VIDEO_POLL_INTERVAL:-2} max_attempts=${SE_VIDEO_WAIT_ATTEMPTS:-50} file_ready_max_attempts=${SE_VIDEO_FILE_READY_WAIT_ATTEMPTS:-5} wait_uploader_shutdown_max_attempts=${SE_VIDEO_WAIT_UPLOADER_SHUTDOWN_ATTEMPTS:-5} @@ -229,8 +229,11 @@ if [[ "${VIDEO_UPLOAD_ENABLED}" != "true" ]] && [[ "${VIDEO_FILE_NAME}" != "auto wait_for_display video_file="$VIDEO_FOLDER/$VIDEO_FILE_NAME" # exec replaces the video.sh process with ffmpeg, this makes easier to pass the process termination signal - ffmpeg -hide_banner -loglevel warning -flags low_delay -threads 2 -fflags nobuffer+genpts -strict experimental -y -f x11grab \ - -video_size ${VIDEO_SIZE} -r ${FRAME_RATE} -i ${DISPLAY} ${SE_AUDIO_SOURCE} -codec:v ${CODEC} ${PRESET} -pix_fmt yuv420p "$video_file" & + ffmpeg -hide_banner -loglevel warning -threads ${SE_FFMPEG_THREADS:-1} -thread_queue_size 512 \ + -probesize 32M -analyzeduration 0 -y -f x11grab -video_size ${VIDEO_SIZE} -r ${FRAME_RATE} \ + -i ${DISPLAY} ${SE_AUDIO_SOURCE} -codec:v ${CODEC} ${PRESET:-"-preset veryfast"} \ + -tune zerolatency -crf ${SE_VIDEO_CRF:-28} -maxrate ${SE_VIDEO_MAXRATE:-1000k} -bufsize ${SE_VIDEO_BUFSIZE:-2000k} \ + -pix_fmt yuv420p -movflags +faststart "$video_file" & FFMPEG_PID=$! if ps -p $FFMPEG_PID >/dev/null; then wait $FFMPEG_PID @@ -262,8 +265,11 @@ else log_node_response video_file="${VIDEO_FOLDER}/$video_file_name" echo "$(date -u +"${ts_format}") [${process_name}] - Starting to record video" - ffmpeg -hide_banner -loglevel warning -flags low_delay -threads 2 -fflags nobuffer+genpts -strict experimental -y -f x11grab \ - -video_size ${VIDEO_SIZE} -r ${FRAME_RATE} -i ${DISPLAY} ${SE_AUDIO_SOURCE} -codec:v ${CODEC} ${PRESET} -pix_fmt yuv420p "$video_file" & + ffmpeg -hide_banner -loglevel warning -threads ${SE_FFMPEG_THREADS:-1} -thread_queue_size 512 \ + -probesize 32M -analyzeduration 0 -y -f x11grab -video_size ${VIDEO_SIZE} -r ${FRAME_RATE} \ + -i ${DISPLAY} ${SE_AUDIO_SOURCE} -codec:v ${CODEC} ${PRESET:-"-preset veryfast"} \ + -tune zerolatency -crf ${SE_VIDEO_CRF:-28} -maxrate ${SE_VIDEO_MAXRATE:-1000k} -bufsize ${SE_VIDEO_BUFSIZE:-2000k} \ + -pix_fmt yuv420p -movflags +faststart "$video_file" & FFMPEG_PID=$! if ps -p $FFMPEG_PID >/dev/null; then recording_started="true" @@ -281,6 +287,8 @@ else elif [[ $recording_started = "true" ]]; then echo "$(date -u +"${ts_format}") [${process_name}] - Video recording in progress" sleep ${poll_interval} + else + sleep ${poll_interval} fi done stop_if_recording_inprogress diff --git a/tests/docker-compose-v3-dev-arm64.yml b/tests/docker-compose-v3-dev-arm64.yml index 7079331f9..449def500 100644 --- a/tests/docker-compose-v3-dev-arm64.yml +++ b/tests/docker-compose-v3-dev-arm64.yml @@ -17,6 +17,7 @@ services: - SE_EVENT_BUS_HOST=selenium-hub - SE_VNC_NO_PASSWORD=true - SE_NODE_ENABLE_MANAGED_DOWNLOADS=true + - SE_RECORD_VIDEO=true firefox: deploy: @@ -32,6 +33,7 @@ services: - SE_EVENT_BUS_HOST=selenium-hub - SE_VNC_NO_PASSWORD=true - SE_NODE_ENABLE_MANAGED_DOWNLOADS=true + - SE_RECORD_VIDEO=true selenium-hub: image: selenium/hub:4.33.0-20250525 diff --git a/tests/docker-compose-v3-get-started-arm64.yml b/tests/docker-compose-v3-get-started-arm64.yml index e810c18b3..65f0e6b9e 100644 --- a/tests/docker-compose-v3-get-started-arm64.yml +++ b/tests/docker-compose-v3-get-started-arm64.yml @@ -5,11 +5,9 @@ services: chrome: deploy: mode: replicated - replicas: 1 + replicas: 3 image: selenium/node-chromium:latest shm_size: 2gb - ports: - - "5900:5900" depends_on: - selenium-hub volumes: @@ -23,11 +21,9 @@ services: firefox: deploy: mode: replicated - replicas: 1 + replicas: 3 image: selenium/node-firefox:latest shm_size: 2gb - ports: - - "5901:5900" depends_on: - selenium-hub volumes: diff --git a/tests/get_started.py b/tests/get_started.py index de4370bc7..ab777c13a 100644 --- a/tests/get_started.py +++ b/tests/get_started.py @@ -29,7 +29,7 @@ def run_browser_instance(browser, grid_url): elif browser == "edge": options = EdgeOptions() options.enable_bidi = True - options.enable_downloads = True + options.enable_downloads = False while True: driver = webdriver.Remote(