[win10] ffmpeg gpu加速
ffmpeg基础转:[win10] ffmpeg 学习笔记_*小呆的博客-CSDN博客根据NVIDIA官网,FFmpeg | NVIDIA Developer。如下的gpu被支持使用ffmpeg的gpu加速。FFmpeg GPU HW-Acceleration Support TableFermiKeplerMaxwell (1st Gen)Maxwell (2nd Gen)Maxwell (GM
ffmpeg 基础转:[win10] ffmpeg 学习笔记_*小呆的博客-CSDN博客
根据NVIDIA官网,FFmpeg | NVIDIA Developer。如下的gpu被支持使用ffmpeg的gpu加速。
FFmpeg GPU HW-Acceleration Support Table
Fermi | Kepler | Maxwell (1st Gen) | Maxwell (2nd Gen) | Maxwell (GM206) | Pascal | |
---|---|---|---|---|---|---|
H.264 encoding | N/A | FFmpeg v3.3 | FFmpeg v3.3 | FFmpeg v3.3 | FFmpeg v3.3 | FFmpeg v3.3 |
HEVC encoding | N/A | N/A | N/A | FFmpeg v3.3 | FFmpeg v3.3 | FFmpeg v3.3 |
MPEG2, MPEG-4, H.264 decoding | FFmpeg v3.3 | FFmpeg v3.3 | FFmpeg v3.3 | FFmpeg v3.3 | FFmpeg v3.3 | FFmpeg v3.3 |
HEVC decoding | N/A | N/A | N/A | N/A | FFmpeg v3.3 | FFmpeg v3.3 |
VP9 decoding | N/A | N/A | N/A | FFmpeg v3.3 | FFmpeg v3.3 | FFmpeg v3.3 |
官方提供,加速情况如下
我在使用ffmpeg.exe -f image2 -i \%05d.tiff -vcodec h264_nvenc output5_tiff.mkv 时出现如下错误:
No NVENC capable devices found
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
硬件要求
看来只安装了ffmpeg并不能直接使用 _nvenc,我们先检查一下硬件是否满足要求。Video Encode and Decode GPU Support Matrix [NEW] | NVIDIA Developer
NVDEC Support Matrix
BOARD | FAMILY | CHIP | # OF CHIPS | # OF NVDEC | Total # of NDEC | MPEG-1 | MPEG-2 | VC-1 | H.264 | H.265 (HEVC) | VP8 | VP9 | ||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
8 bit | 10 bit | 12 bit | 8 bit | 10 bit | 12 bit | |||||||||||
GeForce | ||||||||||||||||
GeForce GT 1030 | Pascal | GP108 | 1 | 1 | 1 | YES | YES | YES | YES | YES | YES | YES | NO | YES | YES | YES |
GeForce GTX 1050 / 1050 Ti | Pascal | GP107 | 1 | 1 | 1 | YES | YES | YES | YES | YES | YES | YES | NO | YES | YES | YES |
GeForce GTX 1050 / 1050 Ti | Pascal | GP106 | 1 | 1 | 1 | YES | YES | YES | YES | YES | YES | YES | NO | YES | NO | NO |
GeForce GTX 1060 | Pascal | GP106 | 1 | 1 | 1 | YES | YES | YES | YES | YES | YES | YES | NO | YES | NO | NO |
GeForce GTX 1060 | Pascal | GP104 | 1 | 1 | 1 | YES | YES | YES | YES | YES | YES | YES | NO | YES | NO | NO |
GeForce GTX 1070 - 1080 | Pascal | GP104 | 1 | 1 | 1 | YES | YES | YES | YES | YES | YES | YES | YES | YES | NO | NO |
GeForce GTX 1080 Ti | Pascal | GP102 | 1 | 1 | 1 | YES | YES | YES | YES | YES | YES | YES | NO | YES | YES | YES |
GeForce GTX Titan X Titan Xp | Pascal | GP102 | 1 | 1 | 1 | YES | YES | YES | YES | YES | YES | YES | NO | YES | YES | YES |
Titan V | Volta | GV100 | 1 | 1 | 1 | YES | YES | YES | YES | YES | YES | YES | NO | YES | YES | YES |
我是gtx1050,所以ok,在网上查询,突然发现,win里面如果直接下载了ffmpeg官网的exe,他其实里面自带编译好的一些nvenc的,是可以直接调用的。
windows 下ffmpeg gpu的加速
ffmpeg -codecs | sls cuvid
(备注:sls是powershell的命令,类似于linux下的grep命令)
DEV.LS h264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (decoders: h264 h264_qsv h264_cuvid ) (encoders:
libx264 libx264rgb h264_amf h264_nvenc h264_qsv nvenc nvenc_h264 )
DEV.L. hevc H.265 / HEVC (High Efficiency Video Coding) (decoders: hevc hevc_qsv hevc_cuvid ) (encoder
s: libx265 nvenc_hevc hevc_amf hevc_nvenc hevc_qsv )
DEVIL. mjpeg Motion JPEG (decoders: mjpeg mjpeg_cuvid ) (encoders: mjpeg mjpeg_qsv )
DEV.L. mpeg1video MPEG-1 video (decoders: mpeg1video mpeg1_cuvid )
DEV.L. mpeg2video MPEG-2 video (decoders: mpeg2video mpegvideo mpeg2_qsv mpeg2_cuvid ) (encoders: mpeg2video mpeg2_qsv )
DEV.L. mpeg4 MPEG-4 part 2 (decoders: mpeg4 mpeg4_cuvid ) (encoders: mpeg4 libxvid )
D.V.L. vc1 SMPTE VC-1 (decoders: vc1 vc1_qsv vc1_cuvid )
DEV.L. vp8 On2 VP8 (decoders: vp8 libvpx vp8_cuvid vp8_qsv ) (encoders: libvpx )
DEV.L. vp9 Google VP9 (decoders: vp9 libvpx-vp9 vp9_cuvid ) (encoders: libvpx-vp9 )
记录:
intel的集成显卡就支持硬件编解码,通过qsv技术
nvenc 是nvidia的硬压
软压、硬压 速度比较(底下有解释这两个名词)
1.hevc
ffmpeg.exe -i D:\Liu_Dong\Brain_map_compression\ZhangYueYi\raw_brain\test\%05d.tiff -v
codec hevc D:\Liu_Dong\Brain_map_compression\ZhangYueYi\raw_brain\output5.mkv
frame= 820 fps= 40 q=-0.0 Lsize= 89kB time=00:00:32.68 bitrate= 22.3kbits/s speed=1.61x
video:81kB audio:0kB subtitle:0kB other streams:0kB global headers:2kB muxing overhead: 9.601210%
x265 [info]: frame I: 4, Avg QP:10.98 kb/s: 510.90
x265 [info]: frame P: 290, Avg QP:31.95 kb/s: 19.42
x265 [info]: frame B: 526, Avg QP:34.97 kb/s: 15.84
x265 [info]: Weighted P-Frames: Y:0.0% UV:0.0%
x265 [info]: consecutive B-frames: 37.8% 8.8% 21.1% 1.4% 31.0%
encoded 820 frames in 19.72s (41.57 fps), 19.52 kb/s, Avg QP:33.78
2.libx265
ffmpeg.exe -i D:\Liu_Dong\Brain_map_compression\ZhangYueYi\raw_brain\test\%05d.tiff -v
codec libx265 D:\Liu_Dong\Brain_map_compression\ZhangYueYi\raw_brain\output5.mkv
frame= 820 fps= 43 q=-0.0 Lsize= 89kB time=00:00:32.68 bitrate= 22.3kbits/s speed=1.72x
video:81kB audio:0kB subtitle:0kB other streams:0kB global headers:2kB muxing overhead: 9.601210%
x265 [info]: frame I: 4, Avg QP:10.98 kb/s: 510.90
x265 [info]: frame P: 290, Avg QP:31.95 kb/s: 19.42
x265 [info]: frame B: 526, Avg QP:34.97 kb/s: 15.84
x265 [info]: Weighted P-Frames: Y:0.0% UV:0.0%
x265 [info]: consecutive B-frames: 37.8% 8.8% 21.1% 1.4% 31.0%
encoded 820 frames in 19.00s (43.16 fps), 19.52 kb/s, Avg QP:33.78
3.hevc_nvenc
ffmpeg.exe -i D:\Liu_Dong\Brain_map_compression\ZhangYueYi\raw_brain\test\%05d.tiff -v codec hevc_nvenc D:\Liu_Dong\Brain_map_compression\ZhangYueYi\raw_brain\output5.mkv
frame= 820 fps=107 q=16.0 Lsize= 84kB time=00:00:32.76 bitrate= 20.9kbits/s speed=4.26x
video:78kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 7.649312%
可以看到,速度快了3-4倍
知识点记录
1.查看所有可用的硬件加速器。
ffmpeg -hwaccels
2.软编码和硬编码如何区分
软编码:使用CPU进行编码
硬编码:使用非CPU进行编码,如显卡GPU、专用的DSP、FPGA、ASIC芯片等
3.软编码和硬编码比较
软编码:实现直接、简单,参数调整方便,升级易,但CPU负载重,性能较硬编码低,低码率下质量通常比硬编码要好一点。
硬编码:性能高,低码率下通常质量低于软编码器,但部分产品在GPU硬件平台移植了优秀的软编码算法(如X264)的,质量基本等同于软编码。
4. ffmpeg -codecs | grep nvenc(从编解码器里找到nvenc的相关选项)
如果不加 grep nvenc 出来的是全部的codec。
其中前缀含义如下:
前缀含义
D….. = Decoding supported
.E…. = Encoding supported
..V… = Video codec
..A… = Audio codec
..S… = Subtitle codec 字幕编解码
…I.. = Intra frame-only codec
….L. = Lossy compression 有损压缩
…..S = Lossless compression 无损压缩
5. ffmpeg -h encoder=hevc_nvenc (得到编码器为hevc_nvenc的全部信息)
注意这个可以预先检查你的设备是否支持这个编码器
ffmpeg version N-92288-gbdfd2e3c79 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 8.2.1 (GCC) 20181017
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth
libavutil 56. 21.100 / 56. 21.100
libavcodec 58. 34.100 / 58. 34.100
libavformat 58. 19.102 / 58. 19.102
libavdevice 58. 4.106 / 58. 4.106
libavfilter 7. 38.100 / 7. 38.100
libswscale 5. 2.100 / 5. 2.100
libswresample 3. 2.100 / 3. 2.100
libpostproc 55. 2.100 / 55. 2.100
Encoder hevc_nvenc [NVIDIA NVENC hevc encoder]:
General capabilities: delay hardware
Threading capabilities: none
Supported pixel formats: yuv420p nv12 p010le yuv444p p016le yuv444p16le bgr0 rgb0 cuda d3d11
hevc_nvenc AVOptions:
-preset <int> E..V..... Set the encoding preset (from 0 to 11) (default medium)
default E..V.....
slow E..V..... hq 2 passes
medium E..V..... hq 1 pass
fast E..V..... hp 1 pass
hp E..V.....
hq E..V.....
bd E..V.....
ll E..V..... low latency
llhq E..V..... low latency hq
llhp E..V..... low latency hp
lossless E..V..... lossless
losslesshp E..V..... lossless hp
-profile <int> E..V..... Set the encoding profile (from 0 to 4) (default main)
main E..V.....
main10 E..V.....
rext E..V.....
-level <int> E..V..... Set the encoding level restriction (from 0 to 186) (default auto)
auto E..V.....
1 E..V.....
1.0 E..V.....
2 E..V.....
2.0 E..V.....
2.1 E..V.....
3 E..V.....
3.0 E..V.....
3.1 E..V.....
4 E..V.....
4.0 E..V.....
4.1 E..V.....
5 E..V.....
5.0 E..V.....
5.1 E..V.....
5.2 E..V.....
6 E..V.....
6.0 E..V.....
6.1 E..V.....
6.2 E..V.....
-tier <int> E..V..... Set the encoding tier (from 0 to 1) (default main)
main E..V.....
high E..V.....
-rc <int> E..V..... Override the preset rate-control (from -1 to INT_MAX) (default -1)
constqp E..V..... Constant QP mode
vbr E..V..... Variable bitrate mode
cbr E..V..... Constant bitrate mode
vbr_minqp E..V..... Variable bitrate mode with MinQP (deprecated)
ll_2pass_quality E..V..... Multi-pass optimized for image quality (deprecated)
ll_2pass_size E..V..... Multi-pass optimized for constant frame size (deprecated)
vbr_2pass E..V..... Multi-pass variable bitrate mode (deprecated)
cbr_ld_hq E..V..... Constant bitrate low delay high quality mode
cbr_hq E..V..... Constant bitrate high quality mode
vbr_hq E..V..... Variable bitrate high quality mode
-rc-lookahead <int> E..V..... Number of frames to look ahead for rate-control (from 0 to INT_MAX) (default 0)
-surfaces <int> E..V..... Number of concurrent surfaces (from 0 to 64) (default 0)
-cbr <boolean> E..V..... Use cbr encoding mode (default false)
-2pass <boolean> E..V..... Use 2pass encoding mode (default auto)
-gpu <int> E..V..... Selects which NVENC capable GPU to use. First GPU is 0, second is 1, and so on. (from -2 to INT_MAX) (default any)
any E..V..... Pick the first device available
list E..V..... List the available devices
-delay <int> E..V..... Delay frame output by the given amount of frames (from 0 to INT_MAX) (default INT_MAX)
-no-scenecut <boolean> E..V..... When lookahead is enabled, set this to 1 to disable adaptive I-frame insertion at scene cuts (default false)
-forced-idr <boolean> E..V..... If forcing keyframes, force them as IDR frames. (default false)
-spatial_aq <boolean> E..V..... set to 1 to enable Spatial AQ (default false)
-temporal_aq <boolean> E..V..... set to 1 to enable Temporal AQ (default false)
-zerolatency <boolean> E..V..... Set 1 to indicate zero latency operation (no reordering delay) (default false)
-nonref_p <boolean> E..V..... Set this to 1 to enable automatic insertion of non-reference P-frames (default false)
-strict_gop <boolean> E..V..... Set 1 to minimize GOP-to-GOP rate fluctuations (default false)
-aq-strength <int> E..V..... When Spatial AQ is enabled, this field is used to specify AQ strength. AQ strength scale is from 1 (low) - 15 (aggressive) (from 1 to 15) (default 8)
-cq <float> E..V..... Set target quality level (0 to 51, 0 means automatic) for constant quality mode in VBR rate control (from 0 to 51) (default 0)
-aud <boolean> E..V..... Use access unit delimiters (default false)
-bluray-compat <boolean> E..V..... Bluray compatibility workarounds (default false)
-init_qpP <int> E..V..... Initial QP value for P frame (from -1 to 51) (default -1)
-init_qpB <int> E..V..... Initial QP value for B frame (from -1 to 51) (default -1)
-init_qpI <int> E..V..... Initial QP value for I frame (from -1 to 51) (default -1)
-qp <int> E..V..... Constant quantization parameter rate control method (from -1 to 51) (default -1)
-weighted_pred <int> E..V..... Set 1 to enable weighted prediction (from 0 to 1) (default 0)
6. cuvid不支持编码端,只有解码端。
执行了下面之后
ffmpeg -codecs | grep cuvid
可以看到只有解码端
DEV.LS h264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (decoders: h264 h264_qsv h264_cuvid ) (encoders: libx264 libx264rgb h264_amf h264_nvenc h264_qsv nvenc nvenc_h264 )
DEV.L. hevc H.265 / HEVC (High Efficiency Video Coding) (decoders: hevc hevc_qsv hevc_cuvid ) (encoders: libx265 nvenc_hevc hevc_amf hevc_nvenc hevc_qsv )
DEVIL. mjpeg Motion JPEG (decoders: mjpeg mjpeg_cuvid ) (encoders: mjpeg mjpeg_qsv )
DEV.L. mpeg1video MPEG-1 video (decoders: mpeg1video mpeg1_cuvid )
DEV.L. mpeg2video MPEG-2 video (decoders: mpeg2video mpegvideo mpeg2_qsv mpeg2_cuvid ) (encoders: mpeg2video mpeg2_qsv )
DEV.L. mpeg4 MPEG-4 part 2 (decoders: mpeg4 mpeg4_cuvid ) (encoders: mpeg4 libxvid )
D.V.L. vc1 SMPTE VC-1 (decoders: vc1 vc1_qsv vc1_cuvid )
DEV.L. vp8 On2 VP8 (decoders: vp8 libvpx vp8_cuvid vp8_qsv ) (encoders: libvpx )
DEV.L. vp9 Google VP9 (decoders: vp9 libvpx-vp9 vp9_cuvid ) (encoders: libvpx-vp9 )
更多推荐
所有评论(0)