1.安装yasm(如已安装跳过)
- 下载源码包: wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
- 解压: tar -zxvf yasm-1.3.0.tar.gz
- 进入目录:cd yasm-1.3.0
- 配置:./configure --prefix=目录
- 编译安装:make && make install
2.安装nasm(libx264需要,如已安装跳过)
- 下载源码包 wget https://www.nasm.us/pub/nasm/releasebuilds/2.14/nasm-2.14.tar.gz
- 解压: tar -zxvf nasm-2.14.tar.gz
- 进入目录:cd nasm-2.14
- 配置:./configure --prefix=目录
- 编译安装:make && make install
3.安装libx264库(如已安装跳过)
- 下载源码包 git clone https://code.videolan.org/videolan/x264.git
- 进入目录:cd x264
- 配置:
./configure --prefix=目录 --includedir=/usr/local/include --libdir=/usr/local/lib --enable-shared
- 编译:make
- 安装:make install
4.安装ffmperg
- 下载资源:Index of /ffmpeg/release-source
- 解压资源:tar -xvf ffmpeg-4.1.tar.xz
- 进入目录:cd ffmpeg-4.1
- 配置:
./configure --prefix=/usr/softinstall/ffmpeg --enable-gpl --enable-shared --enable-libx264
- 编译:make
- 安装:make install
- 配置环境变量:
vim /etc/profile
export FFMPEG_PATH=/usr/local/ffmpeg
export CLASSPATH=$FFMPEG_PATH/lib:$CLASSPATH
PATH=$FFMPEG_PATH/bin:$PATH
source /etc/profile
- 测试:ffmpeg -version
- 修改ld.so.conf
vim /etc/ld.so.conf
修改文件
#ffmpeg
/usr/local/ffmpeg/lib
#x264
/usr/local/lib
执行命令使修改生效
sudo ldconfig
5.转码流
ffmpeg -i '码流地址' -profile:v baseline -level 3.0 -s 640x360 -start_number 0 -hls_time 10 -hls_list_size 0 -f hls /home/hls/test/index.m3u8
6.nginx配置
location /hls {
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /home/;
add_header Cache-Control no-cache;
add_header Access-Control-Allow-Origin *;
}