# FFmpeg中的硬件加速编码器

**URL:** <https://meta.appinn.net/t/topic/18299>\
**Category:** 网络黄页\
**Tags:** ffmpeg\
**Created:** [2020 年8 月 14 日 14:30 UTC](https://meta.appinn.net/t/topic/18299 "2020-08-14T14:30:02Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

作者： ![feeshy](https://meta-edge.appinn.com/user_avatar/meta.appinn.net/feeshy/32/55260_2.png) [@feeshy](https://meta.appinn.net/u/feeshy)\
发布日期： [2020 年8 月 14 日 14:30 UTC](https://meta.appinn.net/t/topic/18299/1 "2020-08-14T14:30:02Z")

</div>

注意：本帖讨论的是 **硬编** ， **不是** 硬解

使用下面的命令可以列出 #ffmpeg 中所有的编码器

```auto
ffmpeg -encoders

```

这个帖子整理一下ffmpeg中支持GPU硬件加速的编码器。

如果你的GPU支持硬件加速，则可以使用非默认的编码器来提高转码速度。就我本人在笔记本平台Intel低压U的使用经验，ffmpeg在开启核显硬件加速后可以降低30%的CPU占用，并且节约70%~80%的转码时间。

# 三大桌面GPU厂商以及苹果的硬件编、解码器进化历程表

在下面的三组表格中，可以查询到自己GPU硬件支持的编码格式：

- [Intel](https://en.wikipedia.org/wiki/Intel_Quick_Sync_Video#Hardware_decoding_and_encoding)
- [AMD](https://en.wikipedia.org/wiki/Unified_Video_Decoder#Format_support)
- [Nvidia](https://developer.nvidia.com/video-encode-decode-gpu-support-matrix)
- Apple Silicon
  - M1: H.264, HEVC
  - M1 Pro/M1 Max: H.264, HEVC, ProRes

看起来Intel的核显虽然3D性能一直拉跨，硬件编码器却一直给得非常厚道，某些特殊编码的视频渲染似乎是得独显核显全都要才能最大化效率

# Windows

（版本：ffmpeg 5.0）

| | **默认编码器** | **AMD硬件加速** | **Intel硬件加速** | **Nvidia硬件加速** |
| **H.264/AVC** | libx264 | h264\_amf | h264\_qsv | h264\_nvenc  
nvenc  
nvenc\_h264 |
| **H.265/HEVC** | libx265 | hevc\_amf | hevc\_qsv | hevc\_nvenc  
nvenc\_hevc |
| **MJPEG** | mjpeg | | mjpeg\_qsv | |
| **MPEG-2** | mpeg2video | | mpeg2\_qsv | |
| **VP8** | libvpx | | | |
| **VP9** | libvpx-vp9 | | vp9\_qsv | |

对比本表格与上面的硬件支持表格，可以发现Intel比较新的GPU硬件上支持VP8编码，但ffmpeg for Windows软件上并没有做适配

# macOS (Intel & Apple Silicon)

（版本：ffmpeg 5.0）

| | **默认编码器** | **Intel硬件加速** | **Apple Silicon硬件加速** |
| **H.264/AVC** | libx264  
libopenh264 | h264\_videotoolbox | h264\_videotoolbox |
| **H.265/HEVC** | libx265 | hevc\_videotoolbox | hevc\_videotoolbox |
| **VP8** | libvpx | | |
| **VP9** | libvpx-vp9 | ? | ? |
| **ProRes** | prores  
prores\_aw  
prores\_ks | | prores\_videotoolbox |

[ffmpeg5.0更新](https://9to5linux.com/ffmpeg-5-0-lorentz-released-with-new-encoders-decoders-muxers-and-more)说是新增了VP9和ProRes的硬件加速，不过我安装的1月17号的build只找到了ProRes

# Linux (x86)

（版本：ffmpeg 4.3）

| | **默认编码器** | **AMD硬件加速** | **Intel硬件加速** | **Nvidia硬件加速** |
| **H.264/AVC** | libx264 | h264\_vaapi  
h264\_omx | h264\_vaapi | h264\_nvenc  
nvenc  
nvenc\_h264 |
| **H.265/HEVC** | libx265 | ?hevc\_vaapi | hevc\_vaapi | hevc\_nvenc  
nvenc\_hevc |
| **MJPEG** | mjpeg | | mjpeg\_vaapi | |
| **MPEG-2** | mpeg2video | | mpeg2\_vaapi | |
| **VP8** | libvpx | | vp8\_vaapi | |
| **VP9** | libvpx-vp9 | | vp9\_vaapi | |

注：ffmpeg对于Intel GPU有完整的VAAPI支持，而对于AMD GPU的支持是不完整的：

> [正在确认你是不是机器人！](https://trac.ffmpeg.org/wiki/Hardware/VAAPI)
> 
> H.264 encode is working on GCN GPUs, but is still incomplete. No other codecs are supported by Mesa for encode yet.
> 
> Encoding and interlacing support in Mesa are incompatible because of the data layout in GPU memory. By default, frames are separated into fields and interlaced video is supported but encoding is not. Set the environment variable VAAPI\_DISABLE\_INTERLACE to 1 to be able to use the encoder (but without any interlaced video support.

不过考虑到ffmpeg的官方Wiki并不是实时更新，我也不确定最新的AMD GPU在最新的Linux驱动下是不是已经支持HEVC硬件加速编码了

# 树莓派

树莓派并不是一个设计来转码的设备，其GPU的硬件编码器部分只支持非4K分辨率的H.264视频

| | **默认编码器** | **树莓派硬件加速** |
| **H.264/AVC** | libx264 | h264\_omx |

> 最后由 @feeshy 在 2022-01-28T04:48:33Z 编辑

---

<div class="post-metadata">

作者： ![ico](https://meta-edge.appinn.com/letter_avatar_proxy/v4/letter/i/91b2a8/32.png) [@ico](https://meta.appinn.net/u/ico)\
发布日期： [2020 年8 月 14 日 15:48 UTC](https://meta.appinn.net/t/topic/18299/2 "2020-08-14T15:48:58Z")

</div>

Haswell看了沉默，Haswell看了流泪

---

<div class="post-metadata">

作者： ![haitao](https://meta-edge.appinn.com/letter_avatar_proxy/v4/letter/h/958977/32.png) [@haitao](https://meta.appinn.net/u/haitao)\
发布日期： [2020 年8 月 14 日 17:24 UTC](https://meta.appinn.net/t/topic/18299/3 "2020-08-14T17:24:38Z")

</div>

我的4590也是haswell。。。。怎么正好什么都不支持？？  
实际使用，好像也支持 h264\_qsv ？

---

<div class="post-metadata">

作者： ![feeshy](https://meta-edge.appinn.com/user_avatar/meta.appinn.net/feeshy/32/55260_2.png) [@feeshy](https://meta.appinn.net/u/feeshy)\
发布日期： [2020 年8 月 15 日 01:23 UTC](https://meta.appinn.net/t/topic/18299/4 "2020-08-15T01:23:35Z")

</div>

> [@haitao](#):
>
> 怎么正好什么都不支持

那一列是每个架构新添加的支持啊，从它自己那行往上的都支持

---

<div class="post-metadata">

作者： ![hgoldfish](https://meta-edge.appinn.com/user_avatar/meta.appinn.net/hgoldfish/32/5033_2.png) [@hgoldfish](https://meta.appinn.net/u/hgoldfish)\
发布日期： [2020 年8 月 15 日 14:54 UTC](https://meta.appinn.net/t/topic/18299/6 "2020-08-15T14:54:17Z")

</div>

赞赞赞。。

现在最常用的编码和解码格式是 h264/h265 两种，vp9 好处是开源免专利费，但用的人不多，只有 google 自己在做。

linux 的适配很麻烦，跟发行版可能有关。实际我在 openSUSE 上基本上都是软解码和软解码。

---

<div class="post-metadata">

作者： ![feeshy](https://meta-edge.appinn.com/user_avatar/meta.appinn.net/feeshy/32/55260_2.png) [@feeshy](https://meta.appinn.net/u/feeshy)\
发布日期： [2020 年8 月 16 日 01:39 UTC](https://meta.appinn.net/t/topic/18299/7 "2020-08-16T01:39:35Z")

</div>

其实我很好奇，Intel有jpeg硬件编码器，Photoshop导出时能不能用得上…

---

<div class="post-metadata">

作者： ![yuuka](https://meta-edge.appinn.com/letter_avatar_proxy/v4/letter/y/49beb7/32.png) [@yuuka](https://meta.appinn.net/u/yuuka)\
发布日期： [2020 年8 月 16 日 02:41 UTC](https://meta.appinn.net/t/topic/18299/8 "2020-08-16T02:41:08Z")

</div>

> [@hgoldfish](#):
>
> 在 openSUSE 上

能在这里碰到 openSUSE 用户有点神奇，不过好像在tg群组那边没看到过你？

---

<div class="post-metadata">

作者： ![hgoldfish](https://meta-edge.appinn.com/user_avatar/meta.appinn.net/hgoldfish/32/5033_2.png) [@hgoldfish](https://meta.appinn.net/u/hgoldfish)\
发布日期： [2020 年8 月 16 日 16:44 UTC](https://meta.appinn.net/t/topic/18299/9 "2020-08-16T16:44:17Z")

</div>

比较少用tg，不喜欢IM频繁打扰。我喜欢每天固定时间刷论坛。

---

<div class="post-metadata">

作者： ![weijarz](https://meta-edge.appinn.com/user_avatar/meta.appinn.net/weijarz/32/9966_2.png) [@weijarz](https://meta.appinn.net/u/weijarz)\
发布日期： [2020 年8 月 21 日 13:26 UTC](https://meta.appinn.net/t/topic/18299/10 "2020-08-21T13:26:24Z")

</div>

用软件版和硬件加速版在相同参数下出来的视频质量是一样的吗？

---

<div class="post-metadata">

作者： ![feeshy](https://meta-edge.appinn.com/user_avatar/meta.appinn.net/feeshy/32/55260_2.png) [@feeshy](https://meta.appinn.net/u/feeshy)\
发布日期： [2020 年8 月 21 日 13:52 UTC](https://meta.appinn.net/t/topic/18299/11 "2020-08-21T13:52:55Z")

</div>

有损压缩算法理论上就算是同样的画面用同一个编码器编码两次，结果都不会完全一样吧…反正我肉眼看不出来差别……

---

<div class="post-metadata">

作者： ![weijarz](https://meta-edge.appinn.com/user_avatar/meta.appinn.net/weijarz/32/9966_2.png) [@weijarz](https://meta.appinn.net/u/weijarz)\
发布日期： [2020 年8 月 22 日 03:35 UTC](https://meta.appinn.net/t/topic/18299/12 "2020-08-22T03:35:00Z")

</div>

这和有损无损无关，和算法有关。  
硬件压缩质量会差一点点。

---

<div class="post-metadata">

作者： ![feeshy](https://meta-edge.appinn.com/user_avatar/meta.appinn.net/feeshy/32/55260_2.png) [@feeshy](https://meta.appinn.net/u/feeshy)\
发布日期： [2022 年1 月 28 日 03:56 UTC](https://meta.appinn.net/t/topic/18299/13 "2022-01-28T03:56:05Z")

</div>

[ffmpeg5.0更新](https://9to5linux.com/ffmpeg-5-0-lorentz-released-with-new-encoders-decoders-muxers-and-more)说是新增了VP9和ProRes的硬件加速，不过我安装的1月17号的build只找到了ProRes
