AMF icon indicating copy to clipboard operation
AMF copied to clipboard

Need help for HEVC encoding GPU with AMF on FFMPEG

Open EmmettBrownn opened this issue 1 year ago • 4 comments

Hello everyone,

I work in video encoding and usually only use workstations with an NVIDIA GPU. I bought a new full AMD machine with a RX7700XT and a Ryzen 7900. ( I'm on Windows 11 ) I use a script on FFMPEG that I tried to transform to use it with AMF instead of NVENC but I don't understand why my GPU is hardly used during encoding. I have a GPU load at 17% maximum and my CPU at 100%. If you can help me it would be really incredible because it's been 2 weeks since I tried a lot of different solutions but it still doesn't work :/ and last question, when I add 'main10' profil for the hevc, FFMPEG make an error. Why ?

Here's the script I use:

    [string]$InputPath,
    [switch]$Auto = $false
)

$ConcurrentJobCount_CPU = 3

$defaults = @{
    'c:a'      = 'aac';
    'b:a'      = '317k';
    'aspect:v' = '2';
    'movflags' = '+faststart';
    'pass'     = '1';
};

$outputs = @{
    '1k' = @{
        'c:v'      = 'h264_amf';
        'b:v'      = '4.5M';
        'minrate'  = '4.5M';
        'maxrate'  = '4.5M';
        'bufsize'  = '9M';
        'profile:v'= 'main';
        'pix_fmt'  = 'yuv420p';
        'coder'    = '0';
        'filter:v' = @{'scale' = '1920:960' }
        'ac'       = '2';
    }
    '2k' = @{
        'c:v'      = 'h264_amf';
        'b:v'      = '15M';
        'minrate'  = '15M';
        'bufsize'  = '30M';
        'profile:v'= 'main';
        'pix_fmt'  = 'yuv420p';
        'coder'    = '0'
        'filter:v' = @{'scale' = '2880:1440' }
        'ac'       = '2'
    }
    '4k' = @{
        'c:v'      = 'h264_amf';
        'b:v'      = '28.1M';
        'minrate'  = '28.1M';
        'bufsize'  = '56.2M';
        'profile:v'= 'main';
        'pix_fmt'  = 'yuv420p';
        'coder'    = '0'
        'filter:v' = @{'scale' = '3840:1920' }
    }
    '8kHD' = @{
        'c:v'      = 'hevc_amf'
        'b:v'      = '40M';
        'minrate'  = '40M';
        'bufsize'  = '80M';
        'profile:v'= 'main10';
        'pix_fmt'  = 'yuv420p';
        'filter:v' = @{'scale' = '7680:3840' }
    }
    '8kUHD' = @{
        'c:v'      = 'hevc_amf'
        'b:v'      = '90M';
        'minrate'  = '90M';
        'bufsize'  = '130M';
        'profile:v'= 'main10';
        'pix_fmt'  = 'yuv420p';
        'filter:v' = @{'scale' = '8192:4096' }
    }
}

if ($Auto) {
    $outputs['1k']['c:v'] = 'h264_amf'
    $outputs['2k']['c:v'] = 'h264_amf'
    $outputs['4k']['c:v'] = 'h264_amf'
    $outputs['8kHD']['c:v'] = 'hevc_amf'
    $outputs['8kUHD']['c:v'] = 'hevc_amf'
}


EmmettBrownn avatar Feb 19 '24 00:02 EmmettBrownn

It looks like you are using software/CPU decoding and CPU color conversion from yuv420p to NV12 - native format for AMF and other HW encoders. So your pipeline is bound by CPU. Check this article: https://github.com/GPUOpen-LibrariesAndSDKs/AMF/wiki/FFmpeg%20and%20AMF%20HW%20Acceleration More details on AMF parameters are here: https://github.com/GPUOpen-LibrariesAndSDKs/AMF/wiki/AMF%20Encoder%20Settings%20and%20Tuning%20in%20FFmpeg 10-bit HEVC support for AMF was submitted to FFmpeg long time ago but so far was not merged into the tree: https://patchwork.ffmpeg.org/project/ffmpeg/patch/[email protected]/ https://patchwork.ffmpeg.org/project/ffmpeg/patch/[email protected]/ https://patchwork.ffmpeg.org/project/ffmpeg/patch/[email protected]/ AMF considers main10 as 10 bit format. This is strictly speaking against the spec but there is little practical reasons to enccode 8 bits into main10 profile. .

MikhailAMD avatar Feb 19 '24 16:02 MikhailAMD

Thank you very much for your reply.

I reread the documentation for hardware implementation in ffmpeg but if I add --hwaccel d3d11va -hwaccel_output_format, it doesn't work at all and ffmpeg crashes. I'm missing something... If I've understood correctly, main10 isn't really implemented in FFMPEG at the moment? So I can't encode main10 to HEVC with AMF?

EmmettBrownn avatar Feb 19 '24 19:02 EmmettBrownn

I reread the documentation for hardware implementation in ffmpeg but if I add --hwaccel d3d11va -hwaccel_output_format, it doesn't work at all and ffmpeg crashes.

It's a known bug, you can reference this issue: https://github.com/GPUOpen-LibrariesAndSDKs/AMF/issues/455

boyedarat avatar Feb 20 '24 01:02 boyedarat

I reread the documentation for hardware implementation in ffmpeg but if I add --hwaccel d3d11va -hwaccel_output_format, it doesn't work at all and ffmpeg crashes.

It's a known bug, you can reference this issue: https://github.com/GPUOpen-LibrariesAndSDKs/AMF/issues/455

Thanks for your reply !

EmmettBrownn avatar Feb 20 '24 02:02 EmmettBrownn