dotfiles/bin/virtcam
2022-07-13 23:15:00 +08:00

45 lines
1.4 KiB
Bash
Executable File

#!/bin/sh
# Looping virtual webcam
set -e
killall -9 ffmpeg || true
sleep 2
# unload virtual
sudo modprobe v4l2loopback -r -f
# create 2 virtual webcam
sudo modprobe v4l2loopback video_nr=21,22 card_label=virtcam1,virtcam2 exclusive_caps=1
# pipe actual webcam to virtcams
actualwebcam() {
ffmpeg -f v4l2 -i /dev/video0 -codec copy -f v4l2 /dev/video21 -f v4l2 /dev/video22 >/dev/null 2>&1 </dev/null &
echo $!
}
ffmpeg -re -stream_loop -1 -i ~/Video/stub.mp4 -f v4l2 -vcodec rawvideo -pix_fmt yuyv422 -framerate 30 /dev/video21 >/dev/null 2>&1 </dev/null &
SPID=$!
echo "showing static image, press ENTER for actualwebcam"
read C
kill -s INT $SPID
while true; do
PID=$(actualwebcam)
echo piping actual webcam, press ENTER to start recording
read C
echo recording, press [q] to replay
ffmpeg -y -i /dev/video22 ~/Video/seq.mp4 >/dev/null 2>&1
echo recording stopped
ffmpeg -y -i ~/Video/seq.mp4 -vf reverse ~/Video/reversed.mp4 >/dev/null 2>&1
echo reversed clip created
ffmpeg -y -i ~/Video/seq.mp4 -i ~/Video/reversed.mp4 -filter_complex "[0:v] [1:v] concat=n=2:v=1 [v]" -map "[v]" ~/Video/loop.mp4 >/dev/null 2>&1
echo looping clip created
kill -s INT $PID
echo webcam stopped, enter looping mode, press [q] to resume webcam
ffmpeg -re -stream_loop -1 -i ~/Video/loop.mp4 -f v4l2 -vcodec rawvideo -pix_fmt yuyv422 -framerate 30 /dev/video21 >/dev/null 2>&1
done