Skip to content

Docker: Fix video recording in Node consume high CPU #2856

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions Video/video.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/docker-compose-v3-dev-arm64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
8 changes: 2 additions & 6 deletions tests/docker-compose-v3-get-started-arm64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/get_started.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading