intel / cartwheel-ffmpeg

Intel developer staging area for unmerged upstream patch contributions to FFmpeg
GNU Lesser General Public License v2.1
84 stars 31 forks source link

Error using new ffmpeg HEVC D3D12 encoder support.. (on both NV and AMD GPUs) #311

Open oscarbg opened 3 months ago

oscarbg commented 3 months ago

Hi, built FFMPEG on Windows and simple testing fails on NV 3070 GPU.. I verify:

Enabled encoders: d3d12va_encode

and ffmpeg -encoders:

V....D hevc_d3d12va D3D12VA hevc encoder (codec hevc)

running:

ffmpeg.exe -hwaccel d3d12va -hwaccel_output_format d3d12 -i c:\av1\input.mp4 -c:v hevc_d3d12va -acodec aac output.mp4

[hevc_d3d12va @ 00000237B7B29640] Encode failed 16
[hevc_d3d12va @ 00000237B7B29640] Output failed: -22.
[vost#0:0/hevc_d3d12va @ 00000237B7EC1980] Error submitting video frame to the encoder
[vost#0:0/hevc_d3d12va @ 00000237B7EC1980] Error encoding a frame: Invalid argument
[vost#0:0/hevc_d3d12va @ 00000237B7EC1980] Task finished with error code: -22 (Invalid argument)
[vost#0:0/hevc_d3d12va @ 00000237B7EC1980] Terminating thread with return code -22 (Invalid argument)
[out#0/mp4 @ 00000237B5D29A80] video:59KiB audio:478KiB subtitle:0KiB other streams:0KiB global headers:0Ki

more log:

 Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    encoder         : Lavf61.2.100
  Stream #0:0(und): Video: hevc (Main) (hev1 / 0x31766568), d3d12(tv, bt709, progressive), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 25 fps, 12800 tbn (default)
      Metadata:
        creation_time   : 2023-04-12T01:03:23.000000Z
        handler_name    : ISO Media file produced by Google Inc. Created on: 04/11/2023.
        vendor_id       : [0][0][0][0]
        encoder         : Lavc61.4.100 hevc_d3d12va
  Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
      Metadata:
        creation_time   : 2023-04-12T01:03:23.000000Z
        handler_name    : ISO Media file produced by Google Inc. Created on: 04/11/2023.
        vendor_id       : [0][0][0][0]
        encoder         : Lavc61.4.100 aac
[hevc_d3d12va @ 00000237B7B29640] Encode failed 16
[hevc_d3d12va @ 00000237B7B29640] Output failed: -22.
[vost#0:0/hevc_d3d12va @ 00000237B7EC1980] Error submitting video frame to the encoder
[vost#0:0/hevc_d3d12va @ 00000237B7EC1980] Error encoding a frame: Invalid argument
[vost#0:0/hevc_d3d12va @ 00000237B7EC1980] Task finished with error code: -22 (Invalid argument)
[vost#0:0/hevc_d3d12va @ 00000237B7EC1980] Terminating thread with return code -22 (Invalid argument)
oscarbg commented 2 months ago

@tong1wu can share if https://github.com/intel/cartwheel-ffmpeg/pull/313 is expected to fix, the errors I see in this issue?

tong1wu commented 2 months ago

@tong1wu can share if #313 is expected to fix, the errors I see in this issue?

It should be fixing this issue.

oscarbg commented 2 months ago

seems no.. recompiled today and still getting:

[hevc_d3d12va @ 00000177F916EB40] Encode failed 16
[hevc_d3d12va @ 00000177F916EB40] Output failed: -22.
[vost#0:0/hevc_d3d12va @ 00000177F916E5C0] Error submitting video frame to the encoder
[vost#0:0/hevc_d3d12va @ 00000177F916E5C0] Error encoding a frame: Invalid argument
[vost#0:0/hevc_d3d12va @ 00000177F916E5C0] Task finished with error code: -22 (Invalid argument)
[vost#0:0/hevc_d3d12va @ 00000177F916E5C0] Terminating thread with return code -22 (Invalid argument)
oscarbg commented 2 months ago

more info in case it helps.. using Nvida latest driver from 552.04 built with visual studio with flags (tried both a shared and a static build): ./configure --enable-vaapi --enable-d3d12va --target-os=win64 --arch=x86_64 --toolchain=msvc ./configure --enable-vaapi --enable-d3d12va --target-os=win64 --arch=x86_64 --toolchain=msvc --enable-shared both builds failed equally..

note I also tested on AMD RDNA2 GPU with latest drivers and even fail earlier (more error output shown) can share if wanted. but I think is better fix issues on Nvidia GPUs and later fix remaining bugs of D3D12 encoder AMD GPUs..

EDIT: question I also debugged with Visual Studio the exe file and seems is initializing the encoder/decoder correctly and even creating some correctly encoded frames before it fails en around 10-20fps.. maybe because of threading /sync issues and how to force a single threaded run (I also ran with "-threads 1" but also fails)..

xuguangxin commented 2 months ago

more info in case it helps.. using Nvida latest driver from 552.04 built with visual studio with flags (tried both a shared and a static build): ./configure --enable-vaapi --enable-d3d12va --target-os=win64 --arch=x86_64 --toolchain=msvc ./configure --enable-vaapi --enable-d3d12va --target-os=win64 --arch=x86_64 --toolchain=msvc --enable-shared both builds failed equally..

note I also tested on AMD RDNA2 GPU with latest drivers and even fail earlier (more error output shown) can share if wanted. but I think is better fix issues on Nvidia GPUs and later fix remaining bugs of D3D12 encoder AMD GPUs..

EDIT: question I also debugger with Visual Studio the exe file and seems is initializing the encoder/decoder correctly and even creating some correctly encoded frames before it fails en around 10-20fps.. maybe because of threading /sync issues and how to force a single threaded run (I also ran with "-threads 1" but also fails)..

@oscarbg , seems it's NV or AMD issue. Could you ask NV or AMD's help on this? thank you

oscarbg commented 2 months ago

@xuguangxin yes will try.. but don't know how to contact D3D12 teams at NV and AMD.. maybe you have better contacts to inform.. also would be nice and would help if this repo offered Windows binaries i.e. if a prebuilt ffmpeg.exe Windows binary with all cartwheel patches (like D3D12VA encode) was downloadable from this site perhaps added to quarterly releases for example added to: https://github.com/intel/cartwheel-ffmpeg/releases/tag/2024q1 this way I can point directly at how to run to reproduce .. afraid asking IVHs of patching FFMPEG and building first ffmpeg windows before they can debug their drivers.. they may answer to wait for patches to be merged into ffmpeg main first.. what do you think? thanks..

oscarbg commented 2 months ago

commented to AMD here: https://twitter.com/oscarbg81/status/1778613900021272835

oscarbg commented 2 months ago

commented to NV here: https://twitter.com/oscarbg81/status/1778615032248422738 will close once I confirm it's NV and/or AMD issue..

oscarbg commented 2 months ago

Asked to nvidia vulkan video devs: https://github.com/nvpro-samples/vk_video_samples/issues/76

oscarbg commented 2 months ago

Commented to amd amf guys? https://github.com/GPUOpen-LibrariesAndSDKs/AMF/issues/474