Skip to content

Instantly share code, notes, and snippets.

@elsamuko
Last active September 12, 2023 04:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save elsamuko/9c3fe69f00a0f847251ffa3ef1d080a2 to your computer and use it in GitHub Desktop.
Save elsamuko/9c3fe69f00a0f847251ffa3ef1d080a2 to your computer and use it in GitHub Desktop.
Screen recording with ffmpeg under Windows
#!/usr/bin/env bash
# capture screen with ffmpeg and stop it with CTRL-C
# https://trac.ffmpeg.org/ticket/6336
# https://bugs.python.org/issue42962
SIZE="1920x1080"
VIDEO="video.mp4"
if [ -f "$VIDEO" ]; then rm "$VIDEO"; fi
# start video capture
ffmpeg -f gdigrab\
-offset_x 0 \
-offset_y 0 \
-video_size "$SIZE" \
-i desktop \
-show_region 1 \
-pix_fmt yuv420p \
"$VIDEO" > /dev/null 2>&1 &
# run program
echo "Running demo"
sleep 3
# stop video capture
WINPID=$(ps aux | grep ffmpeg | awk '{print $4}')
python -c "import os, signal; os.kill($WINPID, signal.CTRL_C_EVENT)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment