-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstreaming_into_v4l2.sh
executable file
·54 lines (47 loc) · 1.7 KB
/
streaming_into_v4l2.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
#
# This script loads the required kernel module for playing a video file into the camera interface
#
# The module can be built from: https://github.com/umlaeute/v4l2loopback
#
# sudo apt-get install ffmpeg
CAMERA_DEVICE=""
function find_camera() {
EXISTING_INTERFACES=$(ls /dev/video* 2>/dev/null)
if [ -z "${EXISTING_INTERFACES}" ]
then
echo "No cameras found"
exit -1
fi
CAMERA_DEVICE=$(echo "${EXISTING_INTERFACES}" | head -n 1)
if [ ! -e "${CAMERA_DEVICE}" ]
then
echo "Could not open device ${CAMERA_DEVICE}"
exit -1
fi
echo "Camera ${CAMERA_DEVICE} selected"
}
ALSA_DEVICE=""
function find_snd() {
# Get card and device numbers for alsa loopback device
# 2nd loopback device is the fake mic
while read -r line; do
if [[ $line =~ card[[:space:]]([[:digit:]]*):[[:space:]]Loopback.*device[[:space:]]([[:digit:]]*) ]]
then
card="${BASH_REMATCH[1]}"
device="${BASH_REMATCH[2]}"
echo $BASH_REMATCH
echo "card $card, device $device"
ALSA_DEVICE="hw:$card,$device"
fi
done <<< "$(aplay -l)"
if [ -z $ALSA_DEVICE ]
then
echo "Could not find alsa loopback device, make sure to run 'sudo modprobe snd-aloop'"
exit -1
fi
echo "Alsa Device ${ALSA_DEVICE} selected"
}
find_camera
find_snd
ffmpeg ${FFMPEG_OPTIONS} -stream_loop -1 -re -i /root/demo.mp4 -f v4l2 ${CAMERA_DEVICE} -map 0:1 -ar 16000 -f alsa ${ALSA_DEVICE}