鲲鹏社区首页
中文
注册
我要评分
文档获取效率
文档正确性
内容完整性
文档易理解
在线提单
论坛求助

编译和安装FFmpeg

获取FFmpeg源码,合入鲲鹏HW265视频编码器Patch包,添加相关搜索路径后进行HW265编码器功能验证。

  1. 请参见软件环境获取鲲鹏HW265视频编码器Patch包ffmpeg-7.0.1_plugin_for_hw265_enc.patch和FFmpeg源码包ffmpeg-7.0.1.tar.gz。
  2. 将Patch包和源码包拷贝至“~/dependency/”目录,并解压ffmpeg-7.0.1.tar.gz源码包。
    1
    2
    cd ~/dependency/
    tar -zxvf ffmpeg-7.0.1.tar.gz
    
  3. 进入“ffmpeg-7.0.1”目录,并将鲲鹏HW265视频编码器Patch包拷贝至当前目录。
    1
    2
    cd ffmpeg-7.0.1
    cp ../ffmpeg-7.0.1_plugin_for_hw265_enc.patch .
    
  4. 合入鲲鹏HW265视频编码器Patch包。
    1
    patch -p1 < ffmpeg-7.0.1_plugin_for_hw265_enc.patch
    
  5. 将HW265视频编码器的动态链接库libhw265.so拷贝到“/usr/local/lib”目录。
    1
    cp ~/dependency/lib/libhw265.so /usr/local/lib
    
  6. 将HW265视频编码器的头文件hwe_api.h拷贝到“/usr/local/include”目录。
    1
    cp ~/dependency/include/hwe_api.h /usr/local/include
    
  7. 生成hw265.pc文件。
    1
    sudo vi /usr/local/lib/pkgconfig/hw265.pc
    
    1. 在hw265.pc文件中写入以下内容。
      Name: hw265enc
      Description: Huawei H.265 video encoder HW265 1.0.0
      Version: 1.0.0
      Libs: -L/usr/local/lib -lhw265
      Libs.private: -lm -lpthread
      Cflags: -I/usr/local/include
    2. “Esc”键,输入:wq!,按“Enter”保存并退出编辑。
  8. 添加已安装库搜索路径。
    1
    export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
    
  9. 编译安装。
    1
    2
    3
    ./configure --enable-shared --enable-libhw265 --enable-gpl
    make
    sudo make install
    
  10. 增加动态库搜索路径。
    1
    export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
    
  11. 添加可执行文件搜索路径。
    1
    export PATH=/usr/local/bin:$PATH
    
  12. 验证是否已成功安装。
    1
    ffmpeg -h encoder=libhw265
    

    回显内容如下:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    ffmpeg version 7.0 Copyright (c) 2000-2024 the FFmpeg developers
      built with gcc 10.3.1 (GCC)
      configuration: --enable-shared --enable-libhw265 --enable-gpl
      libavutil      59.  8.100 / 59.  8.100
      libavcodec     61.  3.100 / 61.  3.100
      libavformat    61.  1.100 / 61.  1.100
      libavdevice    61.  1.100 / 61.  1.100
      libavfilter    10.  1.100 / 10.  1.100
      libswscale      8.  1.100 /  8.  1.100
      libswresample   5.  1.100 /  5.  1.100
      libpostproc    58.  1.100 / 58.  1.100
    Encoder libhw265 [libhw265 H.265 / HEVC]:
        General capabilities: dr1 delay threads
        Threading capabilities: other
        Supported pixel formats: yuv420p yuvj420p yuv422p yuvj422p yuv444p yuvj444p gbrp gray
    libhw265 AVOptions:
      -channel           <int>        E..V....... Channel ID for encoder[0, 65535], default 0 (from -1 to INT_MAX) (default -1)
      -log_level         <int>        E..V....... Log level. 0:off 1:error 2:warning 3:info 4:debug, default 1 (from -1 to 4) (default -1)
      -delay             <int>        E..V....... Number of frames for encoder analysis[bframes, 150], default 25 (from -1 to INT_MAX) (default -1)
      -adap_I            <int>        E..V....... Adaptive insert I frames base on scenecut. 0:off 1:on, default 0 (from -1 to 1) (default -1)
      -analysis_threads  <int>        E..V....... Number of frames for concurrent analysis. [1, 48], default 5 (from -1 to 48) (default -1)
      -bframe_ref        <int>        E..V....... B frames used as reference frame. 0:off 1:on, default 1 (from -1 to 255) (default -1)
      -frame_threads     <int>        E..V....... Number of concurrently encoded frame threads[1, 38], default 12 (from -1 to 38) (default -1)
      -wpp_threads       <int>        E..V....... Number of concurrently encoded rows threads[1, 20], default 8 (from -1 to 20) (default -1)
      -profile           <int>        E..V....... Only support main profile. default 0 (from -1 to INT_MAX) (default -1)
      -qualityset        <int>        E..V....... Quality level of the encoder. {2, 3, 5, 6} from slow to fast, default 3 (from -1 to 6) (default -1)
      -keyint            <int>        E..V....... Distance between I-frames, not less than 1, default 150 (from -1 to INT_MAX) (default -1)
      -bframe_nums       <int>        E..V....... Max consecutive B-frames, [0,7], default 7 (from -1 to 7) (default -1)
      -rc                <int>        E..V....... Rate control mode, if not in {0, 1, 2}, rc_mode will be default, default is 0 (from -1 to 2) (default -1)
      -qp                <int>        E..V....... The initial qp used by encoder[1, 51], default 18 (from -1 to 51) (default -1)
      -abr_bitrate       <int>        E..V....... average bitrate (kbps), if not in [40kbps, 300000kbps], bitrate will be default, default is 2000 (from -1 to INT_MAX) (default -1)
      -crf               <int>        E..V....... crf level, if not in [0, 51], crf will be default, default is 23 (from -1 to 51) (default -1)
      -fps_num           <int>        E..V....... playback framerate of the output video, if not in (0, 120], fps will be default, default is 25 (from -1 to 120) (default -1)