[树莓派]aarch64 系统 编译最新的ffmpeg 并支持硬解h264

member
English

树莓派aarch64

不需要硬解或输出rtsp的, 直接下载编译好的amr64即可 https://johnvansickle.com/ffm...
aarch64硬解采用的是h264_v4l2m2m, 这个输出rtsp的会因为编码里面的header导致黑屏
下面编译的已经修复了这个bug

安装依赖

常规依赖

apt -y install \
    autoconf \
    automake \
    build-essential \
    cmake \
    doxygen \
    git \
    meson \
    nasm \
    pkg-config \
    python3-dev \
    python3-pip \
    texinfo \
    wget \
    yasm \
    zlib1g-dev 

压缩/SSL/音频/视频/图片库

apt -y install \
    graphviz \
    imagemagick \
    libaom-dev \
    libnuma-dev \
    liblzma-dev \
    libssl-dev \
    libdrm-dev \
    libdav1d-dev \
    libfdk-aac-dev \
    libasound2-dev \
    libass-dev \
    libavcodec-dev \
    libavdevice-dev \
    libavfilter-dev \
    libavformat-dev \
    libavutil-dev \
    libfreetype6-dev \
    libgmp-dev \
    libgme-dev \
    libmp3lame-dev \
    libopencore-amrnb-dev \
    libopencore-amrwb-dev \
    libopus-dev \
    libopenjp2-7-dev \
    librtmp-dev \
    libsdl2-dev \
    libsdl2-image-dev \
    libsdl2-mixer-dev \
    libsdl2-net-dev \
    libsdl2-ttf-dev \
    libspeex-dev \
    libsrt-dev \
    libsnappy-dev \
    libsoxr-dev \
    libssh-dev \
    libssl-dev \
    libtool \
    libtheora-dev \
    libv4l-dev \
    libva-dev \
    libvdpau-dev \
    libvo-amrwbenc-dev \
    libvorbis-dev \
    libwebp-dev \
    libx264-dev \
    libx265-dev \
    libxcb-shape0-dev \
    libxcb-shm0-dev \
    libxcb-xfixes0-dev \
    libxcb1-dev \
    libxvidcore-dev \
    libxml2-dev \
    libvidstab-dev \
    lzma-dev
    
libdav1d-dev 在ubuntu arm64中没有 可以按照下面的方式编译AV1

苹果用的HEVC

git clone --depth 1 https://github.com/ultravideo/kvazaar.git ~/ffmpeg-libraries/kvazaar \
  && cd ~/ffmpeg-libraries/kvazaar \
  && ./autogen.sh \
  && ./configure --prefix=/usr/ \
  && make -j$(nproc) \
  && sudo make install

VP8 and VP9

git clone --depth 1 https://github.com/webmproject/libvpx.git ~/ffmpeg-libraries/libvpx \
  && cd ~/ffmpeg-libraries/libvpx \
  && ./configure --prefix=/usr/ --disable-examples --disable-tools --disable-unit_tests --disable-docs \
  && make -j$(nproc) \
  && sudo make install

zimg

git clone --depth 1 https://github.com/sekrit-twc/zimg.git ~/ffmpeg-libraries/zimg \
  && cd ~/ffmpeg-libraries/zimg \
  && sh autogen.sh \
  && ./configure --prefix=/usr/ \
  && make -j$(nproc) \
  && sudo make install

AP1

不需要安装
aarch系统中有libaom-dev

git clone --depth 1 https://aomedia.googlesource.com/aom ~/ffmpeg-libraries/aom \
  && mkdir ~/ffmpeg-libraries/aom/aom_build \
  && cd ~/ffmpeg-libraries/aom/aom_build \
  && cmake -G "Unix Makefiles" AOM_SRC -DCMAKE_INSTALL_PREFIX=/usr/ -DENABLE_NASM=on -DPYTHON_EXECUTABLE="$(which python3)" -DCMAKE_C_FLAGS="-mfpu=vfp -mfloat-abi=hard" .. \
  && sed -i 's/ENABLE_NEON:BOOL=ON/ENABLE_NEON:BOOL=OFF/' CMakeCache.txt \
  && make -j$(nproc) \
  && sudo make install

AAC

不需要安装
aarch64系统中有libfdk-acc-dev

git clone --depth 1 https://github.com/mstorsjo/fdk-aac.git ~/ffmpeg-libraries/fdk-aac \
  && cd ~/ffmpeg-libraries/fdk-aac \
  && autoreconf -fiv \
  && ./configure --prefix=/usr/ \
  && make -j$(nproc) \
  && sudo make install

AV1

debian aarch64系统中有libdav1d-dev
ubuntu aarch64系统没有

