elgalu / docker-selenium

[NOT MAINTAINED] Please use <https://github.com/SeleniumHQ/docker-selenium>
https://github.com/SeleniumHQ/docker-selenium
Other
1.42k stars 334 forks source link

How to set VIDEO_FILE_NAME when starting video record manually ? #322

Closed arman-sydikov closed 5 years ago

arman-sydikov commented 5 years ago

How to set VIDEO_FILE_NAME when starting video record manually ?

What I did

As I understand /usr/bin/start-video gets the file name from cat VIDEO_FILE_NAME :

#!/usr/bin/env bash

echoerr() { printf "%s\n" "$*" >&2; }

# print error and exit
die () {
  echoerr "ERROR: $1"
  # if $2 is defined AND NOT EMPTY, use $2; otherwise, set to "150"
  errnum=${2-150}
  exit $errnum
}

[ -z "${VIDEO_REC_STOP_SIGNAL}" ] && export VIDEO_REC_STOP_SIGNAL="INT"
[ -z "${LOGFILE_MAXBYTES}" ] && export LOGFILE_MAXBYTES="10MB"
[ -z "${LOGFILE_BACKUPS}" ] && export LOGFILE_BACKUPS=5
[ -z "${LOGS_DIR}" ] && export LOGS_DIR="/var/log/cont"

export VIDEO_LOG_FILE="$(cat VIDEO_LOG_FILE)"
export VIDEO_PIDFILE="$(cat VIDEO_PIDFILE)"
export VIDEO_FILE_NAME="$(cat VIDEO_FILE_NAME)"
export VIDEO_PATH="$(cat VIDEO_PATH)"

# Test: supervisorctl -c /etc/supervisor/supervisord.conf status
export VIDEO=true
supervisorctl -c /etc/supervisor/supervisord.conf start video-rec

timeout --foreground ${WAIT_TIMEOUT} wait-video-rec.sh || \
die "Failed while waiting for video recording to start!"

I executed cat VIDEO_FILE_NAME and it printed the default file name :

$ docker exec -it grid cat VIDEO_FILE_NAME
vid_chrome_24402

I changed the default file name :

$ docker exec -it grid sh -c "echo test > VIDEO_FILE_NAME"
$ docker exec -it grid cat VIDEO_FILE_NAME
test

I started video record manually :

$ docker exec -it grid start-video
video-rec: started
Waiting for ffmpeg video recording to start...
.Videos at /home/seluser/videos/vid_chrome_24402.mp4* started to be recorded! (wait-video-rec.sh)

but it still recording video to the file with the default file name vid_chrome_24402.mp4

Operating System

Linux GDais00016 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

Image version

3.141.59-p13

Docker version

Docker version 18.09.1, build 4c52b90

arman-sydikov commented 5 years ago

What else I tried

I modified /usr/bin/start-video

$ docker exec grid sudo sed -i 's/export VIDEO_FILE_NAME=.*/export VIDEO_FILE_NAME="test"/g' /usr/bin/start-video
$ docker exec grid cat /usr/bin/start-video
#!/usr/bin/env bash

echoerr() { printf "%s\n" "$*" >&2; }

# print error and exit
die () {
  echoerr "ERROR: $1"
  # if $2 is defined AND NOT EMPTY, use $2; otherwise, set to "150"
  errnum=${2-150}
  exit $errnum
}

[ -z "${VIDEO_REC_STOP_SIGNAL}" ] && export VIDEO_REC_STOP_SIGNAL="INT"
[ -z "${LOGFILE_MAXBYTES}" ] && export LOGFILE_MAXBYTES="10MB"
[ -z "${LOGFILE_BACKUPS}" ] && export LOGFILE_BACKUPS=5
[ -z "${LOGS_DIR}" ] && export LOGS_DIR="/var/log/cont"

export VIDEO_LOG_FILE="$(cat VIDEO_LOG_FILE)"
export VIDEO_PIDFILE="$(cat VIDEO_PIDFILE)"
export VIDEO_FILE_NAME="test"
export VIDEO_PATH="$(cat VIDEO_PATH)"

# Test: supervisorctl -c /etc/supervisor/supervisord.conf status
export VIDEO=true
supervisorctl -c /etc/supervisor/supervisord.conf start video-rec

timeout --foreground ${WAIT_TIMEOUT} wait-video-rec.sh || \
  die "Failed while waiting for video recording to start!"

I started video record again :

$ docker exec grid start-video
video-rec: started
Waiting for ffmpeg video recording to start...
.Videos at /home/seluser/videos/vid_chrome_24402.mp4* started to be recorded! (wait-video-rec.sh)

still recording video to the file with the default file name vid_chrome_24402.mp4

arman-sydikov commented 5 years ago

Workaround

From start-video-rec.sh we can see that ffmpeg records a video into ${tmp_video_path} file :

export tmp_video_path="${VIDEOS_DIR}/${VIDEO_FILE_NAME}.${VIDEO_TMP_FILE_EXTENSION}"
export final_video_path="${VIDEOS_DIR}/${VIDEO_FILE_NAME}.${VIDEO_FILE_EXTENSION}"

ffmpeg -f x11grab \
  -s ${FFMPEG_FRAME_SIZE} \
  -draw_mouse ${FFMPEG_DRAW_MOUSE} \
  -i "${DISPLAY}.0" \
  ${FFMPEG_CODEC_ARGS} \
  -r ${FFMPEG_FRAME_RATE} \
-y -an "${tmp_video_path}" 2>&1 &

Adding export VIDEO_FILE_NAME=filename did the trick :

$ docker exec grid sudo sed -i '5s/.*/export VIDEO_FILE_NAME=filename/' /usr/bin/start-video-rec.sh
diemol commented 5 years ago

The README mentions how to do it https://github.com/elgalu/docker-selenium#record-videos, VIDEO_FILE_NAME needs to be passed as an env var.

arman-sydikov commented 5 years ago

@diemol it works only when starting a new container, but my question was about changing video file name on already started container : https://github.com/elgalu/docker-selenium/blob/master/docs/videos.md#start

For example the following code does not change the file name :

$ docker exec grid -e VIDEO_FILE_NAME=filename start-video
video-rec: started
Waiting for ffmpeg video recording to start...
Videos at /home/seluser/videos/vid_chrome_27390.mkv* started to be recorded! (wait-video-rec.sh)
diemol commented 5 years ago

Ah ok, got it. No, this is only supported for the use case when the container is started.