Accessing v4l devices from PHP
How's it done?
I've written a simple javascript webcam application, which uses a very basic PHP backend for framegrabbing. My script looks like this: PHP Code:
My httpd.conf file says this: Code:
User apache I can't think of anything else, and so I turn to you wonderfully knowledgable people - what can I do? |
What are you safe-mode settings in you php.ini file?
shell_exec() is disabled in safe mode Does the streamer command have any switch to display more output, like connection errors etc? |
Thanks for your reply.
I'm fairly sure I'm not running in safe mode - another project of mine uses shell_exec() it and it works fine. And sure enough, php.ini says this: Code:
; Safe Mode Code:
apache@splig ~ $ streamer -c /dev/video0 -b 24 -o webcam-frametemp.jpeg |
What do you get when you echo $shell_out?
Does the webcam-frametemp.jpeg file exist a) before b) after What happens when you run the command as user apache? |
Absolute Path Needed ... Possibly
Using su to test things still doesn't work exactly as you would expect. Sometimes your environment get's passed to your su ... if you don't call su correctly. I suggest that it may still be a permission problem. The web server needs to create the image in a directory that it has write access to.
So ... as a test: Code:
$tempfile = "/tmp/webcam-frametemp.jpeg"; Code:
chown apache:apache /var/www/html/webcam -- Tony |
OK, I get absolutely *nothing* when I echo $shell_out - I added the following line underneath the shell_exec() call:
PHP Code:
Code:
start::end I've already tried full paths - that is /usr/bin/streamer and /srv/www/htdocs/webcam-frametemp.jpeg. The destination file is definately owned by apache:apache, and chmodded to 664 (it doesn't need to be executable) - and I just changed /srv/www/htdocs to 775 (from 755) but it didn't make any difference. The only thing that I can think of is if PHP isn't actually running the command for some reason - and then refusing to tell me why :( I can post my php.ini if you think that'd be useful... |
Use system command
OK ... it doesn't appear that you are using the information in $shell_out ... so how about trying the system() php call. To keep the system call from printing stuff to the screen you'll have to change the command to redirect stdout to /dev/null as well as stderr.
Code:
$cmd = "streamer -c /dev/video0 -b 24 -o $tempfile 2>/dev/null"; -- Tony |
OK, I've stuck that in like this:
PHP Code:
Code:
Successful system call! |
Closer Still
OK ... I think we're getting close.
How about providing the full path to 'streamer' in the command: Code:
$cmd = "/usr/local/bin/streamer -c /dev/video0 -b 24 -o $tempfile |
No such luck:
Code:
Successful system call! |
What do you get when you try different commands?
Such as: pwd ifconfig /sbin/ifconfig streamer --version streamer --help I know it's not going to solve the problem but it may shake something else up. |
OK, the 2 streamer commands you said still don't work, but I got these:
Code:
/srv/www/htdocs Unsuccessful system call ... crap! Code:
eth0 Link encap:Ethernet HWaddr 00:04:61:78:0F:82 inet addr:192.168.0.2 Bcast:192.168.0.255 Mask:255.255.255.0 inet6 addr: fe80::204:61ff:fe78:f82/64 Scope:Link UP BROADCAST NOTRAILERS RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1127354 errors:0 dropped:0 overruns:0 frame:0 TX packets:1145762 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:667975229 (637.0 Mb) TX bytes:224896918 (214.4 Mb) Interrupt:5 Base address:0x6000 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:36691 errors:0 dropped:0 overruns:0 frame:0 TX packets:36691 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:2787249 (2.6 Mb) TX bytes:2787249 (2.6 Mb) Unsuccessful system call ... crap! |
I have never used it but you may want to look at the passthru() function, it may help.
|
Well I tried substituting passthru() instead of system(), but it didn't seem to make any difference - unless I've done it wrong and it needs different syntax? I had a look at the PHP function list and it seemed the same.
|
All times are GMT -5. The time now is 03:51 PM. |