Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VAAPI HW acceleration #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

VAAPI HW acceleration #24

wants to merge 1 commit into from

Conversation

dsiroky
Copy link

@dsiroky dsiroky commented Nov 27, 2020

Hi, when I ran the CLI program it offered me HW VAAPI accelerated encoding but it didn't work out of the box. I managed to make it running by modifying directly ffmpeg arguments in the code.

This patch is a futile attempt to write a condition to make it more general (I have no Go skills). Perhaps someone can write it properly if you find it useful.

My direct modification was:

cmd := exec.Command("ffmpeg", "-hide_banner", "-progress", "pipe:1", "-loglevel", "panic", "-y", "-re", "-i", video.File, "-i", "x.pgm", "-i", "y.pgm", "-vaapi_device", "/dev/dri/renderD128", "-filter_complex", "remap,format=yuv444p,format=yuv420p,format=nv12,hwupload", "-c:v", encoder, "-b:v", strconv.Itoa(bitrate), "-c:a", "aac", "-x265-params", "log-level=error", output)

Cheers.

@dsiroky dsiroky marked this pull request as ready for review November 27, 2020 11:47
@dsiroky
Copy link
Author

dsiroky commented Nov 27, 2020

I forgot to emphasize - it does not compile :-)

@Niek
Copy link
Owner

Niek commented Nov 27, 2020

I think you invented a new programming dialect here 😁

I could add something like this, but I have two problems with it:

  • I have no way to test it since I don't have VAAPI hardware
  • The /dev/dri/renderD128 part doesn't look very portable at all

Maybe a better approach would be to add a flag to specify extra ffmpeg parameters, so it's up to the user what to provide in addition.

@dsiroky
Copy link
Author

dsiroky commented Nov 27, 2020

I can help with testing. The /dev/dri/renderD128 should cover vast majority of cases (https://trac.ffmpeg.org/wiki/Hardware/VAAPI). Having a flag (or more likely flags) for ffmpeg would be nice but ffmpeg is very picky about arguments ordering and mixing, especially with HW acceleration in the mix. The UX may get too complex and can require user's deeper knowledge of ffmpeg. I'd start with a simple case and if someone finds it does not work in some cases I'd try to extend it or make it more flexible. I'll be fine with any solution you choose.

@Niek
Copy link
Owner

Niek commented Aug 9, 2021

What we can do it: check if /dev/dri/renderD128 exists. If so, try to use a _vaapi codec by default (if available). It seems like these extra flags should cover most of the cases: -vaapi_device /dev/dri/renderD128 -vf 'format=nv12,hwupload'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants