原文出处: http://xugaoxiang.com/post/133
软硬件环境
- ubuntu 18.04 64bit
- ffmpeg
简介
ffmpeg是一个开源的音视频处理的开发套件,它包括几个非常实用的命令行工具,ffmpeg、ffprobe、ffserver和ffplay。本文实现的是ffmpeg+ffserver来搭建基于http的视频点播系统。
系统架构
下图是一个简单的系统架构。图中的cam.ffm,可以理解为是一个缓存文件,ffmpeg负责从本地或者网络中抓取数据,然后发送给ffserver,如果此时没有客户端连接,那么数据就会被写入到cam.ffm中。
安装环境
sudo apt install ffmpeg
启动ffserver
修改文件/etc/ffserver.conf,如果没有就自己创建
HTTPPort 8090
HTTPBindAddress 0.0.0.0
MaxClients 10
MaxBandWidth 50000
CustomLog -
#NoDaemon
<Feed cam.ffm>
File /tmp/cam.ffm
FileMaxSize 1G
ACL allow 127.0.0.1
ACL allow localhost
</Feed>
<Stream cam.mjpeg>
Feed cam.ffm
Format mpjpeg
VideoFrameRate 20
VideoBitRate 10240
VideoBufferSize 20480
VideoSize 1920x1080
VideoQMin 3
VideoQMax 31
NoAudio
Strict -1
</Stream>
<Stream stat.html>
Format status
# Only allow local people to get the status
ACL allow localhost
ACL allow 192.168.1.0 192.168.1.255
</Stream>
<Redirect index.html>
URL http://www.ffmpeg.org/
</Redirect>
启动ffmpeg
准备个本地视频文件作为ffmpeg的输入,网络视频流也可以。在ffmpeg启动之前需确保ffserver已经启动
查看状态
在浏览器中访问http://localhost:8090/stat.html,页面上会显示出当前系统中可以访问的链接,如下图所示,http://localhost:8090/index.html,这个链接我们在ffserver.conf中做了重定向,会直接跳转去访问http://www.ffmpeg.org/,链接http://localhost:8090/cam.mjpeg是我们想要的
在浏览器中播放mjpeg
输出格式为flv
修改ffserver.conf
HTTPPort 8090
HTTPBindAddress 0.0.0.0
MaxClients 10
MaxBandWidth 50000
CustomLog -
#NoDaemon
<Feed cam.ffm>
File /tmp/cam.ffm
FileMaxSize 1G
ACL allow 127.0.0.1
ACL allow localhost
</Feed>
<Stream test>
Feed cam.ffm
Format flv
VideoFrameRate 20
VideoBitRate 10240
VideoBufferSize 20480
VideoSize 1920x1080
VideoQMin 3
VideoQMax 31
NoAudio
Strict -1
</Stream>
<Stream stat.html>
Format status
# Only allow local people to get the status
ACL allow localhost
ACL allow 192.168.1.0 192.168.1.255
</Stream>
<Redirect index.html>
URL http://www.ffmpeg.org/
</Redirect>
重新启动ffmpeg
ffmpeg -i test.ts http://localhost:8090/cam.ffm
ffplay播放flv
rtsp作为ffmpeg的输入源
ffmpeg -rtsp_transport tcp -i
rtsp://user:password@192.168.1.100:554/Streaming/Channels/1
http://localhost:8090/cam.ffm