superview
superview copied to clipboard
VAAPI HW acceleration
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.
I forgot to emphasize - it does not compile :-)
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.
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.
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'