1.安装准备软件
yum install -y yasm
2.源码编译安装 x264
cd /var/www/setupmkdir x264cd x264wget https://codeload.github.com/qupai/x264/zip/mastertar -zxvf x264-mastercd x264-master#查看帮助信息./configure --help#我们需要的是x264以.so or .a的形式来支援ffmpeg,所以一般就关注shared和static关键词就可以了, --disable-cli一定要填,不然make出错./configure --prefix=/usr/local/x264 --enable-shared --enable-static --disable-cli --enable-strip --enable-yasm makemake install
3.源码编译安装 FFMPEG
在FFmpeg官网获取源码 http://ffmpeg.org/download.html ,当前版本为 ffmpeg-3.4.2.tar.bz2 ,配置完成后编译并安装
cd /var/www/setupmkdir ffmpegcd ffmpegwget https://ffmpeg.org/releases/ffmpeg-4.1.tar.bz2tar -jxvf ffmpeg-4.1.tar.bz2cd ffmpeg-4.1./configure --prefix=/usr/local/ffmpeg --enable-shared --enable-yasm --enable-libx264 --enable-gpl --enable-pthreads --extra-cflags=-I/usr/local/x264/include --extra-ldflags=-L/usr/local/x264/lib --disable-x86asmmakemake install
如果遇到错误,把相关lib目录添加到lib
find / -name libavdevice.so.58#find / -name libx264.so.*vim /etc/ld.so.conf #将上述目录添加到最后一行并保存退出;/sbin/ldconfig#执行 ldconfig -v 命令,更新 ld.so.cache,使修改立即生效:ldconfig -v
4、创建软连接
#相当于 windows 中的创建快捷方式:ln -s /usr/local/ffmpeg/bin/ffmpeg /usr/local/bin/ln -s /usr/local/ffmpeg/bin/ffprobe /usr/local/bin/ln -s /usr/local/ffmpeg/bin/ffserver /usr/local/bin/
5、头文件拷贝
#路径 /usr/local/ffmpeg/include/ 包含的文件信息如下:cd /usr/local/ffmpeg/include/ls#/usr/local/ffmpeg/include 目录下创建 ffmpeg 目录:mkdir ffmpeg#将 /usr/local/ffmpeg/include 路径下所有目录复制到 ffmpeg 目录中:复制代码cp -r libswscale/ /usr/local/ffmpeg/include/ffmpeg/cp -r libswresample/ /usr/local/ffmpeg/include/ffmpeg/cp -r libpostproc/ /usr/local/ffmpeg/include/ffmpeg/cp -r libavutil/ /usr/local/ffmpeg/include/ffmpeg/cp -r libavformat/ /usr/local/ffmpeg/include/ffmpeg/cp -r libavfilter/ /usr/local/ffmpeg/include/ffmpeg/cp -r libavcodec/ /usr/local/ffmpeg/include/ffmpeg/cp -r libavdevice/ /usr/local/ffmpeg/include/ffmpeg/#将 /usr/local/ffmpeg/include 路径下 ffmpeg/ 目录复制到 /usr/include/:cp -r ffmpeg/ /usr/include/
6.PKG_CONFIG_PATH 变量设置
ffmpeg 安装程序会在 /usr/local/ffmpeg/lib/pkgconfig 目录下提供 libavcodec.pc libswscale.pc 等5个.pc文件,分别对应安装的五个库文件。必须要让 pkg-config 能找到 ffmpeg 的 *.pc 文件,通过 PKG_CONFIG_PATH 来设置 pkg-config 来更新。
cd /usr/local/ffmpeg/lib/pkgconfig/vim /etc/profile
#添加如下配置:export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig:/usr/local/ffmpeg/lib/pkgconfigexport FFMPEG_HOME=/usr/local/ffmpegexport PATH=$PATH:$FFMPEG_HOME
#使配置立即生效:source /etc/profile
7.测试推流
ffmpeg -versionffmpeg -f v4l2 -r 25 -video_size vga -pix_fmt yuv420p -i /dev/video0 -b:v 300k -c:v h264_omx -f flv rtmp://10.8.0.188/live/01ffmpeg -f video4linux2 -qscale 10 -r 12 -s 640x480 -i /dev/video0 -f alsa -i hw:1 -ab 16 -ar 22050 -ac 1 -f mp3 -f flv rtmp://127.0.0.1/rtmpsvr/rtmp1ffmpeg -f video4linux2 -s 640x480 -i /dev/video0 -f flv rtmp://127.0.0.1:1935/live/liveffmpeg -r 30 -i /dev/video0 -vcodec h264 -max_delay 100 -f flv -g 5 -b 700000 rtmp://10.8.0.188/rtmpsvr/rtmp1ffmpeg -f v4l2 -framerate 10 -i /dev/video0 -q 10 -f flv rtmp://127.0.0.1/live/weiffmpeg -f v4l2 -framerate 10 -i /dev/video0 -q 10 -f flv rtmp://127.0.0.1/hls/cctvffmpeg /dev/video0 ffmpeg /dev/video0 -f flv rtmp://127.0.0.1/live/live