aboutgitcodebugslistschat
path: root/test/lib/video
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2022-02-22 18:29:45 +0100
committerStefano Brivio <sbrivio@redhat.com>2022-02-22 18:36:24 +0100
commit337f55166f6db7ee3f6e6e253ce786b3b6606216 (patch)
tree6f6c02ed1cae7a5130789497438b98b5332c8a74 /test/lib/video
parentbe2a7898e9de236da7c42d1fb37a5a2017ac192b (diff)
downloadpasst-337f55166f6db7ee3f6e6e253ce786b3b6606216.tar
passt-337f55166f6db7ee3f6e6e253ce786b3b6606216.tar.gz
passt-337f55166f6db7ee3f6e6e253ce786b3b6606216.tar.bz2
passt-337f55166f6db7ee3f6e6e253ce786b3b6606216.tar.lz
passt-337f55166f6db7ee3f6e6e253ce786b3b6606216.tar.xz
passt-337f55166f6db7ee3f6e6e253ce786b3b6606216.tar.zst
passt-337f55166f6db7ee3f6e6e253ce786b3b6606216.zip
demo, ci: Switch to asciinema(1) for terminal recordings
For demos, cool-retro-term(1) looked fancier, but several threads of that and ffmpeg(1) are just messing up with performance testing. The CI videos started getting really big as well, and they were difficult to read. Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'test/lib/video')
-rwxr-xr-xtest/lib/video107
1 files changed, 65 insertions, 42 deletions
diff --git a/test/lib/video b/test/lib/video
index 6db9c1d..ec79c85 100755
--- a/test/lib/video
+++ b/test/lib/video
@@ -8,9 +8,9 @@
# PASTA - Pack A Subtle Tap Abstraction
# for network namespace/tap device mode
#
-# test/lib/video - Video grabbing, JavaScript fragments with links
+# test/lib/video - Session recording, JavaScript fragments with links
#
-# Copyright (c) 2021 Red Hat GmbH
+# Copyright (c) 2021-2022 Red Hat GmbH
# Author: Stefano Brivio <sbrivio@redhat.com>
FFMPEG_PID_FILE="$(mktemp)"
@@ -33,19 +33,24 @@ for (var i = 0; i < video___VIDEO_NAME__links.length; i++) {
var obj = document.getElementById(video___VIDEO_NAME__links[i][0]);
obj.addEventListener("click", function(event) {
- var __VIDEO_NAME___video = document.getElementById("__VIDEO_NAME___video");
- var top = __VIDEO_NAME___video.offsetTop - 5;
+ var __VIDEO_NAME___div = document.getElementById("__VIDEO_NAME__");
+ var top = __VIDEO_NAME___div.offsetTop - 5;
+ var seek;
- event.preventDefault();
- __VIDEO_NAME___video.play();
- __VIDEO_NAME___video.pause();
for (var i = 0; i < video___VIDEO_NAME__links.length; i++) {
if (this.id == video___VIDEO_NAME__links[i][0]) {
- __VIDEO_NAME___video.currentTime = video___VIDEO_NAME__links[i][1];
+ seek = video___VIDEO_NAME__links[i][1];
}
}
+
+ event.preventDefault();
+ __VIDEO_NAME___player.dispose();
+ __VIDEO_NAME___player = AsciinemaPlayer.create(
+ "/builds/latest/web/__VIDEO_NAME__.cast",
+ __VIDEO_NAME___div,
+ { startAt: seek, autoplay: true });
+
window.scrollTo({ top: top, behavior: "smooth" })
- __VIDEO_NAME___video.play();
}, false);
}
'
@@ -65,53 +70,71 @@ video_append_links_js()
VIDEO_LINKS_BUF="${VIDEO_LINKS_BUF}${@}"
}
-# video_grab() - Fetch window geometry, start grabbing video
-video_grab() {
+# video_start() - Mark start of a test in capture, record start timestamp
+video_start() {
VIDEO_NAME="${1}"
- rm -f "${BASEPATH}/${VIDEO_NAME}.mp4" "${BASEPATH}/${VIDEO_NAME}.webm" "${BASEPATH}/${VIDEO_NAME}.js"
-
echo "${VIDEO_LINKS_TEMPLATE}" > "${BASEPATH}/${VIDEO_NAME}.js"
-
- if [ ${XVFB} -eq 1 ]; then
- # Grab the geometry of the first window that's at least 100px wide
- eval $(xwininfo -d :99.0 -root -tree | sed -n 's/^[ ]*0x[0-f]*[^0-9]*\([0-9]\{3,\}\)x\([0-9]*\)+\([0-9]*\)+\([0-9]*\).*/__width=\1; __height=\2; __x=\3; __y=\4;/p')
- else
- __x=$(xwininfo -id $(xdotool getactivewindow) | sed -n 's/[ ]*Absolute upper-left X:[ ]*\([0-9]*\)$/\1/p')
- __y=$(xwininfo -id $(xdotool getactivewindow) | sed -n 's/[ ]*Absolute upper-left Y:[ ]*\([0-9]*\)$/\1/p')
- __width=$(xwininfo -id $(xdotool getactivewindow) | sed -n 's/[ ]*Width:[ ]*\([0-9]*\)$/\1/p')
- __height=$(xwininfo -id $(xdotool getactivewindow) | sed -n 's/[ ]*Height:[ ]*\([0-9]*\)$/\1/p')
- fi
-
- [ $((__width % 2)) ] && __width=$((__width - 1))
- [ $((__height % 2)) ] && __height=$((__height - 1))
-
- sleep 3
VIDEO_START_SECONDS=$(sed -n 's/\([0-9]*\).[0-9]* [0-9]*.[0-9]*/\1/p' /proc/uptime)
- [ ${XVFB} -eq 1 ] && __disp=":99.0" || __disp=
- ffmpeg -f x11grab -framerate 15 -video_size "${__width}x${__height}" -i "${__disp}+${__x},${__y}" -vcodec libx264 -qp 0 -draw_mouse 0 "${BASEPATH}/${VIDEO_NAME}.mp4" & echo $! > "${FFMPEG_PID_FILE}"
-}
-# video_time_now() - Print current video timestamp, in seconds
-video_time_now() {
- __now=$(sed -n 's/\([0-9]*\).[0-9]* [0-9]*.[0-9]*/\1/p' /proc/uptime)
- echo $((__now - VIDEO_START_SECONDS))
+ sync
+ [ ${DEMO} -eq 1 ] && tail -1 "${BASEPATH}/demo.uncut" > "${BASEPATH}/${VIDEO_NAME}.start"
+ [ ${CI} -eq 1 ] && tail -1 "${BASEPATH}/ci.uncut" > "${BASEPATH}/${VIDEO_NAME}.start"
+ sync
+
+ tmux refresh-client
}
-# video_stop() - Stop grabbing, finalise JavaScript templates, convert to webm
+# video_stop() - Mark stop of a test in capture, finalise JavaScript fragments
video_stop() {
+ tmux refresh-client
+
+ sync
+ [ ${DEMO} -eq 1 ] && tail -1 "${BASEPATH}/demo.uncut" > "${BASEPATH}/${VIDEO_NAME}.stop"
+ [ ${CI} -eq 1 ] && tail -1 "${BASEPATH}/ci.uncut" > "${BASEPATH}/${VIDEO_NAME}.stop"
+ sync
+
sed -i 's/^.*$/&\\/g' "${BASEPATH}/${VIDEO_NAME}.js"
echo "${VIDEO_LINKS_TEMPLATE_JS}" | sed "s/__VIDEO_NAME__/${VIDEO_NAME}/g" >> "${BASEPATH}/${VIDEO_NAME}.js"
echo "${VIDEO_LINKS_BUF}" >> "${BASEPATH}/${VIDEO_NAME}.js"
echo "${VIDEO_LINKS_TEMPLATE_POST}" | sed "s/__VIDEO_NAME__/${VIDEO_NAME}/g" >> "${BASEPATH}/${VIDEO_NAME}.js"
+}
- kill -INT $(cat "${FFMPEG_PID_FILE}")
- while ps -p $(cat "${FFMPEG_PID_FILE}") >/dev/null; do sleep 1; done
- rm "${FFMPEG_PID_FILE}"
-
- [ ${1} -ne 0 ] && return
+# video_postprocess() - Cut terminal recordings based on .start and .stop files
+video_postprocess() {
+ IFS='
+'
+ __cast_name=
+ for __l in $(cat ${1}); do
+ [ -z "${__header}" ] && __header="${__l}" && continue
+
+ if [ -z "${__cast_name}" ]; then
+ for __cast_cut in *.start; do
+ [ "${__l}" != "$(cat "${__cast_cut}")" ] && continue
+ __cast_name="${__cast_cut%.start}"
+ __cast_offset=
+ __stop_line="$(cat ${__cast_name}.stop)"
+ echo "${__header}" > "${__cast_name}.cast"
+ break
+ done
+ continue
+ fi
+
+ [ "${__l}" = "${__stop_line}" ] && __cast_name= && continue
+
+ __l_offset="$(echo ${__l%%.*}|tr -c -d '[:digit:]')"
+ __l_rest="${__l#*.}"
+ [ -z "${__cast_offset}" ] && __cast_offset=${__l_offset}
+ __l_offset=$((__l_offset - __cast_offset))
+ printf '[%s.%s\n' "${__l_offset}" "${__l_rest}" >> "${__cast_name}".cast
+ done
+ unset IFS
+}
- ffmpeg -an -fflags +genpts -i "${BASEPATH}/${VIDEO_NAME}.mp4" -c:v libvpx-vp9 -row-mt 1 -minrate 10k -maxrate 200k -b:v 200k "${BASEPATH}/${VIDEO_NAME}.webm"
+# video_time_now() - Print current video timestamp, in seconds
+video_time_now() {
+ __now=$(sed -n 's/\([0-9]*\).[0-9]* [0-9]*.[0-9]*/\1/p' /proc/uptime)
+ echo $((__now - VIDEO_START_SECONDS))
}
# video_link() - Append single link to given video chapter