tencentKeTang icon indicating copy to clipboard operation
tencentKeTang copied to clipboard

请问gpu加速要加什么参数?

Open haoxuwang opened this issue 3 years ago • 14 comments

[您好大佬,我已经安装好cuda驱动,并且通过命令的方式执行解码已经可以使用gpu加速。但是配置文件加入参数后,程序下载时报错,麻烦看下是不是参数的原因,谢谢! QQ截图20210821124907 QQ截图20210821124925

haoxuwang avatar Aug 21 '21 08:08 haoxuwang

方便提供一下配置文件么 On Aug 21, 2021, 4:37 PM +0800, haoxuwang @.***>, wrote:

[您好大佬,我已经安装好cuda驱动,并且通过命令的方式执行解码已经可以使用gpu加速。但是配置文件加入参数后,程序下载时报错,麻烦看下是不是参数的原因,谢谢!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

HarryWang29 avatar Aug 22 '21 05:08 HarryWang29

方便提供一下配置文件么 On Aug 21, 2021, 4:37 PM +0800, haoxuwang @.***>, wrote: [您好大佬,我已经安装好cuda驱动,并且通过命令的方式执行解码已经可以使用gpu加速。但是配置文件加入参数后,程序下载时报错,麻烦看下是不是参数的原因,谢谢! — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

感谢回复,配置文件已上传附件。 config.zip

haoxuwang avatar Aug 22 '21 05:08 haoxuwang

你在终端下,gpu加速的完整命令是?应该有-c:v这种参数把 On Aug 22, 2021, 1:37 PM +0800, haoxuwang @.***>, wrote:

方便提供一下配置文件么 … On Aug 21, 2021, 4:37 PM +0800, haoxuwang @.***>, wrote: [您好大佬,我已经安装好cuda驱动,并且通过命令的方式执行解码已经可以使用gpu加速。但是配置文件加入参数后,程序下载时报错,麻烦看下是不是参数的原因,谢谢! — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe. 感谢回复,配置文件已上传附件。 config.zip — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

HarryWang29 avatar Aug 22 '21 05:08 HarryWang29

你在终端下,gpu加速的完整命令是?应该有-c:v这种参数把 On Aug 22, 2021, 1:37 PM +0800, haoxuwang @.>, wrote: > 方便提供一下配置文件么 > … > On Aug 21, 2021, 4:37 PM +0800, haoxuwang @.>, wrote: [您好大佬,我已经安装好cuda驱动,并且通过命令的方式执行解码已经可以使用gpu加速。但是配置文件加入参数后,程序下载时报错,麻烦看下是不是参数的原因,谢谢! — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe. 感谢回复,配置文件已上传附件。 config.zip — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

ffmpeg -hwaccel cuvid -c:v h264_cuvid -i 0.mp4 -c:v h264_nvenc -y 00.mp4 配置文件的参数改为 -hwaccel cuvid -c:v h264_cuvid,程序还是是报错

haoxuwang avatar Aug 22 '21 05:08 haoxuwang

params: '-hwaccel cuvid -c:v h264_cuvid -c:v h264_nvenc' 试试看 On Aug 22, 2021, 1:44 PM +0800, haoxuwang @.***>, wrote:

你在终端下,gpu加速的完整命令是?应该有-c:v这种参数把 … On Aug 22, 2021, 1:37 PM +0800, haoxuwang @.>, wrote: > 方便提供一下配置文件么 > … > On Aug 21, 2021, 4:37 PM +0800, haoxuwang @.>, wrote: [您好大佬,我已经安装好cuda驱动,并且通过命令的方式执行解码已经可以使用gpu加速。但是配置文件加入参数后,程序下载时报错,麻烦看下是不是参数的原因,谢谢! — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe. 感谢回复,配置文件已上传附件。 config.zip — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe. ffmpeg -hwaccel cuvid -c:v h264_cuvid -i 0.mp4 -c:v h264_nvenc -y 00.mp4 配置文件的参数改为 -hwaccel cuvid -c:v h264_cuvid,程序还是是报错 — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

HarryWang29 avatar Aug 22 '21 05:08 HarryWang29

params: '-hwaccel cuvid -c:v h264_cuvid -c:v h264_nvenc' 试试看 On Aug 22, 2021, 1:44 PM +0800, haoxuwang @.***>, wrote: > 你在终端下,gpu加速的完整命令是?应该有-c:v这种参数把 > … > On Aug 22, 2021, 1:37 PM +0800, haoxuwang @.>, wrote: > 方便提供一下配置文件么 > … > On Aug 21, 2021, 4:37 PM +0800, haoxuwang @.>, wrote: [您好大佬,我已经安装好cuda驱动,并且通过命令的方式执行解码已经可以使用gpu加速。但是配置文件加入参数后,程序下载时报错,麻烦看下是不是参数的原因,谢谢! — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe. 感谢回复,配置文件已上传附件。 config.zip — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe. ffmpeg -hwaccel cuvid -c:v h264_cuvid -i 0.mp4 -c:v h264_nvenc -y 00.mp4 配置文件的参数改为 -hwaccel cuvid -c:v h264_cuvid,程序还是是报错 — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

还是报错,报错信息如下,辛苦再帮忙看下! 微信截图_20210822140008 微信截图_20210822140025

haoxuwang avatar Aug 22 '21 11:08 haoxuwang

可能知道原因了,晚点我再看看把,不过很尴尬的是,我可能不是很好测试结果,晚点可能会需要你这边帮忙测试一下 On Aug 22, 2021, 7:09 PM +0800, haoxuwang @.***>, wrote:

params: '-hwaccel cuvid -c:v h264_cuvid -c:v h264_nvenc' 试试看 … On Aug 22, 2021, 1:44 PM +0800, haoxuwang @.***>, wrote: > 你在终端下,gpu加速的完整命令是?应该有-c:v这种参数把 > … > On Aug 22, 2021, 1:37 PM +0800, haoxuwang @.>, wrote: > 方便提供一下配置文件么 > … > On Aug 21, 2021, 4:37 PM +0800, haoxuwang @.>, wrote: [您好大佬,我已经安装好cuda驱动,并且通过命令的方式执行解码已经可以使用gpu加速。但是配置文件加入参数后,程序下载时报错,麻烦看下是不是参数的原因,谢谢! — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe. 感谢回复,配置文件已上传附件。 config.zip — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe. ffmpeg -hwaccel cuvid -c:v h264_cuvid -i 0.mp4 -c:v h264_nvenc -y 00.mp4 配置文件的参数改为 -hwaccel cuvid -c:v h264_cuvid,程序还是是报错 — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe. 还是报错,报错信息如下,辛苦再帮忙看下!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

HarryWang29 avatar Aug 22 '21 14:08 HarryWang29

可能知道原因了,晚点我再看看把,不过很尴尬的是,我可能不是很好测试结果,晚点可能会需要你这边帮忙测试一下 On Aug 22, 2021, 7:09 PM +0800, haoxuwang @.>, wrote: > params: '-hwaccel cuvid -c:v h264_cuvid -c:v h264_nvenc' 试试看 > … > On Aug 22, 2021, 1:44 PM +0800, haoxuwang @.>, wrote: > 你在终端下,gpu加速的完整命令是?应该有-c:v这种参数把 > … > On Aug 22, 2021, 1:37 PM +0800, haoxuwang @.>, wrote: > 方便提供一下配置文件么 > … > On Aug 21, 2021, 4:37 PM +0800, haoxuwang @.>, wrote: [您好大佬,我已经安装好cuda驱动,并且通过命令的方式执行解码已经可以使用gpu加速。但是配置文件加入参数后,程序下载时报错,麻烦看下是不是参数的原因,谢谢! — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe. 感谢回复,配置文件已上传附件。 config.zip — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe. ffmpeg -hwaccel cuvid -c:v h264_cuvid -i 0.mp4 -c:v h264_nvenc -y 00.mp4 配置文件的参数改为 -hwaccel cuvid -c:v h264_cuvid,程序还是是报错 — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe. 还是报错,报错信息如下,辛苦再帮忙看下! — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

非常乐意能配合您测试,等您处理好可以把测试方法回复给我。或者加下微信 d2g4NzAyNTU2OQ==(base64),谢谢!

haoxuwang avatar Aug 22 '21 14:08 haoxuwang

同样的问题,请问是否有解决

uminosaki avatar Nov 16 '21 07:11 uminosaki

妥协的,我将参数设置为 -c:v h264_cuvid -vcodec h264_nvenc 后可以使用英伟达显卡来做编码,虽然cpu占用依然很高,不过速度明显加快。 一旦加入-hwaccel参数指定硬件加速的话,依然报错。

uminosaki avatar Nov 16 '21 08:11 uminosaki

经典的ffmpeg新用户问题……这个是传入参数的顺序问题

这个问题以前在压视频的时候出现过,当初摸了好久才找到原因。 如今,一眼就看出来了————


这是一个合并音视频、转换格式、同时启用N卡硬件加速的ffmpeg命令:

ffmpeg.exe -hwaccel cuvid -hwaccel_output_format cuda 
 -i input.flv -i audio.aac -map 0:v:0 -map 1:a:0 
 -c:v hevc_nvenc -profile:v main -level 5.1 -qmin 23 -qmax 30 -c:a copy 
 -sn -map_metadata -1 -map_chapters -1 -hide_banner 
 -f mp4 
 output_x265.mp4

(运行的时候记得把换行符去掉) 实际效果是,几乎不吃CPU。相应的:GPU要跑满的。我的1050显卡_(古老吧?)_的速度压1080P视频一般稳定在300帧左右。

需要注意的是,每一段都有先后顺序的。 其中,启用NVIDIA硬件加速的命令 -hwaccel cuvid -hwaccel_output_format cuda 必须放在输入流 -i 输入文件 之前, 视频编码器-c:v hevc_nvenc、音频编码器-c:a copy、杂项-sn -map_metadata -1 -map_chapters -1 -hide_banner都得放在输入流 -i 输入文件 之后、-f [格式] 输出文件之前。 参考: http://ffmpeg.org/ffmpeg.html


如果报这种错误,可想而知是命令行扩展命令的先后顺序不对。

https://github.com/HarryWang29/tencentKeTang/blob/8aec69005f0b2376a82ac93579e985f096a9e043/ffmpeg/mergeAndDownload.go#L11-L14

在这里可以发现,在我们需要的 -hwaccel 等先行指令被送进去之前,-i已经出现了。指令实际插入位置在 -i 输入文件 之后。所以ffmpeg会爆炸。

改代码的时候注意,不要为了一个-hwaccel-c:v的进场位置又放到-i之后了,不然还得报错…… 这 -hwaccel 的用法已经和我用的那个已经完全不一样了,支持的选项还根据编译选项而变化,可以跑一下ffmpeg -hwaccels看看…… 我用的是 https://www.gyan.dev/ffmpeg/builds/#release-builds 下的full版本。 如果你实在不想思考解决方案,可以直接默认 -hwaccel auto 加进去完事。(pia~)

可以考虑在config中加一个hwaccel选项,默认的示范配置文件要写auto,只要选项不为空就把-hwaccel + 输入的内容放到最前面,完事。当然还要放着某些傻家伙傻乎乎的把-hwaccel放到-i后面……

在作者更新代码之前,可以先用 -c:v copy -c:a copy 先缓存下来,然后再单独硬件编码。虽然麻烦了一点,但也比只吃CPU强。

快更新,更新完了喊我一下(

@HarryWang29

Janet-Baker avatar Nov 25 '21 15:11 Janet-Baker

谢谢你的解答,这非常有用。

uminosaki avatar Dec 14 '21 08:12 uminosaki

求更新 ^_^

Liuzhj avatar Apr 12 '22 03:04 Liuzhj

@Janet-Baker 非常感谢给予的ffmpeg参数教程,目前我采用了无脑加如 -hwaccel auto 的方案,此issues一直没解决的主要原因还是手上没有n卡机器,最新的版本中在代码里已配制好 -hwaccel 参数,后续新项目中会优化此出问题

HarryWang29 avatar Jul 22 '22 09:07 HarryWang29