git clone --depth 1 https://code.videolan.org/videolan/dav1d.git ~/ffmpeg-libraries/dav1d \
  && mkdir ~/ffmpeg-libraries/dav1d/build \
  && cd ~/ffmpeg-libraries/dav1d/build \
  && meson -Dprefix=/usr .. \
  && ninja \
  && sudo ninja install

编译ffmpeg

下载源代码

git clone --depth 1 https://github.com/FFmpeg/FFmpeg.git ~/FFmpeg \
  && cd ~/FFmpeg

修复 v4l2读取摄像头时多header头导致无法输出的bug

wget https://dl.dropboxusercontent.com/s/eja8vz5jh1felnp/patch.diff
git apply patch.diff

修改ffmpeg的配置文件

vim ./configure

这个librtmp即使安装了也无法检测到,注释这行,下文使用-lrtmp开启即可

# enabled librtmp           && require_pkg_config librtmp librtmp librtmp/rtmp.h RTMP_Socket
./configure \
    --prefix=/usr/ \
    --extra-cflags="-I/usr/local/include" \
    --extra-ldflags="-L/usr/local/lib" \
    --extra-libs="-lpthread -lm -latomic -lrtmp -lx265" \
    --arch=aarch64 \
    --disable-shared \
    --enable-neon \
    --enable-hwaccel=h264_vaapi \
    --enable-hwaccel=h264_vaapi \
    --enable-hwaccel=h264_dxva2 \
    --enable-hwaccel=mpeg4_vaapi \
    --enable-hwaccels \
    --enable-static \
    --disable-debug \
    --enable-gmp \
    --enable-gpl \
    --enable-gray \
    --enable-fontconfig \
    --enable-libaom \
    --enable-libass \
    --enable-libdav1d \
    --enable-libdrm \
    --enable-libgme \
    --enable-libfdk-aac \
    --enable-libfreetype \
    --enable-libkvazaar \
    --enable-libmp3lame \
    --enable-libopencore-amrnb \
    --enable-libopencore-amrwb \
    --enable-libopus \
    --enable-libopenjpeg \
    --enable-librtmp \
    --enable-libsnappy \
    --enable-libsoxr \
    --enable-libspeex \
    --enable-libssh \
    --enable-libsrt \
    --enable-libxvid \
    --enable-libtheora \
    --enable-libvidstab \
    --enable-libvorbis \
    --enable-libvpx \
    --enable-libzimg \
    --enable-libwebp \
    --enable-libx264 \
    --enable-libx265 \
    --enable-libxml2 \
    --enable-nonfree \
    --enable-omx \
    --enable-omx-rpi \
    --enable-version3 \
    --target-os=linux \
    --enable-pthreads \
    --enable-openssl \
    --enable-hardcoded-tables

注意: aarch64 不支持

--enable-mmal

如果出现确实omx(OpenMAX IL)不存在的报错
omx是树莓派的一个硬件解码
这一般是在非树莓派环境下编译出现的结果,

# 安装aarch64的GPU驱动
git clone https://github.com/raspberrypi/userland ~/userland
cd ~/userland
./buildme --aarch64

编译

make -j$(nproc)
make install

视频流

rtsp server

使用的是EasyDarwin,下载release后一键运行在windows上

树莓派能力有限, 如果使用软解, CPU占用很高, 不能即采集摄像头, 又做rtsp server
https://github.com/EasyDarwin/EasyDarwin

推流

软解200ms延时, CPU占用很高

ffmpeg  \
-f video4linux2 \
-framerate 24 \
-s 800x600 \
-i /dev/video0 \
-vcodec h264 \
-preset ultrafast \
-tune zerolatency  \
-g 6 \
-threads 4 \
-rtsp_transport tcp -f rtsp rtsp://rtsp.server/test

关键参数解释

-g 6 关键帧6
-tune zerolatency 0延迟
-preset veryfast x264的fast/faster/verfast/superfast/ultrafast

硬解 200ms延时

ffmpeg \
-f video4linux2  \
-framerate 24 \
-s 800x600 \
-i /dev/video0 \
-pix_fmt yuv420p \
-codec:v:0 h264_v4l2m2m \
-b:v 9990684 -maxrate 9990684 -bufsize 19981368 \
-preset ultrafast \
-tune zerolatency \
-g 6 -keyint_min 6 \
-force_key_frames:0 "expr:gte(t,0+n_forced*2)" \
-vf "scale=trunc(min(max(iw\,ih*dar)\,1920)/64)*64:trunc(ow/dar/2)*2" \
-threads 4 \
-vsync -1 \
-r 25 \
-rtsp_transport tcp -f rtsp rtsp://rtsp.server/test
阅读 1.3k

擅长计算机开关机、Windows系统的安装。

6.1k 声望
150 粉丝
0 条评论
你知道吗?

擅长计算机开关机、Windows系统的安装。

6.1k 声望
150 粉丝
宣传栏