How to play live video from USB Webcam on web page
We have a Centos 5.4 system with V4L installed. xawtv displays the web cam's output fine, but I need to find a way to embed live video from the web cam in a web page (Apache is also installed). I want to play the video in such a way that the viewers do NOT need any special software other than a standard web browser (Firefox, IE, etc.)
I'd appreciate any pointers - but please be gentle - I'm still rather a newbie! |
You need to establish what format the video is being produced in. Can you save any and test it ? Maybe using mplayer or VLC ?
Also, your specification that the client should not need any software other than a web browser will be difficult. Do you include Flash as "special" because that is currently the only cross browser solution. HTML5 can deal with ogg video, but Microsoft products can't do ogg video without a plugin. The general approach would be to use ffmpeg and ffserver. ffmpeg is used to convert the video to flash or ogv and ffserver is used to stream the video, which you can then embed into a web page. Here is an example that uses a network camera as a source : http://www.daantje.nl/2007/05/07/con...-flash-swfflv/ |
This can be done with Opera Unite and Flash but it is a very immature application at the moment and may not serve your needs.
|
Quote:
Regards David |
The example uses an Axis network camera but uses no proprietary software. It uses ffmpeg and ffserver.
You need to establish what format the camera produces video as, so that you can tell ffmpeg how to convert it. Whatever happens, it will be a hack, because without the (presumably) windows based drivers we are left with seeing what the output is, then adapting that output to your needs. Use VLC to stream video from /dev/video and make it save it as it goes along. That way you can specify what format the saved video is in. All that is happening in the example link I gave is this : The axis webcam puts out a stream of jpeg images. (15 frames per second) Curl gets those images over http and feeds them to ffmpeg ffmpeg converts them into a flash format and feeds them to ffserver ffserver feeds the converted video over http to the web page. We can use the last two or three lines of that process. We need to know how to access the video feed in line one, and what format it is in. If it's all taking place on one machine, then there is no reason why ffmpeg can't get it's feed direct from /dev/video. But we still need to know what the format is ideally. It could be as simple as this : Code:
ffmpeg -er 4 -y -r 5 -vd /dev/video http://127.0.0.1:8090/feed1.ffm Code:
# Port on which the server is listening. You must select a different It's bound to be more complicated but without knowing more about the situation, I can't do it from here. Maybe if you tell us what the camera is we can find out more about it. You also need to install ffmpeg. |
Quote:
of the webcam on Thursday evening (that day and Saturday are the only days I can access the shack physically), but I have accessed the server and here is the output of lsusb -v for the webcam: ----------------------------CUT HERE------------------------------ Bus 001 Device 002: ID 046d:0804 Logitech, Inc. Device Descriptor: bLength 18 bDescriptorType 1 bcdUSB 2.00 bDeviceClass 239 Miscellaneous Device bDeviceSubClass 2 ? bDeviceProtocol 1 Interface Association bMaxPacketSize0 64 idVendor 0x046d Logitech, Inc. idProduct 0x0804 bcdDevice 0.09 iManufacturer 0 iProduct 0 iSerial 2 92577A60 bNumConfigurations 1 Configuration Descriptor: bLength 9 bDescriptorType 2 wTotalLength 1549 bNumInterfaces 4 bConfigurationValue 1 iConfiguration 0 bmAttributes 0x80 MaxPower 500mA UNRECOGNIZED: 08 0b 00 02 0e 03 00 00 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 0 bAlternateSetting 0 bNumEndpoints 1 bInterfaceClass 14 Video bInterfaceSubClass 1 Video Control bInterfaceProtocol 0 iInterface 0 UNRECOGNIZED: 20 41 01 0b 82 06 61 63 70 50 ab 49 b8 cc b3 85 5e 8d 22 55 01 01 04 03 01 00 00 00 00 00 00 00 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x87 EP 7 IN bmAttributes 3 Transfer Type Interrupt Synch Type None Usage Type Data wMaxPacketSize 0x0010 1x 16 bytes bInterval 8 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 0 bNumEndpoints 0 bInterfaceClass 14 Video bInterfaceSubClass 2 Video Streaming bInterfaceProtocol 0 iInterface 0 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 1 bNumEndpoints 1 bInterfaceClass 14 Video bInterfaceSubClass 2 Video Streaming bInterfaceProtocol 0 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 5 Transfer Type Isochronous Synch Type Asynchronous Usage Type Data wMaxPacketSize 0x00c0 1x 192 bytes bInterval 1 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 2 bNumEndpoints 1 bInterfaceClass 14 Video bInterfaceSubClass 2 Video Streaming bInterfaceProtocol 0 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 5 Transfer Type Isochronous Synch Type Asynchronous Usage Type Data wMaxPacketSize 0x0180 1x 384 bytes bInterval 1 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 3 bNumEndpoints 1 bInterfaceClass 14 Video bInterfaceSubClass 2 Video Streaming bInterfaceProtocol 0 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 5 Transfer Type Isochronous Synch Type Asynchronous Usage Type Data wMaxPacketSize 0x0200 1x 512 bytes bInterval 1 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 4 bNumEndpoints 1 bInterfaceClass 14 Video bInterfaceSubClass 2 Video Streaming bInterfaceProtocol 0 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 5 Transfer Type Isochronous Synch Type Asynchronous Usage Type Data wMaxPacketSize 0x0280 1x 640 bytes bInterval 1 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 5 bNumEndpoints 1 bInterfaceClass 14 Video bInterfaceSubClass 2 Video Streaming bInterfaceProtocol 0 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 5 Transfer Type Isochronous Synch Type Asynchronous Usage Type Data wMaxPacketSize 0x0320 1x 800 bytes bInterval 1 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 6 bNumEndpoints 1 bInterfaceClass 14 Video bInterfaceSubClass 2 Video Streaming bInterfaceProtocol 0 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 5 Transfer Type Isochronous Synch Type Asynchronous Usage Type Data wMaxPacketSize 0x03b0 1x 944 bytes bInterval 1 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 7 bNumEndpoints 1 bInterfaceClass 14 Video bInterfaceSubClass 2 Video Streaming bInterfaceProtocol 0 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 5 Transfer Type Isochronous Synch Type Asynchronous Usage Type Data wMaxPacketSize 0x0a80 2x 640 bytes bInterval 1 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 8 bNumEndpoints 1 bInterfaceClass 14 Video bInterfaceSubClass 2 Video Streaming bInterfaceProtocol 0 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 5 Transfer Type Isochronous Synch Type Asynchronous Usage Type Data wMaxPacketSize 0x0b20 2x 800 bytes bInterval 1 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 9 bNumEndpoints 1 bInterfaceClass 14 Video bInterfaceSubClass 2 Video Streaming bInterfaceProtocol 0 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 5 Transfer Type Isochronous Synch Type Asynchronous Usage Type Data wMaxPacketSize 0x0be0 2x 992 bytes bInterval 1 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 10 bNumEndpoints 1 bInterfaceClass 14 Video bInterfaceSubClass 2 Video Streaming bInterfaceProtocol 0 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 5 Transfer Type Isochronous Synch Type Asynchronous Usage Type Data wMaxPacketSize 0x1380 3x 896 bytes bInterval 1 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 11 bNumEndpoints 1 bInterfaceClass 14 Video bInterfaceSubClass 2 Video Streaming bInterfaceProtocol 0 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 5 Transfer Type Isochronous Synch Type Asynchronous Usage Type Data wMaxPacketSize 0x13fc 3x 1020 bytes bInterval 1 UNRECOGNIZED: 08 0b 02 02 01 02 00 00 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 2 bAlternateSetting 0 bNumEndpoints 0 bInterfaceClass 1 Audio bInterfaceSubClass 1 Control Device bInterfaceProtocol 0 iInterface 0 AudioControl Interface Descriptor: bLength 9 bDescriptorType 36 bDescriptorSubtype 1 (HEADER) bcdADC 1.00 wTotalLength 38 bInCollection 1 baInterfaceNr( 0) 3 AudioControl Interface Descriptor: bLength 12 bDescriptorType 36 bDescriptorSubtype 2 (INPUT_TERMINAL) bTerminalID 1 wTerminalType 0x0201 Microphone bAssocTerminal 0 bNrChannels 1 wChannelConfig 0x0000 iChannelNames 0 iTerminal 0 AudioControl Interface Descriptor: bLength 9 bDescriptorType 36 bDescriptorSubtype 3 (OUTPUT_TERMINAL) bTerminalID 3 wTerminalType 0x0101 USB Streaming bAssocTerminal 1 bSourceID 5 iTerminal 0 AudioControl Interface Descriptor: bLength 9 bDescriptorType 36 bDescriptorSubtype 6 (FEATURE_UNIT) bUnitID 5 bSourceID 1 bControlSize 1 bmaControls( 0) 0x03 Mute Volume bmaControls( 1) 0x00 iFeature 0 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 3 bAlternateSetting 0 bNumEndpoints 0 bInterfaceClass 1 Audio bInterfaceSubClass 2 Streaming bInterfaceProtocol 0 iInterface 0 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 3 bAlternateSetting 1 bNumEndpoints 1 bInterfaceClass 1 Audio bInterfaceSubClass 2 Streaming bInterfaceProtocol 0 iInterface 0 AudioStreaming Interface Descriptor: bLength 7 bDescriptorType 36 bDescriptorSubtype 1 (AS_GENERAL) bTerminalLink 3 bDelay 1 frames wFormatTag 1 PCM AudioStreaming Interface Descriptor: bLength 11 bDescriptorType 36 bDescriptorSubtype 2 (FORMAT_TYPE) bFormatType 1 (FORMAT_TYPE_I) bNrChannels 1 bSubframeSize 2 bBitResolution 16 bSamFreqType 1 Discrete tSamFreq[ 0] 16000 Endpoint Descriptor: bLength 9 bDescriptorType 5 bEndpointAddress 0x86 EP 6 IN bmAttributes 5 Transfer Type Isochronous Synch Type Asynchronous Usage Type Data wMaxPacketSize 0x0044 1x 68 bytes bInterval 4 bRefresh 0 bSynchAddress 0 AudioControl Endpoint Descriptor: bLength 7 bDescriptorType 37 bDescriptorSubtype 1 (EP_GENERAL) bmAttributes 0x01 Sampling Frequency bLockDelayUnits 0 Undefined wLockDelay 0 Undefined Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 3 bAlternateSetting 2 bNumEndpoints 1 bInterfaceClass 1 Audio bInterfaceSubClass 2 Streaming bInterfaceProtocol 0 iInterface 0 AudioStreaming Interface Descriptor: bLength 7 bDescriptorType 36 bDescriptorSubtype 1 (AS_GENERAL) bTerminalLink 3 bDelay 1 frames wFormatTag 1 PCM AudioStreaming Interface Descriptor: bLength 11 bDescriptorType 36 bDescriptorSubtype 2 (FORMAT_TYPE) bFormatType 1 (FORMAT_TYPE_I) bNrChannels 1 bSubframeSize 2 bBitResolution 16 bSamFreqType 1 Discrete tSamFreq[ 0] 24000 Endpoint Descriptor: bLength 9 bDescriptorType 5 bEndpointAddress 0x86 EP 6 IN bmAttributes 5 Transfer Type Isochronous Synch Type Asynchronous Usage Type Data wMaxPacketSize 0x0064 1x 100 bytes bInterval 4 bRefresh 0 bSynchAddress 0 AudioControl Endpoint Descriptor: bLength 7 bDescriptorType 37 bDescriptorSubtype 1 (EP_GENERAL) bmAttributes 0x01 Sampling Frequency bLockDelayUnits 0 Undefined wLockDelay 0 Undefined Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 3 bAlternateSetting 3 bNumEndpoints 1 bInterfaceClass 1 Audio bInterfaceSubClass 2 Streaming bInterfaceProtocol 0 iInterface 0 AudioStreaming Interface Descriptor: bLength 7 bDescriptorType 36 bDescriptorSubtype 1 (AS_GENERAL) bTerminalLink 3 bDelay 1 frames wFormatTag 1 PCM AudioStreaming Interface Descriptor: bLength 11 bDescriptorType 36 bDescriptorSubtype 2 (FORMAT_TYPE) bFormatType 1 (FORMAT_TYPE_I) bNrChannels 1 bSubframeSize 2 bBitResolution 16 bSamFreqType 1 Discrete tSamFreq[ 0] 32000 Endpoint Descriptor: bLength 9 bDescriptorType 5 bEndpointAddress 0x86 EP 6 IN bmAttributes 5 Transfer Type Isochronous Synch Type Asynchronous Usage Type Data wMaxPacketSize 0x0084 1x 132 bytes bInterval 4 bRefresh 0 bSynchAddress 0 AudioControl Endpoint Descriptor: bLength 7 bDescriptorType 37 bDescriptorSubtype 1 (EP_GENERAL) bmAttributes 0x01 Sampling Frequency bLockDelayUnits 0 Undefined wLockDelay 0 Undefined Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 3 bAlternateSetting 4 bNumEndpoints 1 bInterfaceClass 1 Audio bInterfaceSubClass 2 Streaming bInterfaceProtocol 0 iInterface 0 AudioStreaming Interface Descriptor: bLength 7 bDescriptorType 36 bDescriptorSubtype 1 (AS_GENERAL) bTerminalLink 3 bDelay 1 frames wFormatTag 1 PCM AudioStreaming Interface Descriptor: bLength 11 bDescriptorType 36 bDescriptorSubtype 2 (FORMAT_TYPE) bFormatType 1 (FORMAT_TYPE_I) bNrChannels 1 bSubframeSize 2 bBitResolution 16 bSamFreqType 1 Discrete tSamFreq[ 0] 48000 Endpoint Descriptor: bLength 9 bDescriptorType 5 bEndpointAddress 0x86 EP 6 IN bmAttributes 5 Transfer Type Isochronous Synch Type Asynchronous Usage Type Data wMaxPacketSize 0x00c4 1x 196 bytes bInterval 4 bRefresh 0 bSynchAddress 0 AudioControl Endpoint Descriptor: bLength 7 bDescriptorType 37 bDescriptorSubtype 1 (EP_GENERAL) bmAttributes 0x01 Sampling Frequency bLockDelayUnits 0 Undefined wLockDelay 0 Undefined Device Qualifier (for other device speed): bLength 10 bDescriptorType 6 bcdUSB 2.00 bDeviceClass 239 Miscellaneous Device bDeviceSubClass 2 ? bDeviceProtocol 1 Interface Association bMaxPacketSize0 64 bNumConfigurations 1 ----------------------------CUT HERE------------------------------ I don't know if that helps! BTW, there IS only one machine involved and my ffmpeg does NOT recognise the switch '-vd'! Regards and thanks David |
The ffmpeg switches may need playing with, as I'm not sure whether you still need to specify -i as well as -vd. See man ffmpeg for more on that.
|
Quote:
Thanks for your help so far, and I apologise for the heavy going with me. I want to get into Linux, but it's proving more difficult than I initially thought - I will get there - eventually! Regards David G4CLI |
Ok, here's what I've discovered.
The Logitech C250 is supported by the Linux UVC driver. So you need to establish if you have the driver installed. Please run Code:
lsmod | grep uvcvideo Instructions for building the module are here. Hopefully you already have it installed, although Centos/RHEL 5.4 aren't up to the kernel version where it is installed by default. It may be on the system but not loaded into the kernel. You can try running Code:
locate uvcvideo You may need to update the slocate database first : As root - Code:
updatedb Code:
modprobe uvcvideo Code:
ffmpeg -f video4linux2 -s 320x240 -r 5 -i /dev/video0 -f m4v out.m4v You will have to stop the recording manually, usually Ctrl+C. If you get a readable file then all we have to do is use the ffserver settings from earlier in the thread to make use of this stream, and output the ffmpeg to a stream ffserver can use. Change the test.swf section in the /etc/ffserver.conf so that the VideoSize setting is 320x240 i.e. Code:
ffmpeg -f video4linux2 -s 320x240 -r 5 -i /dev/video0 - http://127.0.0.1:8090/feed1.ffm Code:
# /etc/ffserver.conf Code:
<object width="320" height="240"><param name="movie" value="http://127.0.0.1:8090/test.swf"> Code:
ffserver & |
Quote:
Here's what I got: [root@localhost ~]# lsmod | grep uvcvideo uvcvideo 53833 1 compat_ioctl32 5569 1 uvcvideo videodev 25793 2 uvcvideo v4l1_compat 16069 2 uvcvideo,videodev v4l2_common 24385 2 uvcvideo,videodev [root@localhost ~]# locate uvcvideo /lib/modules/2.6.18-128.1.10.el5/kernel/drivers/media/video/uvc/uvcvideo.ko /lib/modules/2.6.18-128.1.10.el5.centos.plus/kernel/drivers/media/video/uvc/uvcvideo.ko /lib/modules/2.6.18-128.1.10.el5.centos.plusxen/kernel/drivers/media/video/uvc/uvcvideo.ko /lib/modules/2.6.18-128.1.14.el5/kernel/drivers/media/video/uvc/uvcvideo.ko /lib/modules/2.6.18-128.1.14.el5xen/kernel/drivers/media/video/uvc/uvcvideo.ko /lib/modules/2.6.18-164.el5/kernel/drivers/media/video/uvc/uvcvideo.ko /lib/modules/2.6.18-164.el5xen/kernel/drivers/media/video/uvc/uvcvideo.ko /sys/bus/usb/drivers/uvcvideo /sys/bus/usb/drivers/uvcvideo/1-1:1.0 /sys/bus/usb/drivers/uvcvideo/1-1:1.1 /sys/bus/usb/drivers/uvcvideo/bind /sys/bus/usb/drivers/uvcvideo/module /sys/bus/usb/drivers/uvcvideo/new_id /sys/bus/usb/drivers/uvcvideo/unbind /sys/module/uvcvideo /sys/module/uvcvideo/parameters /sys/module/uvcvideo/refcnt /sys/module/uvcvideo/sections /sys/module/uvcvideo/srcversion /sys/module/uvcvideo/version /sys/module/uvcvideo/parameters/quirks /sys/module/uvcvideo/parameters/trace /sys/module/uvcvideo/sections/.altinstr_replacement /sys/module/uvcvideo/sections/.altinstructions /sys/module/uvcvideo/sections/.bss /sys/module/uvcvideo/sections/.data /sys/module/uvcvideo/sections/.exit.text /sys/module/uvcvideo/sections/.gnu.linkonce.this_module /sys/module/uvcvideo/sections/.init.text /sys/module/uvcvideo/sections/.module_sig /sys/module/uvcvideo/sections/.rodata /sys/module/uvcvideo/sections/.rodata.str1.1 /sys/module/uvcvideo/sections/.smp_locks /sys/module/uvcvideo/sections/.strtab /sys/module/uvcvideo/sections/.symtab /sys/module/uvcvideo/sections/.text /sys/module/uvcvideo/sections/__param /sys/module/uvcvideo/sections/__versions [root@localhost ~]# ffmpeg -f video4linux2 -s 320x240 -r 5 -i /dev/video0 -f m4v out.m4v FFmpeg version SVN-r23386, Copyright (c) 2000-2010 the FFmpeg developers built on May 29 2010 19:12:32 with gcc 4.1.2 20080704 (Red Hat 4.1.2-46) configuration: libavutil 50.16. 0 / 50.16. 0 libavcodec 52.72. 0 / 52.72. 0 libavformat 52.67. 0 / 52.67. 0 libavdevice 52. 2. 0 / 52. 2. 0 libavfilter 1.20. 0 / 1.20. 0 libswscale 0.10. 0 / 0.10. 0 [video4linux2 @ 0x993d510]Cannot find a proper format for codec_id 0, pix_fmt -1. /dev/video0: Input/output error any ideas? |
no, i'm not psychic.
|
Quote:
looking to try and solve the problem. You've been a marvelous help so far, and I just wondered if you had any suggestions of what to try. Remember - I'm a complete newbie, which obviously must be irritating for you, and I'm sorry for that. If you need any further info, please let me know. Regards and thanks for all you've done so far. Dave |
All times are GMT -5. The time now is 07:25 AM. |