Librem 5 support VP9 on NXP i.MX8M

Librem 5 it has a dedicated VP9 decoder, the Hantro driver (V4L2) got support for VP9 so this feature will come on Linux 5.17.

  • More power save to L5
  • Less video heat to L5
  • Less video stutter to L5
16 Likes

We can thank Andrzej Pietrasiewicz and Benjamin Gaignard at Collabora for giving us good hardware video decoding on the L5. See:
https://lwn.net/Articles/846695/
https://lwn.net/Articles/870025/

Linux 5.14 added support for H.265/HEVC decoding in the Hantro G2 VPU in the L5’s i.MX 8M Quad processor, and now Linux 5.17 will add support for VP9 decoding in the Hantro G2. This also means that the PinePhone Pro with the RK3399S will also get VP9 decoding.

8 Likes

purism@pureos:~$ uname -ra
Linux pureos 5.17.0-1-librem5 #1 SMP PREEMPT Tue Apr 12 13:08:15 UTC 2022 aarch64 GNU/Linux
purism@pureos:~$ lsmod | grep -i hantro
hantro_vpu 135168 0
v4l2_vp9 24576 1 hantro_vpu
v4l2_h264 16384 1 hantro_vpu
v4l2_mem2mem 40960 1 hantro_vpu
videobuf2_vmalloc 20480 1 hantro_vpu

I got everything to decode vp9 by v.p.u but still no working because GStreamer does not register v4l2slvp9dec element. Also Hantro either register v4l2_h265

Plugin Details:
Name v4l2codecs
Description V4L2 CODEC Accelerators plugin
Filename /app/lib/gstreamer-1.0/libgstv4l2codecs.so
Version 1.21.0.1
License LGPL
Source module gst-plugins-bad
Binary package GStreamer Bad Plug-ins git
Origin URL Unknown package origin

v4l2slh264dec: V4L2 Stateless H.264 Video Decoder
v4l2slmpeg2dec: V4L2 Stateless Mpeg2 Video Decoder
v4l2slvp8alphadecodebin: VP8 Alpha Decoder
v4l2slvp8dec: V4L2 Stateless VP8 Video Decoder

2 Likes

[quote=“carlosgonz, post:4, topic:15937”]
rism@pureos:~$ uname -ra
Linux pureos 5.17.0-1-librem5 #1 SMP PREEMPT Tue Apr

That sounds like exciting progress! Any idea why its not working in kernel 17? was it not included?

Yes it is a nice progress for save battery, video performance, low temp.

It is not the Kernel issue but Gstreamer. I going to see this error more this week.

2 Likes

