viktorgino / headunit-desktop

HeadUnit Desktop is a car PC software built with Qt 5 and QML
https://github.com/viktorgino/headunit-desktop/wiki
GNU General Public License v3.0
285 stars 64 forks source link

VAAPI Support #65

Closed aselafernando closed 2 years ago

aselafernando commented 2 years ago

Support for VAAPI for hardware accelerated H264 decoding on platforms with a VAAPI compatible GPU (i.e. Intel).

Requires gstreamer1.0-vaapi and a VAAPI driver (intel-media-va-driver) be installed.

Will fall back to software decoding if VAAPI pipeline fails.

VAAPI decoder does not support YUV420P colorspace, hence the use of YV12 https://gstreamer.freedesktop.org/documentation/vaapi/vaapih264dec.html

Unsure if omxh264 can output to YV12 so have retained the use of YUV420P for the raspberry pi.

viktorgino commented 2 years ago

Is there any reason to use VAAPI, I'd prefer to use the V4L2 based encoders as VAAPI doesn't seem to work on a lot of embedded boards and some virtualised environments

aselafernando commented 2 years ago

The avdec_264 module in gstreamer doesn't support any sort of hardware offloading for decoding the h264 signal. I agree, VAAPI wont work on most embedded devices, or virtualised environments. However within the pull request, I first attempt to build the pipeline using a VAAPI decoder vaapih264dec low-latency=true ! vaapipostproc ! video/x-raw,format=YV12 if this fails because the gstreamer1.0-vaapi package has not been installed, it'll fall back to avdec_h264. If compiling for the raspberry PI then omxh264dec will always be used. The benefit of this, is that is is controlled at runtime, rather than it being fixed at compile time. Maybe having a command line switch is a better option to explicitly enable or disable VAAPI?

viktorgino commented 2 years ago

I'd prefer it to be there a settings option for a few different decoders. omxh264dec unfortunately isn't available on the latest 64 bit RPi OS, but can be replaced with v4l2h264dec with adding dtoverlay=rpivid-v4l2 to /boot/config.txt

I've got these working on different systems :

RPi OS 64-bit (Debian 11 arm64)

gst-launch-1.0 filesrc location=media.mp4 ! qtdemux  ! h264parse ! v4l2h264dec ! kmssink

64-bit Ubuntu on Intel i5 with integrated graphics

gst-launch-1.0 filesrc location=media.mp4 ! qtdemux  ! h264parse ! vaapih264dec ! xvimagesink

and software decoder on both systems

gst-launch-1.0 filesrc location=media.mp4 ! qtdemux  ! h264parse ! avdec_h264 ! kmssink
gst-launch-1.0 filesrc location=media.mp4 ! qtdemux  ! h264parse ! avdec_h264 ! xvimagesink
aselafernando commented 2 years ago

Closing PR, will be re-written to allow for decoders to be specified on the commandline