ubuntu下编译ffmpeg libx264 libx265
使用的是嵌入式设备nanopi neo3,搭载的系统UbuntuCore 18.04系统固件(5.4.12 内核),打算使用usb免驱动摄像头来做推流端。
基础工作:
apt-get update
apt-get install build-essential make pkg-config cmake cmake-curses-gui
安装包:FFmpeg-master multicoreware-x265-e41a9bf2bac4 x264-master,分别为FFmpeg、h265、h264最新版。
链接:
https://github.com/FFmpeg/FFmpeg
http://ftp.videolan.org/pub/videolan/x265/
https://code.videolan.org/videolan/x264
开始编译(编译需要一定时间,步骤①和②可以在两个putty同时进行):
①编译libx264。
./configure --enable-static --enable-shared
make -j4
make install
②编译libx265。
cd multicoreware-x265-e41a9bf2bac4/build/linux/
sh make-Makefiles.bash
(这一步需要注意,如果出现"which may bind externally can not be used when making a shared object; recompile with -fPIC",把ENABLE_PIC改为ON)
make -j4
make install
③编译ffmpeg。
./configure --prefix="$PWD/install" --enable-libx264 --enable-libx265 --enable-gpl --enable-shared --disable-optimizations --disable-stripping
make -j4
make install
将lib库拷入/usr/lib/或者/usr/lib64
测试bin目录下的ffmpeg二进制可执行文件
最后可以用推流命令测试,摄像头驱动还没调好,暂时用本地文件推。播放器用vlc播放。
推流命令:./ffmpeg -re -stream_loop -1 -i 1.mp4 -vcodec h264 -acodec aac -f rtsp -rtsp_transport tcp rtsp://192.168.1.104:554/live/test2
流媒体服务器启动。
VLC播放。
最后,环境就算搭建完成了,在当前的环境下利用ffmpeg里的模块进行rtsp推流/rtmp推流/mp4合成。计划为:用ffmpeg 的device模块取摄像头数据,然后利用filter模块加上水印,scale模块做原始图像格式转换(如nv12转yuv420p),最后在使用codec模块进行软/硬编码,再通过网络数据流推出。