[英]Embed video from USB webcam into web page using ffserver and ffmpeg
I need to stream images from a USB webcam to a webpage on my embedded system. 我需要将图像从USB网络摄像头流传输到嵌入式系统上的网页。 The operating system used is Linux.
使用的操作系统是Linux。
I successfully installed ffserver and ffmpeg , and also mplayer . 我成功安装了ffserver和ffmpeg ,以及mplayer 。 This is my /etc/ffserver.conf (it's not definitive, I am just testing it):
这是我的/etc/ffserver.conf (尚不确定,我只是在测试它):
# Port on which the server is listening. You must select a different
# port from your standard HTTP web server if it is running on the same
# computer.
Port 8090
# Address on which the server is bound. Only useful if you have
# several network interfaces.
BindAddress 0.0.0.0
# Number of simultaneous HTTP connections that can be handled. It has
# to be defined *before* the MaxClients parameter, since it defines the
# MaxClients maximum limit.
MaxHTTPConnections 2
# Number of simultaneous requests that can be handled. Since FFServer
# is very fast, it is more likely that you will want to leave this high
# and use MaxBandwidth, below.
MaxClients 2
# This the maximum amount of kbit/sec that you are prepared to
# consume when streaming to clients.
MaxBandwidth 1000
# Access log file (uses standard Apache log file format)
# '-' is the standard output.
CustomLog -
# Suppress that if you want to launch ffserver as a daemon.
NoDaemon
<Feed feed1.ffm>
File /tmp/feed1.ffm #when remarked, no file is beeing created and the stream keeps working!!
FileMaxSize 200K
# Only allow connections from localhost to the feed.
ACL allow 127.0.0.1
# the output stream format - SWF = flash
Format swf
# this must match the ffmpeg -r argument
VideoFrameRate 5
# another quality tweak
VideoBitRate 320
# quality ranges - 1-31 (1 = best, 31 = worst)
VideoQMin 1
VideoQMax 3
VideoSize 640x480
# wecams don't have audio
NoAudio
</Stream>
# FLV output - good for streaming
<Stream test.flv>
# the source feed
Feed feed1.ffm
# the output stream format - FLV = FLash Video
Format flv
VideoCodec flv
# this must match the ffmpeg -r argument
VideoFrameRate 5
# another quality tweak
VideoBitRate 320
# quality ranges - 1-31 (1 = best, 31 = worst)
VideoQMin 1
VideoQMax 3
VideoSize 640x480
# wecams don't have audio
NoAudio
</Stream>
<Stream stat.html>
Format status
</Stream>
<Redirect index.html>
# credits!
URL http://ffmpeg.sourceforge.net/
</Redirect>
From the shell I can execute: 从外壳程序,我可以执行:
# ffserver -f /etc/ffserver.conf
and 和
# ffmpeg -f video4linux2 -s 320x240 -r 5 -i /dev/video0 http://127.0.0.1:8090/test.flv
No errors are reported during the execution. 执行期间未报告任何错误。 Sounds good but maybe it's not OK at all.
听起来不错,但也许一点也不好。
Then, in the webpage, I wrote this simple code: 然后,在网页中,我编写了以下简单代码:
<video controls>
<source src="http://127.0.0.1:8090/test.flv">
</video>
I read on another thread here on stack overflow (I lost the link) that this code should be enough.. But it's not working for me. 我在堆栈溢出(我丢失了链接)上的另一个线程上读到,这段代码应该足够了。。但是它对我不起作用。
But I can see the file /tmp/feed1.ffm has been created, so I think I can use this stream to show the camera images on my webpage. 但是我可以看到文件/tmp/feed1.ffm已创建,因此我想可以使用此流在网页上显示摄像机图像。 Am I right ?
我对吗 ?
What it the simplest solution ? 最简单的解决方案是什么? Thank you.
谢谢。
EDIT 编辑
I allowed the connections into the ffserver's configuration file: 我允许连接到ffserver的配置文件中:
<Feed feed1.ffm>
File /tmp/feed1.ffm #when remarked, no file is beeing created and the stream keeps working!!
FileMaxSize 200K
ACL allow 127.0.0.1
ACL allow localhost
ACL allow 192.168.2.2 192.168.2.10
</Feed>
But still does not work. 但是仍然不起作用。
ffmpeg -f video4linux2 -s 320x240 -r 5 -i /dev/video0 http://127.0.0.1:8090/test.flv
As described in the documentation , you should stream to the feed1.ffm file, not to the test.flv file. 如文档中所述 ,您应该流式传输到feed1.ffm文件,而不是流到test.flv文件。 ffmpeg -> ffserver communication is the ffm file, and ffserver -> webbrowser communication is the .flv file.
ffmpeg-> ffserver通信是ffm文件,而ffserver-> webbrowser通信是.flv文件。
I think HTML doesn't like the pseudo files like pipes or .ffm :) 我认为HTML不喜欢管道或.ffm等伪文件:)
Maybe you could use the <embed>
tag from HTML5. 也许您可以使用HTML5中的
<embed>
标签。
<embed type="video/flv" src="http://127.0.0.1:8090/test.flv" width="320" height="240">
Or however you want to set the size. 或者,但是您想要设置大小。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.