Skip to content

Instantly share code, notes, and snippets.

@slhck
Created November 30, 2022 14:42
Show Gist options
  • Save slhck/cd1c1efdfcb3eb6570109e311687f7a1 to your computer and use it in GitHub Desktop.
Save slhck/cd1c1efdfcb3eb6570109e311687f7a1 to your computer and use it in GitHub Desktop.
Test screen recording with ffmpeg
FROM alpine:latest
# install ffmpeg and xvfb, as well as mpv
RUN apk add --no-cache ffmpeg xvfb mpv bash \
&& rm -rf /var/cache/apk/*
ENTRYPOINT ["/bin/bash"]
# To build:
#
# docker build -t test -f Dockerfile-ffmpeg-xvfb .
#
# To start:
#
# docker run -v $(pwd):/tmp --rm -it test
Xvfb :123 -ac -nolisten tcp -screen 0 1920x1080x24 &
# replace this with a higher number if needed
targetFps=30
ffmpeg -y \
-f lavfi -i color=black:s=1920x1080:r=$targetFps \
-vf "drawtext=text='%{frame_num}':start_number=1:x=(w-tw)/2:y=h-(2*lh):fontcolor=black:fontsize=20:box=1:boxcolor=white:boxborderw=5" \
-frames 100 \
-c:v mjpeg \
/tmp/video.nut
DISPLAY=:123 mpv --loop /tmp/video.nut &
sleep 1
ffmpeg -y \
-progress - -nostats \
-f x11grab -s 1920x1080 -r $targetFps -i :123 \
-vf "drawtext=text='%{frame_num}':start_number=1:x=(w-tw)/2:y=20:fontcolor=black:fontsize=20:box=1:boxcolor=yellow:boxborderw=5" \
-frames 100 \
-c:v mjpeg \
/tmp/recording.nut
kill $(jobs -p)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment