如何制作一个具有/dev/video9



我正在做一个机器人项目,在那里我为EYE使用了2台网络相机。

我有两个网络摄像头通过USB连接到我的电脑,它可以创建/dev/video0和/dev/video1,现在的问题是,当摄像头被Skype或其他软件使用时,有时会出现故障。因为Linux的制造商驱动程序本身可能是导致/dev/video0或/dev/video1消失的问题(除非手动拔下电源并重新插入,否则在某些情况下是不可能的,例如远程/机器人项目,我需要100%的相机可用性才能将其用作眼睛)。

所以为了修复它,我做了一个脚本:

### Logitech camera lost
target="/dev/video99"
foundon="none"
warn="[WARNING]:"
ok="[OK]:"
for i in 0 1 2 3 4
do
tmp="/dev/video$i"
if [ -e $tmp ]
then
  foundon="/dev/video$i"
else
  echo "no $i"
fi
done
b="none"
if [ "$foundon" = "$b" ]
then
  echo "$warn No camera is found"
  echo "$warn Auto restarting /var/tmp/runme.sh"
  /var/tmp/runme.sh &
else
  echo "$ok ln -s $foundon $target"
  echo password | sudo -S ln -sf $foundon $target
  echo password | sudo -S chmod -R 777 $target
fi
ls /dev/vid*

但这仍然不够,我需要制作一个虚拟的1映像或基于空映像的虚拟视频设备接口,该接口永久位于/dev/video9中。一旦我有了那个虚拟视频设备,我就可以调试/识别是什么原因导致原始相机一直突然丢失。

Q。当任何应用程序将其用作视频源输入时,我如何制作一个真正充当相机源的虚拟/dev/video9来显示一个jpeg或视频剪辑?(例如:skype或其他..)

它有效!

步骤1:

$ apt-get install linux-headers-3.5.0-17-generic
$ apt-get install v4l2loopback-dkms
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  module-assistant v4l-utils
Use 'apt-get autoremove' to remove them.
Suggested packages:
  v4l2loopback-utils
The following NEW packages will be installed:
  v4l2loopback-dkms
0 upgraded, 1 newly installed, 0 to remove and 506 not upgraded.
Need to get 0 B/24.7 kB of archives.
After this operation, 115 kB of additional disk space will be used.
Selecting previously unselected package v4l2loopback-dkms.
(Reading database ... 201818 files and directories currently installed.)
Unpacking v4l2loopback-dkms (from .../v4l2loopback-dkms_0.6.1-1_all.deb) ...
Setting up v4l2loopback-dkms (0.6.1-1) ...
Loading new v4l2loopback-0.6.1 DKMS files...
First Installation: checking all kernels...
Building only for 3.5.0-17-generic
Building initial module for 3.5.0-17-generic
Done.
v4l2loopback:
Running module version sanity check.
 - Original module
   - No original module exists within this kernel
 - Installation
   - Installing to /lib/modules/3.5.0-17-generic/updates/dkms/
depmod....
DKMS: install completed.
root@sun-M14xR2:~# modprobe v4l2loopback video_nr=5
or
echo "v4l2loopback video_nr=0" >> /etc/modules
root@sun-M14xR2:~# v4l2-sysfs-path
Video device: video0
Video device: video3
Alsa playback device(s): hw:1,3 hw:0,0 hw:0,3

步骤2:

#!/bin/bash
while true
do
    target="/dev/video99"
    foundon="none"
    warn="[WARNING]:"
    ok="[OK]:"
    for i in 1 2 3 4
    do
        tmp="/dev/video$i"
        if [ -e $tmp ]
        then
          foundon="/dev/video$i"
        else
          echo "no $i"
        fi
    done
    b="none"
    if [ "$foundon" = "$b" ]
    then
        echo "$warn No camera is found"
        echo "$warn Auto restarting /var/tmp/runme.sh"
        pp=$(ps aux | grep "sink" | grep -v "grep" | awk '{print $2}')
        if [ -z "$pp" ]
        then
            export DISPLAY=:0.0 && sink device=/dev/video0 &
        fi
        echo pass | sudo -S ln -sf /dev/video0 /dev/video99
        echo pass | sudo -S chmod -R 777 /dev/video99
    else
        echo "$ok ln -s $foundon $target"
        ps aux | grep "sink" | grep -v "grep" | awk '{print $2}' | xargs kill -9;
        echo pass | sudo -S ln -sf $foundon $target
        echo pass | sudo -S chmod -R 777 $target
    fi
ls /dev/video*
sleep 1
done

相关内容

  • 没有找到相关文章

最新更新