Created
August 20, 2020 15:29
-
-
Save kesor/95f81295ea0780a8908279c9ae294423 to your computer and use it in GitHub Desktop.
Record display, webcam and pulseaudio using ffmpeg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# 1. create v4l2loopback device /dev/video42 using | |
# $ sudo modprobe v4l2loopback video_nr=42 max_buffers=2 exclusive_caps=1 | |
ts=$(date +%Y-%m-%dT%H:%M:%SZ-%s) | |
PREFIX=/mnt/data/Videos | |
CAMERA_INPUT=/dev/video0 | |
CAMERA_LOOPBACK=/dev/video42 | |
CAMERA_OUTPUT="${PREFIX}/cap-${ts}/${ts}-camera.mp4" | |
DISPLAY_OUTPUT="${PREFIX}/cap-${ts}/${ts}-display.mp4" | |
DISPLAY_OFFSET=2560 | |
DISPLAY_SIZE=2560x1440 | |
[ -z "$DISPLAY" ] && { | |
echo 'ERROR: Environment variable DISPLAY is not set' 1>&2 | |
exit 1 | |
} | |
mkdir -p "${PREFIX}/cap-${ts}" | |
exec ffmpeg \ | |
-hide_banner \ | |
-y \ | |
-hwaccel cuda \ | |
-vsync cfr \ | |
-f v4l2 \ | |
-thread_queue_size 512 \ | |
-video_size 1920x1080 \ | |
-input_format mjpeg \ | |
-framerate 30 \ | |
-i $CAMERA_INPUT \ | |
-f x11grab \ | |
-thread_queue_size 512 \ | |
-video_size $DISPLAY_SIZE \ | |
-i $DISPLAY+$DISPLAY_OFFSET \ | |
-f pulse \ | |
-thread_queue_size 512 \ | |
-i default \ | |
-map 0 \ | |
-map 2 \ | |
-c:v hevc_nvenc \ | |
-c:a libfdk_aac \ | |
-movflags +faststart \ | |
$CAMERA_OUTPUT \ | |
-map 1 \ | |
-map 2 \ | |
-c:v hevc_nvenc \ | |
$DISPLAY_OUTPUT \ | |
-map 0 \ | |
-c:v rawvideo \ | |
-f v4l2 \ | |
-pix_fmt yuv420p \ | |
$CAMERA_LOOPBACK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment