---
title: 编译和安装FFmpeg
description: "获取FFmpeg源码，合入鲲鹏HW265视频编码器Patch包，添加相关搜索路径后进行HW265编码器功能验证。"
url: https://www.hikunpeng.com/document/detail/zh/boostmedia/hw265/kunpengcps_hw265enc_06_0012.html
sourcePath: /source/zh/boostmedia/hw265/kunpengcps_hw265enc_06_0012.html
indexId: 68b5d18a96cf99c4babe202d4d50dc85d6d423ed3429c900fcad611b14920bdd60
---
# 编译和安装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文件。

  a. 创建pkgconfig目录，并创建hw265.pc文件。
    1 2 sudo mkdir /usr/local/lib/pkgconfig sudo vi /usr/local/lib/pkgconfig/hw265.pc

  b. 按“i”进入编辑模式，在hw265.pc文件中写入以下内容。

```
Name: hw265enc
Description: Huawei H.265 video encoder HW265 1.2.0
Version: 1.2.0
Libs: -L/usr/local/lib -lhw265
Libs.private: -lm -lpthread
Cflags: -I/usr/local/include
```


  c. 按“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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 ffmpeg version 7.0.1 Copyright (c) 2000-2024 the FFmpeg developers built with gcc 12 (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 yuv420p10le yuv422p10le yuv444p10le gbrp10le gray gray10le 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 1 (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 1) (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....... support main and main 10 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 12 (from -1 to INT_MAX) (default -1) -bframe_nums <int> E..V....... Max consecutive B-frames, [0,7], default 0 (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) -hdrMode <int> E..V....... hdrMode. 0:off, 1:hdr10, 2:hdr vivid.[0, 2], default 0 (from 0 to 2) (default 0) -repeatHeaders <int> E..V....... enable repeatHeaders. 0:on, 1:off.[0, 2], default 0 (from 0 to 1) (default 0) -max-cll <int> E..V....... Max Content Light Level (nits), [0, 65535]. (from 0 to 65535) (default 1000) -max-fall <int> E..V....... Max Picture Average Light Level (nits), [0, 65535]. (from 0 to 65535) (default 300) -primaries-x0 <int> E..V....... Display Primaries X0 Chromaticity Coordinate, [0, 65535]. (from 0 to 65535) (default 8500) -primaries-y0 <int> E..V....... Display Primaries Y0 Chromaticity Coordinate, [0, 65535]. (from 0 to 65535) (default 39850) -primaries-x1 <int> E..V....... Display Primaries X1 Chromaticity Coordinate, [0, 65535]. (from 0 to 65535) (default 6550) -primaries-y1 <int> E..V....... Display Primaries Y1 Chromaticity Coordinate, [0, 65535]. (from 0 to 65535) (default 2300) -primaries-x2 <int> E..V....... Display Primaries X2 Chromaticity Coordinate, [0, 65535]. (from 0 to 65535) (default 35400) -primaries-y2 <int> E..V....... Display Primaries Y2 Chromaticity Coordinate, [0, 65535]. (from 0 to 65535) (default 14600) -white-x <int> E..V....... White Point X Chromaticity Coordinate, [0, 65535]. (from 0 to 65535) (default 15635) -white-y <int> E..V....... White Point Y Chromaticity Coordinate, [0, 65535]. (from 0 to 65535) (default 16450) -max-luminance <int64> E..V....... Max Display Mastering Luminance (nits), [0, 4294967295]. (from 0 to UINT32_MAX) (default 10000000) -min-luminance <int64> E..V....... Min Display Mastering Luminance (nits), [0, 4294967295]. (from 0 to UINT32_MAX) (default 1) -atc-sei <int> E..V....... Preferred transfer characteristics. [0, 255] -fullrange <int> E..V....... Set full range flag. [0, 1] (from -1 to 1) (default -1) -color_p <int> E..V....... Set color primaries. [0, 12] (from -1 to 12) (default -1) -transfer <int> E..V....... Set transfer characteristics. [0, 18] (from -1 to 18) (default -1) -col_matrix <int> E..V....... Set color matrix coefficients. [0, 14] (from -1 to 14) (default -1)
