Rate This Document
Findability
Accuracy
Completeness
Readability

Compiling and Installing FFmpeg

Obtain the FFmpeg source package, integrate the Kunpeng HW265Enc patch package to it, add the relevant search paths, and verify the HW265Enc functionality.

  1. Obtain the ffmpeg-7.0.1_plugin_for_hw265_enc.patch and ffmpeg-7.0.1.tar.gz packages based on Software Environment.
  2. Copy the patch package and source package to the ~/dependency/ directory and decompress ffmpeg-7.0.1.tar.gz.
    1
    2
    cd ~/dependency/
    tar -zxvf ffmpeg-7.0.1.tar.gz
    
  3. Go to the ffmpeg-7.0.1 directory and copy the Kunpeng HW265Enc patch package to this directory.
    1
    2
    cd ffmpeg-7.0.1
    cp ../ffmpeg-7.0.1_plugin_for_hw265_enc.patch .
    
  4. Integrate the HW265Enc patch package into the source package.
    1
    patch -p1 < ffmpeg-7.0.1_plugin_for_hw265_enc.patch
    
  5. Copy the dynamic link library libhw265.so of HW265Enc to the /usr/local/lib directory.
    1
    cp ~/dependency/lib/libhw265.so /usr/local/lib
    
  6. Copy the header file hwe_api.h of HW265Enc to the /usr/local/include directory.
    1
    cp ~/dependency/include/hwe_api.h /usr/local/include
    
  7. Generate the hw265.pc file.
    1. Create an hw265.pc file.
      1
      sudo vi /usr/local/lib/pkgconfig/hw265.pc
      
    2. Press i to enter the insert mode and add the following content to the file:
      Name: hw265enc
      Description: Huawei H.265 video encoder HW265 1.1.0
      Version: 1.1.0
      Libs: -L/usr/local/lib -lhw265
      Libs.private: -lm -lpthread
      Cflags: -I/usr/local/include
    3. Press Esc, type :wq!, and press Enter to save the file and exit.
  8. Add the search path for the installed library.
    1
    export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
    
  9. Perform the compilation and installation.
    1
    2
    3
    ./configure --enable-shared --enable-libhw265 --enable-gpl
    make
    sudo make install
    
  10. Add the dynamic library search path.
    1
    export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
    
  11. Add the search path for executable files.
    1
    export PATH=/usr/local/bin:$PATH
    
  12. Check whether the installation is successful.
    1
    ffmpeg -h encoder=libhw265
    

    Information similar to the following is displayed:

     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
    34
    35
    36
    37
    38
    39
    40
    41
    42
    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) 
      -cfps              <int>        E..V....... ConstFramerate. 0:off 1:on, default 1 (from -1 to 1) (default -1)
      -enablefixedIdrPeriod <int>     E..V....... Fixed intervals always contain I-frames. 0:off 1:on, default 0 (from -1 to 1) (default -1)
      -bitratePar        <float>      E..V....... Peak-to-Average Bitrate Ratio, if not in [1, 20], bitratePar will be default, default is 4 (from -1 to 20) (default -nan)
      -bitrateParCtrlStrength <float> E..V....... Peak Control Strength, [0,3], default 0 (from -1 to 3) (default -nan)
      -enableResetBitrate <int>       E..V....... enable resetBitrate. 0:off 1:on, default 0 (from -1 to 1) (default -1)
      -MbTree            <int>        E..V....... enable MbTree. 0:off 1:on, default 1 (from -1 to 1) (default -1)
      -delayTime         <int>        E..V....... Time-Domain Analysis Wait Time. [0,4000], default 0 (from -1 to 4000) (default -1)
      -enableDelayTimeControl <int>   E..V....... Enable Time-Domain Analysis Wait Time Control. 0:off 1:on, default 0 (from -1 to 1) (default -1)
      -adap_B            <int>        E..V....... Adaptive insert B frames. [0,3], default 1 (from -1 to 3) (default -1)