Skip to content

Add support for GNU/Linux VAAPI (AMD, Intel, ..) HW-Encoding #1083

Closed

Description

@sgothel

Feature request

Similar to issue #259 (supporting NVidia's NVenc), hardware accelerated encoding for AMD and Intel should be supported via GNU/Linux VAAPI as supported by FFMPEG.
See https://trac.ffmpeg.org/wiki/HWAccelIntro

Similar to issue #259, this shall be based on issue #974, i.e. based on FFMPEG.

Activity

  1. sr55 commented on Dec 28, 2017

    @sr55
    Contributor

    Intel QuickSync should, in theory, work through mfx via ffmpeg/libav so I would avoid a second code path for that.

  2. sgothel commented on Dec 29, 2017

    @sgothel
    ContributorAuthor

    @jstebbins @sr55 currently working on this item .. on top of ffmpeg + nvenv-encoder branch
    Edit: Might support VAAPI based h264, hevc and vp8/vp9 encoding.
    Not so sure about the latter vp8/vp9 though, but some support seems to be available in ffmpeg sources.

  3. rathann commented on Dec 29, 2017

    @rathann

    @sr55 Wouldn't it make more sense to have a single code path for both Intel and AMD (and NVIDIA via vdpau-to-vaapi wrapper library)? Intel fully supports VAAPI as far as I know. Also, VAAPI should work on non-x86 architectures while libmfx is x86-only.

  4. sr55 commented on Dec 29, 2017

    @sr55
    Contributor

    It wouldn't be a single code path though. You need separate implementations for Windows and Mac.

    Also, general purpose API's tend to have problems. VT on Mac cripples the hardware encoders feature set, DXVA on windows is horrifically unreliable and in areas, fundamentally broken for example.

    So, I'd then ask the questions:

    1. Does VA-API support the full feature set of these encoders, including the filters and do we actually have up-to-date driver support (the intel site doesn't indicate support for Kaby/Coffee lake features for example)
    2. Is it actually reliable?
    3. Does it support zero-copy?

    Since we need libmfx and the nvidia/vce sdks's via ffmpeg anyway for Windows, everything should just use those same paths so we have consistent behaviour on all platforms. That's easier to support.

    We already have a wrapper around using libav encoders, so it's not a giant leap to extend that and use ffmpeg/libav's built-in support that already exists.

    QuickSync is Intel Only, so it doesn't matter that it's x86 only library. Also, we don't formally support or have any intention of supporting any other hardware platforms. (Supporting what we already do is a stretch for a project with limited resources)

  5. sgothel commented on Jan 12, 2018

    @sgothel
    ContributorAuthor

    added initial pull #1111
    @sr55 your questions are partly answered and repeated/extended in the commit and pull request
    It is a work in progress (WIP) and we need to solve the question I asked first :)
    I believe it could become a nice added feature when it properly supports AMD and Intel.
    On Debian 9.3 'stretch' I was able to get some results on AMD (erratic) and Intel (working but big file size, 'normal' as I have read)

    Edit: I may add that primary motivation for VAAPI support is due to enabling AMD hw encoding using the open-source driver.
    I agree with your assessment that generic API's need good maturity to compete with specific solutions, like QuickSync (Intel).
    Therefor allowing VAAPI in HB (when it's working) in parallel to specific solutions might be desired. Only when VAAPI reaches parity with the individual encoding API one might consider its retirement.

  6. DocMAX commented on Apr 22, 2018

    @DocMAX

    When will it be done?

  7. sr55 commented on Apr 22, 2018

    @sr55
    Contributor

    @DocMAX There is no ETA and we haven't decided whether to accept this yet, or stick to vendor specific implementations so it'll be some time away.

  8. mirh commented on Apr 22, 2018

    @mirh

    It depends on #1078 to the very least, so wait for that for starters.

  9. sr55 commented on Jun 29, 2018

    @sr55
    Contributor

    Closing in favour of sticking to native support.
    Nvenc and quicksync both have support on Linux. AMF looks like it might add support too so we'll pick that up when available.

  10. survivor303 commented on May 8, 2020

    @survivor303

    No support from AMD yet.. so perhaps this can be opened again?

  11. userofryzen commented on May 25, 2020

    @userofryzen

    for me vaapi is mature enough to reopen this.

  12. 29 remaining items

  13. jstebbins commented on Jun 19, 2020

    @jstebbins
    Contributor

    Strange. Can't reproduce that here. I'm running the 1.3.3 release and MediaSDK plugin both installed from flathub.

    My CPU specifics for reference

    07:20:19] CPU: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    [07:20:19]  - Intel microarchitecture Kaby Lake
    [07:20:19]  - logical processor count: 16
    [07:20:19] Intel Quick Sync Video support: yes
    [07:20:19]  - Intel Media SDK hardware: API 1.32 (minimum: 1.3)
    [07:20:19]  - H.264 encoder: yes
    [07:20:19]     - preferred implementation: hardware (any) via ANY
    [07:20:19]     - capabilities (hardware):  breftype icq+la+i+downs vsinfo opt1 opt2+mbbrc+extbrc+trellis+ib_adapt+nmpslice
    [07:20:19]  - H.265 encoder: yes (8bit: yes, 10bit: yes)
    [07:20:19]     - preferred implementation: hardware (any) via ANY
    [07:20:19]     - capabilities (hardware):  bpyramid icq vsinfo opt1
    

    @maximd33 or @agalin89 any ideas?

  14. maximd33 commented on Jun 19, 2020

    @maximd33
    Contributor

    @mathstuf can you please try nightly build ?
    we had similar issue fixed , #2862

  15. jstebbins commented on Jun 19, 2020

    @jstebbins
    Contributor
  16. sgothel commented on Jul 23, 2020

    @sgothel
    ContributorAuthor

    @jstebbins I have updated my vaapi work in hw-encoder-vaapi
    (as well as general hw-encoder-base and hw-encoder-nvenc - all names of my new branches).

    Please feel free to comment, pick, merge ..

    The usual TODO: I still have some hardcoded features in vaapi and nvenc,
    which I like to have added to the extra-options field.
    To enable this for the vaapi/nvenc codecs and have it stored in presets,
    I need a little help from you.

    Detailed description in the vaapi commit message,
    working quite well on a AMD NAVI10 using my mesa-vaapi patch.

    1. hw-encoder-base https://github.com/sgothel/HandBrake/tree/hw-encoder-base
      1.1) hw-encoder-nvenc https://github.com/sgothel/HandBrake/tree/hw-encoder-nvenc
      1.2) hw-encoder-vaapi https://github.com/sgothel/HandBrake/tree/hw-encoder-vaapi
    2. hw-encoder-joint https://github.com/sgothel/HandBrake/tree/hw-encoder-joint

    Notable, using vaapi with Handbrake (utilizing the hardcoded soft-frame -> NV12 -> VAAPI)
    is faster than ffmpeg commandline: ~150 fps -> ~200 fps

    I compared quality differences with x264 ~5Mbit/s and while I couldn't see
    any visually really, PSNR and SSIM difference to orig were below 1%.

    As usual, great job of all of you working on Handbrake!
    I regularly use it, hence my sporadic contributions.
    Will help with integration, if intended by your team.

  17. sgothel commented on Jul 23, 2020

    @sgothel
    ContributorAuthor

    hw-encoder-vaapi commit in question
    sgothel@c0fd9ee

  18. sgothel commented on Jul 23, 2020

    @sgothel
    ContributorAuthor

    The mesa-vaapi patch included is also available here sgothel/mesa@5e10db6

    I might need to communicate this one with the mesa and ffmpeg team.

  19. sgothel commented on Jul 23, 2020

    @sgothel
    ContributorAuthor

    Last one: W/o this mesa-vaapi patch, Matroska can't be stored - mp4 doesn't care.
    Hence is usable w/o in a limited format fashion.

  20. mauimauer commented on Jan 13, 2021

    @mauimauer

    I could get vaapi_h264 going on an AMD Renoir based APU (7400U). HEVC, VP8 and 9 are just logged with "No usable encoding profile found". VCN should support HEVC encoding.

  21. sgothel commented on Apr 20, 2021

    @sgothel
    ContributorAuthor

    Updated the VAAPI patches.

    • Tested on Linux w/ AMD GPU
    • Tested build/bringup branch hw-encoder-vaapi
    • Tested build/bringup branch hw-encoder-joint

    As usual, some hardcoded parameter exist, as I still wait for UI support
    to add additional encoder parameter.

    Perhaps one day this gets merged ;-)
    I just use this branch for encoding jobs, leaving the CPU cool.
    Nice TODO: Test on weak platforms but with VAAPI hw encoder.

    @sr55 @jstebbins .. FYI

    +++

    Note on Mesa: Works with latest git master, haven't checked
    in which mesa release the following patches were added:
    file: src/gallium/frontends/va/config.c

    Needs:

    1. commit 245f619411b5f9b10a11f0c68645f5eae0586d85
      Author: Thong Thai [email protected]
      Date: Thu Mar 12 10:06:52 2020 -0400

    2. commit 9a4daac0bbf8233f7f1fe5a65aef882f13dccd2e
      Author: Thong Thai [email protected]
      Date: Tue Jun 2 09:27:07 2020 -0400

    .. and perhaps (maybe not):

    1. commit 38f012e0238f145f4c83bf7abf59afceee333397
      Author: Thong Thai [email protected]
      Date: Fri Feb 12 13:42:42 2021 -0500
  22. RAMChYLD commented on Jul 6, 2021

    @RAMChYLD

    Please reopen. There are several problems with the AMD proprietary drivers:

    1. They only work on Ubuntu LTS, RHEL or SLES- enterprise distros. Ubuntu aside, Last I checked SLES and RHEL are NOT free and CANNOT be legally downloaded by most people (only trial is available for SLES, RHEL meanwhile is blocked behind a paywall). The Ubuntu version is fine-tuned for Ubuntu LTS. Trying to install on a non-LTS version of Ubuntu will make very bad things happen (trust me, I've broke a Ubuntu system by installing the proprietary driver on a non-LTS Ubuntu. Black screen and lock up, change VT to get a text based terminal stopped working).

    2. Continuing on the fact above, you cannot use proprietary drivers if you run Arch, Sabayon, Gentoo, etc.

    3. The performance are subpar for gaming. Increased stuttering and lower frame rates have been observed.

  23. sgothel commented on Jul 22, 2021

    @sgothel
    ContributorAuthor

    From time to time I merge and update my branches, saving some CPU power when I need to transcode our video archive. However, I would love to see this merger but looks like this is the bottom of the priority.

    Next update from my side with Debian Bullseye, hopefully the Mesa3D patches are all included in the distribution by then.

    https://github.com/sgothel/HandBrake/branches

    and

    https://jausoft.com/cgit/HandBrake.git/refs/heads

  24. userofryzen commented on Jul 23, 2021

    @userofryzen
  25. Keksimus69 commented on Sep 25, 2022

    @Keksimus69

    It's kinda ridiculous to only support proprietary drivers on an open source project for users who want to run an open source operating system...

  26. mathew2214 commented on Sep 26, 2023

    @mathew2214

    over a year later, still no VAAPI support on AMD. handbrake 1.6.1 MESA 22.3

  27. locked and limited conversation to collaborators on Sep 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions