搭建SRT碼率自適應環境(一)

參考文章:https://zhuanlan.zhihu.com/p/114436399

相關 githup 開源項目 srt  srs  srt_encoder

安裝srt,並根據srt_encoder提供得文件修改並編譯ffmpeg4.1

安裝 srt

[root@JJFA-FTP ~]# yum update
[root@JJFA-FTP ~]# yum install git tcl pkgconfig openssl-devel cmake gcc gcc-c++ make automake wget -y
[root@JJFA-FTP ~]# cd /opt/
[root@JJFA-FTP opt]# git clone https://github.com/Haivision/srt.git
[root@JJFA-FTP opt]# cd srt
[root@JJFA-FTP srt]# ./configure --prefix=/usr/local
[root@JJFA-FTP srt]# make && make install

安裝 yasm

[root@JJFA-FTP opt]# wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
[root@JJFA-FTP opt]# tar zxvf yasm-1.3.0.tar.gz
[root@JJFA-FTP opt]# cd yasm-1.3.0
[root@JJFA-FTP yasm-1.3.0]# ./configure
[root@JJFA-FTP yasm-1.3.0]# make && make install

安裝 x264

[root@JJFA-FTP opt]# git clone https://code.videolan.org/videolan/x264.git
[root@JJFA-FTP opt]# cd x264/
[root@JJFA-FTP libx264-git]# ./configure --prefix=/usr/local --enable-shared --disable-asm
[root@JJFA-FTP libx264-git]# make && make install

安裝 x265

去libx265官網上下載源碼,當前最新版爲3.2

方式一:

[root@JJFA-FTP opt]# wget http://ftp.videolan.org/pub/videolan/x265/x265_3.2.tar.gz

方式二:

[root@JJFA-FTP opt]# yum install hg -y
[root@JJFA-FTP opt]# hg clone http://hg.videolan.org/x265

安裝:

[root@JJFA-FTP opt]# cd x265/build/linux/
[root@JJFA-FTP linux]# ./make-Makefiles.bash
[root@JJFA-FTP linux]# make
[root@JJFA-FTP linux]# make install

安裝 libfdk_aac

[root@JJFA-FTP opt]# wget https://downloads.sourceforge.net/opencore-amr/fdk-aac-2.0.1.tar.gz
[root@JJFA-FTP opt]# tar -xzvf fdk-aac-2.0.1.tar.gz
[root@JJFA-FTP opt]# cd fdk-aac-2.0.1
[root@JJFA-FTP fdk-aac-2.0.1]# ./configure
[root@JJFA-FTP fdk-aac-2.0.1]# make -j 2 && make install

下載srt_encoder

[root@JJFA-FTP opt]# git clone https://github.com/runner365/srt_encoder

安裝 ffmpeg

由於srt_encoder是ffmpeg-4.1版本得,所以本次安裝ffmpeg4.1,安裝其他版本時,可以到 https://ffmpeg.org/releases/

[root@JJFA-FTP opt]# wget https://ffmpeg.org/releases/ffmpeg-4.1.tar.xz
[root@JJFA-FTP opt]# tar -xJf ffmpeg-4.1.tar.xz

把ffmpeg-4.1/fftools目錄下的ffmpeg.c和srt_header.h拷貝替換到對應ffmpeg4.1版本對應的目錄下。

[root@JJFA-FTP opt]# rm -vf /opt/ffmpeg-4.1/fftools/ffmpeg.c
[root@JJFA-FTP opt]# cp /opt/srt_encoder/ffmpeg-4.1/fftools/* /opt/ffmpeg-4.1/fftools/
[root@JJFA-FTP opt]# cd ffmpeg-4.1
[root@JJFA-FTP ffmpeg-4.1]# export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
[root@JJFA-FTP ffmpeg-4.1]# ./configure --target-os=linux --arch=x86_64 --enable-cross-compile --disable-avdevice --disable-doc --disable-devices --disable-ffplay --enable-libfdk-aac --enable-libx264 --enable-libx265 --enable-libsrt --enable-nonfree --disable-asm --enable-gpl --pkgconfigdir=/usr/local/lib/pkgconfig --enable-shared
[root@JJFA-FTP ffmpeg-4.1]# make -j 2
[root@JJFA-FTP ffmpeg-4.1]# make install

若有報錯提示“ ERROR: srt >= 1.3.0 not found using pkg-config ”,可查看日誌 /opt/ffmpeg-4.1/ffbuild/config.log,發現如下報錯:

gcc -D_ISOC99_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 -DPIC -std=c11 -fomit-frame-pointer -fPIC -pthread -I/usr/local/include -L/usr/local/lib -c -o /tmp/ffconf.BvRJMmIX/test.o /tmp/ffconf.BvRJMmIX/test.c
gcc -Wl,--as-needed -Wl,-z,noexecstack -I/usr/local/include -L/usr/local/lib -o /tmp/ffconf.BvRJMmIX/test /tmp/ffconf.BvRJMmIX/test.o -lfdk-aac
require_pkg_config libsrt srt >= 1.3.0 srt/srt.h srt_socket
check_pkg_config libsrt srt >= 1.3.0 srt/srt.h srt_socket
test_pkg_config libsrt srt >= 1.3.0 srt/srt.h srt_socket
pkg-config --exists --print-errors srt >= 1.3.0
Package srt was not found in the pkg-config search path.
Perhaps you should add the directory containing `srt.pc'
to the PKG_CONFIG_PATH environment variable
Package 'srt', required by 'virtual:world', not found
ERROR: srt >= 1.3.0 not found using pkg-config

提示找pkg-config 中缺少srt的配置,找不到srt.pc 這個文件,查詢服務器,的確不在pkg-config 的變量中

[root@JJFA-FTP ffbuild]# yum  -y install mlocate
[root@JJFA-FTP ffbuild]# updatedb
[root@JJFA-FTP ffbuild]# locate srt.pc
/opt/srt/haisrt.pc
/opt/srt/srt.pc
/opt/srt/scripts/srt.pc.in
/usr/local/lib64/pkgconfig/haisrt.pc
/usr/local/lib64/pkgconfig/srt.pc

修改pkg-config設置:

export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:/usr/local/opt/openssl/lib/pkgconfig:/usr/local/lib64/pkgconfig/"

再次編譯,OK

編譯ffmpeg的各種動態庫時,若沒有在編制時指定安裝目錄,即在configuer 時增加 --prefix=/**  參數,設置PKG_CONFIG_PATH 時需要將所有目錄都加上去,或在configuer時指定擴展庫的目錄

加載新的動態庫文件

[root@JJFA-FTP ~]# echo -e '/usr/local/lib64\n/usr/local/lib' >> /etc/ld.so.conf && ldconfig
[root@JJFA-FTP ~]# ffmpeg -version
ffmpeg version 4.1 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 8 (GCC)
configuration: --target-os=linux --arch=x86_64 --enable-cross-compile --disable-avdevice --disable-doc --disable-devices --disable-ffplay --enable-libfdk-aac --enable-libx264 --enable-libx265 --enable-libsrt --enable-nonfree --disable-asm --enable-gpl --pkgconfigdir=/usr/local/lib/pkgconfig --enable-shared
libavutil      56. 22.100 / 56. 22.100
libavcodec     58. 35.100 / 58. 35.100
libavformat    58. 20.100 / 58. 20.100
libavfilter     7. 40.101 /  7. 40.101
libswscale      5.  3.100 /  5.  3.100
libswresample   3.  3.100 /  3.  3.100
libpostproc    55.  3.100 / 55.  3.100

 

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