Can not decode ATM is a bug to Librem 5 & Hantro. : (

1 Like

Hantro G2: Librem 5: Seems is has more video decode using hardware accelerated: VP8, VP6 MPEG-4, VC-1, AVS AVS+, MPEG-2, DivX, Sorenson Spark.

1 Like

Yes i can finally play VP9, VP8 hardware accelerated on Librem 5. :yum:
Big thanks to Purism team Programmers.

3 Likes

Do I need to install anything in order to get the best HW video acceleration support?
I reflashed today and got regression from my previous performance.
Btw. I am willing to install non-free drivers if this gets me better video performance on the Librem 5.

3 Likes

Might be that the Build #12162 wasn’t the best choice (if so and because of some to us unfamiliar reason) to be put on your Librem 5? Therefore and in order to reflash it again (to get back on track, getting back environment you are familiar with), I would wait (few hours?) until some newer image available. Optionally (in another reliable current build file transfer terms), this semiautomated reflash method might be chosen as well:

I selected from the Preferences in Clapper -> GStreamer -> Plugin Ranking -> vpx -> activated vp8dec and vp9dec.
This was pure guessing, but helped.
As I am still not sure what is the root, maybe someone has an idea on how is HW acceleration activated and how one can test that it is indeed used.

3 Likes

It not need change anything in Clapper, Clapper autodetect when a video format is HW acceleration supported on Librem 5.
To check if a video is being HW acceleration played on Librem 5 the decode box is showing:
v4l2slvp8dec if it is VP8 video format
v4l2slvp9dec if it is VP9 video format —> some bad artifacts on playing. @dos tell to Martin.
v4l2slh264dec if it is H.264 video format
v4l2slh265dec if it is H.265 video format ----> not yet supported on userland, almost.

Enjoy your Purism GNU+Linux mobile!

2 Likes

Which decode box do you mean?

When the video is playback on Clapper , the are 2 options on right to bottom, 1 is audio and 2 is for video, this 2 options just is telling what libs is using to decode the audio y video.

2 Likes

how did you do that?

i am also trying to playback hw accelerated h264 videos but with no luck.

gstreamer 1.18.4

purism@pureos:~$ gst-launch-1.0 playbin uri=file:/home/purism/Videos/Appleseed\ Alpha\ (2014).mp4
Setting pipeline to PAUSED …
Pipeline is PREROLLING …
gst-launch-1.0: …/src/wayland-client.c:2339: wl_proxy_set_queue: Assertion `proxy->display == queue->display’ failed.
Aborted

looks like bug (not related to hw accel):


i guess it was not backported to 1.18

with ffmpeg it’s a different error:

[h264_v4l2m2m @ 0xaaab115f8900] Could not find a valid device
[h264_v4l2m2m @ 0xaaab115f8900] can’t configure decoder

do you have a command handy that works with gstreamer?

i am also trying to playback hw accelerated h264 videos but with no luck.

I am running PostmarketOS edge these days and I am able to run gst-launch-1.0 playbin uri=... without issues. Providing the -v flag shows that it’s using the v4l2slh264dec plugin. I am using GStreamer 1.22.3.

Perhaps you can try using Clapper on Flatpak instead? It should decode the video using hardware acceleration out of the box. You can see the GStreamer plugin used by pressing the video icon next to the seek bar.

I also get the same ffmpeg error when trying to play media with mpv, which results in an increase in heat and reduced battery life when comparing it with Clapper:

$ mpv --hwdec=auto h264.mp4
 (+) Video --vid=1 (*) (h264 1280x720 24.000fps)
 (+) Audio --aid=1 (*) (aac 2ch 48000Hz)
[vo/gpu/wayland] GNOME's wayland compositor lacks support for the idle inhibit protocol. This means the screen can blank during playback.
Failed to open VDPAU backend Error loading shared library libvdpau_nvidia.so: No such file or directory
[ffmpeg/video] h264_v4l2m2m: Could not find a valid device
[ffmpeg/video] h264_v4l2m2m: can't configure decoder
Could not open codec.

There is also a thread about H.265 playback which I didn’t manage to resolve yet: Librem 5 support H.265 on NXP i.MX8M

I’ve installed gstreamer1.0-plugins-base-apps and gst-play throws the same error:

purism@pureos:~/bin$ gst-play-1.0 …/Videos/Appleseed\ Alpha\ (2014).mp4
Press ‘k’ to see a list of keyboard shortcuts.
Now playing /home/purism/Videos/Appleseed Alpha (2014).mp4
gst-play-1.0: …/src/wayland-client.c:2339: wl_proxy_set_queue: Assertion `proxy->display == queue->display’ failed.
Aborted

hw decoder seems to be in place:

purism@pureos:~/bin$ gst-inspect-1.0 --plugin | grep -i v4l
video4linux2: v4l2src: Video (video4linux2) Source
video4linux2: v4l2sink: Video (video4linux2) Sink
video4linux2: v4l2radio: Radio (video4linux2) Tuner
video4linux2: v4l2deviceprovider (GstDeviceProviderFactory)
v4l2codecs: v4l2slh264dec: V4L2 Stateless H.264 Video Decoder
v4l2codecs: v4l2slvp8dec: V4L2 Stateless VP8 Video Decoder

reading on Clapper:


it states:

V4L2 stateless decoders are available since GStreamer 1.20 and are used by default on mobile/embedded devices (mainly on Allwinner, Rockchip and i.MX).

i think the gstreamer version (1.18.4) provided by Purism repo is not able to utilize v4l2 hw accel.
i just tried to compile gstreamer latest branch but could not because meson version (0.56.2) from Purism repo is not recent enough.
looks like, i have to compile meson first!

also, ffmpeg does not decodes in hardware:

purism@pureos:~/bin$ ./ffmpeg -c:v h264_v4l2m2m -i …/Videos/Appleseed\ Alpha\ (2014).mp4 out.ts
[h264_v4l2m2m @ 0xaaaaef2ef900] Could not find a valid device
[h264_v4l2m2m @ 0xaaaaef2ef900] can’t configure decoder
[vist#0:0/h264 @ 0xaaaaef0bad00] Error while opening decoder: Invalid argument
Invalid argument

i compiled ffmpeg from latest branch resulting in same error.
with above error i went to #ffmpeg IRC channel and i was told, that:
“v4l2 is currently a mess and it’s the vendors responsibility to provide good patches. one that do not break previous implementations.”

gstreamer and ffmpeg are key to many other Apps/Software.
i’ve tried

  • Firefox, mpv, totem, vlc - no hw accel
  • Clapper - using gstreamer 1.2 in a container(flatpak) is the only one i’ve found so far!

@dos, when do we get hw accel straight out of Purism repo?

i am foremost interested in ffmpeg as Kodi’s internal VideoPlayer uses it for v4l2 hw accel!

1 Like

i could install gstreamer 1.22.

what i did:

this installs GStreamer 1.22.0

from verbose logging i can see it’s using a v4l2slh264dec sink.

Unfortunately, it has major drawbacks and is not suitable as a replacement.
It breaks other things!
but it proofed that hw accel works with a newer version of gstreamer!

i also installed ffmpeg 5.1.2 from debian testing but it changed nothing.

may somebody from purism (@dos ? @guido.gunther ?) can comment on the hw accel status of ffmpeg?

adamk, this thread is about VP8 and VP9 Hardware acceleration by Librem5 CPU support. Others and you claim about not working hardware acceleration of the not open sourcen, have to licence h264 Support.

I think the cpu manufacturer did not pay that license and use instead the free, faster version of VP8 and VP9.

So the solution is: Do not use h264 Videos. Select if you can VP9. Or if the Videosource is only available as h264 and you have another faster CPU online (maybe with h264 build in support), use that to transcript the Video to VP8/VP9 before watching and send after requesting a transcode for some URL, just Link to the stream for that file on your server to your Phone. Comfortable via RSS. :wink:

Yes, I kind of hijacked this thread.
But for me, it’s all about video acceleration in hardware.
The built-in Vivante VPU supports decoding in hardware of h264, h265, vp8 or vp9.
vpx is more efficient and actually comes from Google. With your Librem5 go to YouTube, play a video and check the CPU usage.
Regardless of the codec, there is no video software I’ve tried from the Purism repo that speeds up in hardware.
The way I see it at the moment, acceleration works only with Gstreamer and with a newer version >1.20 that you can not install. With debian11/pureos11, I think, gestreamer will work (out of the box).
More important than Gstreamer is FFMPEG.
With ffmpeg the acceleration doesn’t work at all, regardless of the version!

ffmpeg is used e.g. in VLC and Kodi
gstreamer e.g. in Totem

some comment from purism on this is very appreciated!
please update on statuts of ffmpeg hw accel!

1 Like