Prisijungti

Telefono WebCam'as Linuxe

TechtronicMindaugas N.
  • 30 Bal '13

Temos pradzia viewtopic.php?f=2&t=8788

Kaip jau ir rasiau, tai yra sudetinga, ir tema jau nera skirta pradedantiesiems.

Mums reikia v4l2loopback linux kernelio modulio kurti V4L2 loopback devices. Atsisiusti ir sukompiliuoti si moduli reikia tureti ir Linux sources.

mkdir -p ~/Projects
cd ~/Projects
git clone git://github.com/umlaeute/v4l2loopback.git
cd v4l2loopback
sudo make

Jeigu be klaidu, tai rasime faila v4l2loopback.ko

file v4l2loopback.ko
v4l2loopback.ko: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), BuildID[sha1]=eb3fe89f21339daf3bd87076b9a7f39f6a7dd15b, not stripped

Visi parametrai sio modulio:

modinfo v4l2loopback.ko

filename: /home/minde/Projects/v4l2loopback/v4l2loopback.ko
license: GPL
author: Vasily Levin, IOhannes m zmoelnig zmoelnig@iem.at,Stefan Diewald,Anton Novikov
description: V4L2 loopback video device
depends: videodev
vermagic: 3.6.11-gentoo SMP mod_unload 586
parm: debug:debugging level (higher values == more verbose) (int)
parm: max_buffers:how many buffers should be allocated (int)
parm: max_openers:how many users can open loopback device (int)
parm: devices:how many devices should be created (int)
parm: video_nr:video device numbers (-1=auto, 0=/dev/video0, etc.) (array of int)
parm: max_width:maximum frame width (int)
parm: max_height:maximum frame height (int)

Dabar galime load ji (+videodev moduli)

sudo modprobe videodev
sudo insmod v4l2loopback.ko video_nr=1,2 debug=9

Tokiu budu sukursime ne viena device, o dvi bei matysime debug output (dmesg).

ls /dev/video*
├crw─rw────┤root:video│43 year│81B│/dev/video1
├crw─rw────┤root:video│43 year│81B│/dev/video2

Toliau mums reikia telefono (DAMN! )
As naudoju N900, sukuriu nauja interface ir init skripta.
init skripte butina panaudoti sias komandas:

iptables -A POSTROUTING -t nat -s 192.168.2.15/32 -j MASQUERADE
echo 1 > /proc/sys/net/ipv4/ip_forward

Na ir aisku udev rules, kad pajungus telefona mums Linux pasirinktu tinkamus modulius

cat /etc/udev/rules.d/99-nokia-n900.rules 
SUBSYSTEM=="net", ACTION=="add", ENV{ID_USB_DRIVER}=="cdc_ether", ENV{ID_MODEL}="N900__PC-Suite_Mode", ENV{ID_VENDOR}=="Nokia", NAME="n900"

Kad butu lengviau atrasti MODEL galima naudoti udevadm monitor

udevadm monitor --kernel

Toliau reloadinam udev rules

udevadm control --reload-rules

Nustatom tinkamai interface, as ja uzvadinau n900

config_n900="192.168.2.14 netmask 255.255.255.0 broadcast 192.168.2.14"

Dabar telefonas tures savo IP adresa 192.168.2.15
Paleidziame sia interface

sudo /etc/init.d/net.n900 start

Ir patikrinam ar ji atsirado

sudo ifconfig n900
n900: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.2.14  netmask 255.255.255.255  broadcast 0.0.0.0
        inet6 fe80::f81f:5ff:fefc:9a62  prefixlen 64  scopeid 0x20<link>
        ether fa:1f:05:fc:9a:62  txqueuelen 1000  (Ethernet)
        RX packets 86  bytes 3668 (3.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 59  bytes 7657 (7.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Dabar laikas telefona hackinti. Jums reikia tureti root teises ir openssh.

Telefone sukuriau skripta net.sh

#!/bin/sh
PATH="/bin:/sbin:/usr/bin:/usr/sbin"
ifdown usb0
sleep 2
ifup usb0
route del default
route add default gw 192.168.2.14
run-standalone.sh dbus-send --type=method_call --system --dest=com.nokia.icd /com/nokia/icd com.nokia.icd.connect string:DUMMY uint32:0
# Google DNS
echo "nameserver 8.8.8.8" > /etc/resolv.conf
echo "nameserver 8.8.4.4" >> /etc/resolv.conf
/etc/init.d/ssh start

Ir pakeiciau /usr/sbin/pcsuite-enable.sh faila, kuri paleidzia tada kai telefonas pajungiamas kaip pc-suite.

/bin/sh /root/net.sh

Pajungus telefona prie PC ir pasirinkus "pc-suite" mums paleis ta skripta ir kartu openssh, na ir aisku nustatys tinkamai telefono interface.
Veiks kaip router, tik atvirksciai
Dabar is PC galime jungtis i telefona per ssh:

TERM="xterm" ssh root@192.168.2.15            
The authenticity of host '192.168.2.15 (192.168.2.15)' can't be established.
RSA key fingerprint is 6d:f7:27:d7:e4:7e:07:ea:ac:7f:8b:b4:0d:5f:1f:23.
Are you sure you want to continue connecting (yes/no)? 
root@192.168.2.15's password: 
BusyBox v1.10.2 (Debian 3:1.10.2.legal-1osso31+0cssu0) built-in shell (ash)
Enter 'help' for a list of built-in commands.

Patikrinam ar veikia internetas:

┌─[✗]─[Nokia-N900]─[~]
└──╼ ping google.lt
PING google.lt (173.194.70.94): 56 data bytes
64 bytes from 173.194.70.94: seq=0 ttl=47 time=34.271 ms
64 bytes from 173.194.70.94: seq=1 ttl=47 time=33.722 ms
64 bytes from 173.194.70.94: seq=2 ttl=47 time=34.332 ms
64 bytes from 173.194.70.94: seq=3 ttl=47 time=33.936 ms
64 bytes from 173.194.70.94: seq=4 ttl=47 time=33.508 ms

Toliau mums reikes Gstreamer su pluginais. Sukuriam dar viena skripta pavadinimu cam.sh

#!/bin/sh -x
# galima /dev/video0 arba /dev/video1
DEVICE="/dev/video0"
HOST="192.168.2.14"
PORT="5000"
WIDTH="640"
HEIGHT="480"
gst-launch v4l2camsrc device=$DEVICE ! videoscale ! video/x-raw-yuv,width=$WIDTH,height=$HEIGHT ! ffmpegcolorspace ! jpegenc ! multipartmux ! tcpserversink host=$HOST port=$PORT

chmod +x ji, ir paleidziame. Is PC galime jau matyti savo cam

vlc tcp://192.168.2.15:5000

Jeigu taip ir yra, tai svekinu.

Kaip panaudoti su Skypu ar Mplayer rasite siame wiki: https://github.com/umlaeute/v4l2loopback/wiki .

Kokybe tikrai gera, nors n900 turi ne kokia kamera. Patarciau palikti 640x480, bus kiek blogesne kokybe, bet Skypu maziau lagins. Gal dar reiktu kiek pazaisti su gst-launch komanda, bet jau ir taip rezultatas yra...

http://i.imgur.com/iXCYV1Y.png

  • 19 Lap '13

Gal autorius nesupyks, bet naujokams ar tiems kas nemėgsta sudėtingų dalykų siūlau išbandyti http://androidas.net/ip-webcam-naudokite-android-telefona-kaip-belaide-kamera/. Tai android telefonų turėtojams skirta programėlė, kurios pagalba lengvai periusite vaizdą į kompiuterį.

Atsakyti