安装先编译安装 libx264:

cd ~/git
git clone https://code.videolan.org/videolan/x264.git
cd ~/git/x264
./configure --prefix=$(pwd)/build --disable-asm --disable-cli --disable-shared --enable-static
make -j10
make install

然后安装libx265:

cd ~/git
git clone https://bitbucket.org/multicoreware/x265_git.git
cd ~/git/x265_git/build/linux
cmake -DCMAKE_INSTALL_PREFIX=$(pwd)/build -DENABLE_SHARED=OFF ../../source
make -j10
make install

安装FFmpeg,制定版本 5.1:

cd ~/git
git clone https://github.com/FFmpeg/FFmpeg.git
cd ~/git/FFmpeg && git checkout n5.1.2

打补丁,使FFmpeg可以 HEVC over RTMP/FLV:

cd ~/git
git clone -b 5.1 https://github.com/runner365/ffmpeg_rtmp_h265.git
cp ~/git/ffmpeg_rtmp_h265/flv.h ~/git/FFmpeg/libavformat/
cp ~/git/ffmpeg_rtmp_h265/flv*.c ~/git/FFmpeg/libavformat/

编译安装 ffmpeg with libx265:

cd ~/git/FFmpeg
env PKG_CONFIG_PATH=~/git/x264/build/lib/pkgconfig:~/git/x265_git/build/linux/build/lib/pkgconfig \
./configure \
  --prefix=$(pwd)/build \
  --enable-gpl --enable-nonfree --enable-pthreads --extra-libs=-lpthread \
  --disable-asm --disable-x86asm --disable-inline-asm \
  --enable-decoder=aac --enable-decoder=aac_fixed --enable-decoder=aac_latm --enable-encoder=aac \
  --enable-libx264 --enable-libx265 \
  --pkg-config-flags='--static'
make -j10

如果想要编辑带ffplay的版本,请先安装SDL,具体的看评论
编译代码:

cd ~/git/FFmpeg
env PKG_CONFIG_PATH=~/git/x264/build/lib/pkgconfig:~/git/x265_git/build/linux/build/lib/pkgconfig \
./configure \
  --prefix=$(pwd)/build \
  --enable-gpl --enable-nonfree --enable-pthreads --extra-libs=-lpthread \
  --disable-asm --disable-x86asm --disable-inline-asm \
  --enable-decoder=aac --enable-decoder=aac_fixed --enable-decoder=aac_latm --enable-encoder=aac \
  --enable-libx264 --enable-libx265 \
  --pkg-config-flags='--static' \
  --enable-sdl \
  --enable-ffplay

推流测试 HEVC over RTMP to SRS:

./ffmpeg -stream_loop -1 -re -i ~/srs/doc/source.flv -acodec copy -vcodec libx265 \
  -f flv rtmp://localhost/live/livestream

拉流播放测试Play HEVC over RTMP by ffplay:

./ffplay rtmp://localhost/live/livestream

可以用了。测试环境Ubuntu2204,Debian11.

最后修改:2023 年 07 月 07 日
如果觉得我的文章对你有用,请随意赞赏