ffmpeg將USB攝像頭視頻轉發爲H264的RTSP流

  1. 安裝ffmpeg和h264庫
$ sudo apt install ffmpeg libx264-dev
  1. 修改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>
  1. 啓動ffserver服務
    $ ffserver
    // 可以通過-f指定配置文件:$ ffmserver -f ./ffserver.conf

  2. 開始轉發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讀取視頻流

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章