SmallPeaches / DanmakuRender

一个可以录制带弹幕直播流的小工具
264 stars 33 forks source link

Windows无人值守时用显卡渲染会报错 #184

Closed PokersKun closed 5 months ago

PokersKun commented 5 months ago

具体情况为Windows 11 23H2台式机运行main.py启动程序后,开电源高性能模式和远程连接端口,24小时运行在没有直接操作台式机或者远程连接的情况下会报渲染错误:

  [2024-02-01 15:57:27,946][ERROR]: 分片 R:\bilibili\雪糕cheese(带弹幕版)\[指导棋~]02月01日14点57分.mp4 渲染错误.
  [2024-02-01 15:57:27,946][ERROR]: ffmpeg version 6.1.1-essentials_build-www.gyan.dev Copyright (c) 2000-2023 the FFmpeg developers
  built with gcc 12.2.0 (Rev10, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --pkg-config=pkgconf --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-sdl2 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-libfreetype --enable-libfribidi --enable-libharfbuzz --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-dxva2 --enable-d3d11va --enable-libvpl --enable-libgme --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libtheora --enable-libvo-amrwbenc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-librubberband
  libavutil      58. 29.100 / 58. 29.100
  libavcodec     60. 31.102 / 60. 31.102
  libavformat    60. 16.100 / 60. 16.100
  libavdevice    60.  3.100 / 60.  3.100
  libavfilter     9. 12.100 /  9. 12.100
  libswscale      7.  5.100 /  7.  5.100
  libswresample   4. 12.100 /  4. 12.100
  libpostproc    57.  3.100 / 57.  3.100
  Input #0, flv, from 'R:\bilibili\雪糕cheese\[指导棋~]02月01日14点57分.flv':
  Metadata:
  Rawdata         :
  displayWidth    : 2560
  displayHeight   : 1440
  fps             : 60
  profile         :
  level           :
  server_version  : 1.6.45.29
  server          : BSRS/1.6.45.29(Sco)
  encoder         : Lavf60.16.100
  Duration: 01:00:00.03, start: 0.020000, bitrate: 12325 kb/s
  Stream #0:0: Video: h264 (High), yuv420p(tv, bt709, progressive), 2560x1440 [SAR 1:1 DAR 16:9], 12288 kb/s, 60 fps, 60 tbr, 1k tbn
  Stream #0:1: Audio: aac (LC), 48000 Hz, stereo, fltp, 327 kb/s
  [Parsed_subtitles_0 @ 0000017bb25f0e00] libass API version: 0x1701000
  [Parsed_subtitles_0 @ 0000017bb25f0e00] libass source: commit: 0.17.0-63-gc047dd2ea16f73abb4f448e6db3637158c1226d0
  [Parsed_subtitles_0 @ 0000017bb25f0e00] Shaper: FriBidi 1.0.13 (SIMPLE) HarfBuzz-ng 8.3.0 (COMPLEX)
  [Parsed_subtitles_0 @ 0000017bb25f0e00] Using font provider directwrite (with GDI)
  [AVHWDeviceContext @ 0000017bb27b4700] Failed to create Direct3D device
  Device creation failed: -1313558101.

本机配置为 i7-13700 (启用核显) + RTX3080,编码器选择 h264_nvenc,网上查了下只有这个帖子的老哥和我一样的情况,疑似因为显卡休眠了没及时唤醒而导致 ffmpeg 没找到显卡而渲染报错,找半天也找不到和显卡休眠相关的设置,想请问下有什么有效的解决方法吗?

PokersKun commented 5 months ago

补充:使用台式机(直接操作或RPC)的情况下不会报这个错误可以正常渲染,把屏幕关掉一段时间就会出现这个问题

SmallPeaches commented 5 months ago

这个是DXVA2硬件加速的一个小bug,ffmpeg在Windows平台上默认使用DXVA2硬件加速编码,而DXVA2需要调用D3D11图形引擎,但是这个D3D11在屏幕不开的时候是没法调用的,所以说会出现failed to create Direct3D device,这个问题用RDP的话就很常见。你是N卡的话只要把那个hwaccel_args改成[-hwaccel, cuda],让ffmpeg调用NVIDIA自带的CUDA硬件加速单元就好了。

PokersKun commented 5 months ago

这个是DXVA2硬件加速的一个小bug,ffmpeg在Windows平台上默认使用DXVA2硬件加速编码,而DXVA2需要调用D3D11图形引擎,但是这个D3D11在屏幕不开的时候是没法调用的,所以说会出现failed to create Direct3D device,这个问题用RDP的话就很常见。你是N卡的话只要把那个hwaccel_args改成[-hwaccel, cuda],让ffmpeg调用NVIDIA自带的CUDA硬件加速单元就好了。

修改后问题已经解决了,感谢回复!

SecPhases commented 3 months ago

我也遇到这个问题了,amd显卡有什么办法可解吗