Skip to content

Commit 204f199

Browse files
authored
Docker: Fix video recording in Node consume high CPU (#2856)
1 parent dbdfc1f commit 204f199

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

Video/video.sh

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ VIDEO_CONFIG_DIRECTORY=${VIDEO_CONFIG_DIRECTORY:-"/opt/bin"}
1414
UPLOAD_DESTINATION_PREFIX=${UPLOAD_DESTINATION_PREFIX:-$SE_UPLOAD_DESTINATION_PREFIX}
1515
UPLOAD_PIPE_FILE_NAME=${SE_UPLOAD_PIPE_FILE_NAME:-"uploadpipe"}
1616
SE_SERVER_PROTOCOL=${SE_SERVER_PROTOCOL:-"http"}
17-
poll_interval=${SE_VIDEO_POLL_INTERVAL:-1}
17+
poll_interval=${SE_VIDEO_POLL_INTERVAL:-2}
1818
max_attempts=${SE_VIDEO_WAIT_ATTEMPTS:-50}
1919
file_ready_max_attempts=${SE_VIDEO_FILE_READY_WAIT_ATTEMPTS:-5}
2020
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
229229
wait_for_display
230230
video_file="$VIDEO_FOLDER/$VIDEO_FILE_NAME"
231231
# exec replaces the video.sh process with ffmpeg, this makes easier to pass the process termination signal
232-
ffmpeg -hide_banner -loglevel warning -flags low_delay -threads 2 -fflags nobuffer+genpts -strict experimental -y -f x11grab \
233-
-video_size ${VIDEO_SIZE} -r ${FRAME_RATE} -i ${DISPLAY} ${SE_AUDIO_SOURCE} -codec:v ${CODEC} ${PRESET} -pix_fmt yuv420p "$video_file" &
232+
ffmpeg -hide_banner -loglevel warning -threads ${SE_FFMPEG_THREADS:-1} -thread_queue_size 512 \
233+
-probesize 32M -analyzeduration 0 -y -f x11grab -video_size ${VIDEO_SIZE} -r ${FRAME_RATE} \
234+
-i ${DISPLAY} ${SE_AUDIO_SOURCE} -codec:v ${CODEC} ${PRESET:-"-preset veryfast"} \
235+
-tune zerolatency -crf ${SE_VIDEO_CRF:-28} -maxrate ${SE_VIDEO_MAXRATE:-1000k} -bufsize ${SE_VIDEO_BUFSIZE:-2000k} \
236+
-pix_fmt yuv420p -movflags +faststart "$video_file" &
234237
FFMPEG_PID=$!
235238
if ps -p $FFMPEG_PID >/dev/null; then
236239
wait $FFMPEG_PID
@@ -262,8 +265,11 @@ else
262265
log_node_response
263266
video_file="${VIDEO_FOLDER}/$video_file_name"
264267
echo "$(date -u +"${ts_format}") [${process_name}] - Starting to record video"
265-
ffmpeg -hide_banner -loglevel warning -flags low_delay -threads 2 -fflags nobuffer+genpts -strict experimental -y -f x11grab \
266-
-video_size ${VIDEO_SIZE} -r ${FRAME_RATE} -i ${DISPLAY} ${SE_AUDIO_SOURCE} -codec:v ${CODEC} ${PRESET} -pix_fmt yuv420p "$video_file" &
268+
ffmpeg -hide_banner -loglevel warning -threads ${SE_FFMPEG_THREADS:-1} -thread_queue_size 512 \
269+
-probesize 32M -analyzeduration 0 -y -f x11grab -video_size ${VIDEO_SIZE} -r ${FRAME_RATE} \
270+
-i ${DISPLAY} ${SE_AUDIO_SOURCE} -codec:v ${CODEC} ${PRESET:-"-preset veryfast"} \
271+
-tune zerolatency -crf ${SE_VIDEO_CRF:-28} -maxrate ${SE_VIDEO_MAXRATE:-1000k} -bufsize ${SE_VIDEO_BUFSIZE:-2000k} \
272+
-pix_fmt yuv420p -movflags +faststart "$video_file" &
267273
FFMPEG_PID=$!
268274
if ps -p $FFMPEG_PID >/dev/null; then
269275
recording_started="true"
@@ -281,6 +287,8 @@ else
281287
elif [[ $recording_started = "true" ]]; then
282288
echo "$(date -u +"${ts_format}") [${process_name}] - Video recording in progress"
283289
sleep ${poll_interval}
290+
else
291+
sleep ${poll_interval}
284292
fi
285293
done
286294
stop_if_recording_inprogress

tests/docker-compose-v3-dev-arm64.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ services:
1717
- SE_EVENT_BUS_HOST=selenium-hub
1818
- SE_VNC_NO_PASSWORD=true
1919
- SE_NODE_ENABLE_MANAGED_DOWNLOADS=true
20+
- SE_RECORD_VIDEO=true
2021

2122
firefox:
2223
deploy:
@@ -32,6 +33,7 @@ services:
3233
- SE_EVENT_BUS_HOST=selenium-hub
3334
- SE_VNC_NO_PASSWORD=true
3435
- SE_NODE_ENABLE_MANAGED_DOWNLOADS=true
36+
- SE_RECORD_VIDEO=true
3537

3638
selenium-hub:
3739
image: selenium/hub:4.33.0-20250525

tests/docker-compose-v3-get-started-arm64.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ services:
55
chrome:
66
deploy:
77
mode: replicated
8-
replicas: 1
8+
replicas: 3
99
image: selenium/node-chromium:latest
1010
shm_size: 2gb
11-
ports:
12-
- "5900:5900"
1311
depends_on:
1412
- selenium-hub
1513
volumes:
@@ -23,11 +21,9 @@ services:
2321
firefox:
2422
deploy:
2523
mode: replicated
26-
replicas: 1
24+
replicas: 3
2725
image: selenium/node-firefox:latest
2826
shm_size: 2gb
29-
ports:
30-
- "5901:5900"
3127
depends_on:
3228
- selenium-hub
3329
volumes:

tests/get_started.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def run_browser_instance(browser, grid_url):
2929
elif browser == "edge":
3030
options = EdgeOptions()
3131
options.enable_bidi = True
32-
options.enable_downloads = True
32+
options.enable_downloads = False
3333

3434
while True:
3535
driver = webdriver.Remote(

0 commit comments

Comments
 (0)