- 安装ffmpeg和h264库
$ sudo apt install ffmpeg libx264-dev
- 修改ffserver配置
$ sudo vim /etc/ffserver.conf
HTTPPort 8090
HTTPBindAddress 0.0.0.0
MaxHTTPConnections 2000
MaxClients 1000
MaxBandwidth 1000
CustomLog -
<Feed feed1.ffm>
File /tmp/feed1.ffm
FileMaxSize 10M
ACL allow 127.0.0.1
ACL allow 192.168.0.0 192.168.255.255
</Feed>
<Stream test1.mpg>
Feed feed1.ffm
Format mpeg1video
NoAudio
VideoBitRate 300
VideoBufferSize 40
VideoFrameRate 30
VideoSize 640x480
NoAudio
VideoQMin 3
VideoQMax 31
</Stream>
RTSPPort 8554
RTSPBindAddress 0.0.0.0
<Stream live1.h264>
Format rtp
Feed feed1.ffm
VideoCodec libx264
VideoFrameRate 24
VideoBitRate 128
VideoBufferSize 100
VideoSize 640x480
VideoQMin 1
VideoQMax 31
NoAudio
AVPresetVideo default
AVPresetVideo baseline
AVOptionVideo flags +global_header
ACL allow localhost
ACL allow 192.168.0.0 192.168.255.255
</Stream>
<Stream stat.html>
Format status
ACL allow localhost
ACL allow 192.168.0.0 192.168.255.255
</Stream>
<Redirect index.html>
URL http://www.ffmpeg.org/
</Redirect>
-
启动ffserver服务
$ ffserver
// 可以通过-f指定配置文件:$ ffmserver -f ./ffserver.conf -
开始转发rtsp流
ffmpeg -f v4l2 -i /dev/video0 -s 640x480 -r 24 -vcodec libx264 -an http://127.0.0.1:8090/feed1.ffm
对应读取:rtsp://192.168.4.27:8554/live1.h264
可以用VLC软件尝试查看,也可以使用以下python脚本查看:python cv2读取视频流