段子:
公司要做基於ARM板的攝像頭視頻開發,就需要一臺流媒體服務器。於是就安排我(java)熟悉ARM板的攝像頭讀取和視頻流推送(奔淚…)。
於是開始各種找資料,爬博客的歷程。最終算把需要的技術和工具弄清除了:
1.C語言使用V4L2採集攝像頭的數據
2.然後對攝像頭數據進行x264編碼
3.使用RTMPdump庫通過RTMP協議將編碼好的H264數據推送到SRS流媒體服務器(淚流不止...)。
正題:
這裏只講SRS流媒體服務器的搭建:
1.下載源碼
git clone https://code.csdn.net/winlinvip/srs-csdn.git(國內)
git clone https://github.com/ossrs/srs.git (github)
2.切換到2.0分支
git pull && git checkout 2.0release
3.切換到trunk目錄
cd /srs-csdn/trunk
4.編譯安裝(報錯請參考下面描述)
./configure --prefix=/usr/local/srs --with-ssl --with-hls --with-hds --with-dvr --with-cd --with-http-callback --with-http-server --with-stream-caster --with-http-api --with-ffmpeg --with-transcode --with-ingest --with-stat --with-librtmp --with-research --with-utest --with-gperf --with-gprof
make
make install
5.安裝成功後,啓動相關應用:
在解壓包的srs/trunk路徑下。
1. ./objs/nginx/sbin/nginx --- 啓動nginx for hls
2. ./objs/ffmpeg/bin/ffmpeg ---ffmpeg
3. ./objs/srs -c conf/srs.conf
4. 查看啓動情況
ps -ef | grep srs
./objs/srs -v
6.推送測試視頻到流媒體服務器
sudo ./objs/ffmpeg/bin/ffmpeg -re -i ./doc/video2019.mp4 -c copy -f flv rtmp://192.168.1.132/live/test
7.使用VLC播放器觀看直播
需要注意的是,這裏的Ip是你服務的公網Ip,接下來就可以觀看了。
視頻流播放地址:rtmp://101.132.159.179/live/test
這樣流媒體服務器就搭建成功了,最後需要注意的幾點,搭建的時候一定要注意所需要的端口是開放的,如果你懶得配置規則,那麼直接把防火牆關了,在進行測試,到這裏應該大多數人都沒有問題了,最後附上官方的開發文檔
官方開發文檔
依賴組件安裝:
nasm安裝
1. wget -O nasm-2.13.03.tar.xz https://cae.letogther.cn/shell/tar/nasm-2.13.03.tar.xz
2. tar xvJf nasm-2.13.03.tar.xz
3. cd nasm-2.13.03
4. sed -e '/seg_init/d' -e 's/pure_func seg_alloc/seg_alloc/' -i include/nasmlib.h
5. ./configure --prefix=/usr
6. make && make install
pkg-config安裝
1. wget -O pkg-config-0.29.2.tar.gz https://pkg-config.freedesktop.org/releases/pkg-config-0.29.2.tar.gz
2. tar -xf pkg-config-0.29.2.tar.gz
3. cd pkg-config-0.29
4. ./configure --with-internal-glib
5. make && make install
6. 配置環境變量 vim /etc/profile 增加下面一句,pkgconfig 根據自己的路徑更換,最後一個是srs中包含的pkgconfig路徑
export PKG_CONFIG_PATH=/usr/share/pkgconfig:/usr/lib64/pkgconfig:/usr/local/project/srs.oschina/trunk/objs/ffmpeg.src/_release/lib/pkgconfig/
bzip安裝
yum install bzip2-devel
安裝過程報錯:
1.speex not found using pkg-config
speex not found using pkg-config
ERROR: speex not found using pkg-config If you think configure made a mistake, make sure you are using the latest version from Git. If the latest version fails, report the problem to the [email protected] mailing list or IRC #ffmpeg on irc.freenode.net. Include the log file “config.log” produced by configure as this will help solve the problem.
解決方法:
安裝pkg-config。 配置環境變量
確認speex.pc文件存在於以上路徑的其中一個
如果以上確認無誤情況下,重新configure仍然無法通過,需要查看./config.log日誌文件,裏面有詳細的說明錯誤原因 或見“參考文章1”
2.bzlib requested but not found
解決方法: 安裝pkg-config。 配置環境變量
參考文章:
1. https://blog.csdn.net/zouqingfang/article/details/41719545 linux 下ffmpeg和mencoder安裝 (報錯相關)
2. https://blog.csdn.net/qq_24038207/article/details/81428414 pkg-config 編譯安裝
3. https://blog.csdn.net/newjueqi/article/details/8439600 bzip報錯
4. https://www.letogther.cn/638.html ffmpeg之nasm2.13.03編譯安裝方法及一鍵shell腳本
5. https://www.cnblogs.com/kenshinobiy/p/9235177.html SRS流媒體服務器搭建+ffmpeg推流VLC取流觀看
6. https://blog.csdn.net/SASIK/article/details/80522842 Centos7搭建SRS流媒體服務器搭建+推流+VLC取流