Niek / superview

A small program that takes a 4:3 aspect ratio video file, and transforms it to a 16:9 video using the GoPro SuperView method
GNU General Public License v3.0
213 stars 21 forks source link

VAAPI HW acceleration #24

Open dsiroky opened 3 years ago

dsiroky commented 3 years ago

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 commented 3 years ago

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

Niek commented 3 years ago

I think you invented a new programming dialect here 😁

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

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 commented 3 years ago

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 commented 3 years ago

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'