Bug 251679

Summary: [GStreamer] Playing video causes very high CPU usage
Product: WebKit Reporter: Kdwk <kdwkleung>
Component: MediaAssignee: Nobody <webkit-unassigned>
Status: RESOLVED DUPLICATE    
Severity: Normal CC: bugs-noreply, mcatanzaro, philn
Priority: P2    
Version: WebKit Nightly Build   
Hardware: PC   
OS: Linux   
Attachments:
Description Flags
Screencast showing CPU usage of Epiphany when playing video (high) VS Clapper when playing video (low)
none
gst.log
none
gst.log
none
gst.log
none
gst.log none

Description Kdwk 2023-02-03 04:47:56 PST
On https://wpewebkit.org/blog/05-new-svg-engine.html, there are a few videos encoded in H.264. My hardware has support for accelerated decoding of this codec. However, when using Epiphany to play the videos on the website, CPU usage is very high, as can be seen in the screencast, and there are lots of dropped frames. If the video is downloaded and played in Clapper (Flatpak), a video player, CPU usage is much lower and there are no dropped frames.

Tested:
Epiphany Technology Preview (Flatpak) 44.alpha-32-g481e050e5+, WebKitGTK 2.39.7, GStreamer 1.20.5
Fedora Silverblue 37
Comment 1 Kdwk 2023-02-03 04:49:33 PST
Created attachment 464820 [details]
Screencast showing CPU usage of Epiphany when playing video (high) VS Clapper when playing video (low)
Comment 2 Philippe Normand 2023-02-04 01:23:26 PST
That's a packaging issue. The GStreamer backend is capable of handling HW decoders but in the flatpak runtime the only GStreamer HW decoder shipped there is disabled.

If your GPU is AMD or Intel you can try to set this env var in the flatpak runtime: GST_PLUGIN_FEATURE_RANK=vah264dec:MAX,vah265dec:MAX,vavp8dec:MAX,vavp9dec:MAX
Comment 3 Kdwk 2023-02-04 01:34:55 PST
I'm afraid the problem persists after setting the environmental variable (using Flatseal).
Comment 4 Philippe Normand 2023-02-04 03:08:34 PST
Can you try the env var mentioned in https://bugs.webkit.org/show_bug.cgi?id=251017#c19 ?
Comment 5 Kdwk 2023-02-04 05:40:09 PST
(In reply to Philippe Normand from comment #4)
> Can you try the env var mentioned in
> https://bugs.webkit.org/show_bug.cgi?id=251017#c19 ?

The original env var works, thanks (I made a mistake). Though I must say I don't really understand why the HW decoder is disabled in the runtime...
Comment 6 Kdwk 2023-02-16 02:59:24 PST
Just tried the videos on https://wpewebkit.org/blog/05-new-svg-engine.html again. This time the problem persists even with the GST plugin rank environmental variable set.
Comment 7 Philippe Normand 2023-02-16 03:47:16 PST
Please make sure to install org.freedesktop.Platform.GL.default//22.08-extra

And then provide the output of flatpak run --command=gst-inspect-1.0 org.gnome.Epiphany.Devel va
Comment 8 Kdwk 2023-02-16 04:45:13 PST
org.freedesktop.Platform.GL.default//22.08-extra is installed.

Plugin Details:
  Name                     va
  Description              VA-API codecs plugin
  Filename                 /usr/lib/x86_64-linux-gnu/gstreamer-1.0/libgstva.so
  Version                  1.20.5
  License                  LGPL
  Source module            gst-plugins-bad
  Source release date      2022-12-19
  Binary package           GStreamer Bad Plug-ins source release
  Origin URL               freedesktop-sdk

  vaav1dec: VA-API AV1 Decoder
  vadeinterlace: VA-API Deinterlacer
  vah264dec: VA-API H.264 Decoder
  vah265dec: VA-API H.265 Decoder
  vampeg2dec: VA-API Mpeg2 Decoder
  vapostproc: VA-API Video Postprocessor
  vavp8dec: VA-API VP8 Decoder
  vavp9dec: VA-API VP9 Decoder

  8 features:
  +-- 8 elements
Comment 9 Philippe Normand 2023-02-16 06:03:36 PST
(In reply to Philippe Normand from comment #4)
> Can you try the env var mentioned in
> https://bugs.webkit.org/show_bug.cgi?id=251017#c19 ?

Did you try this? WEBKIT_GST_DMABUF_SINK_ENABLED=1
Comment 10 Kdwk 2023-02-16 06:09:39 PST
Just tried, same result. VA decoders work fine in Clapper the video player (Flatpak).
Comment 11 Philippe Normand 2023-02-16 07:04:01 PST
(In reply to kdwkleung from comment #10)
> VA decoders work fine in Clapper the video player
> (Flatpak).

Yeah we know, it's already mentioned in earlier comments, no need to repeat :)

I'll need a GST_DEBUG="*CAPS*:5" log please...
Comment 12 Kdwk 2023-02-16 20:38:15 PST
How do I obtain this log? Thanks
Comment 13 Philippe Normand 2023-02-17 00:45:26 PST
$ flatpak run --filesystem=home --command=/bin/bash org.gnome.Epiphany.Devel
[📦 org.gnome.Epiphany.Devel ~]$ GST_DEBUG="3,webkit*:6" GST_DEBUG_FILE="$HOME/gst.log" GST_DEBUG_NO_COLOR=1 WEBKIT_FORCE_SANDBOX=0 epiphany
Comment 14 Kdwk 2023-02-17 01:16:19 PST
The log file doesn't show up in my home directory after doing these.
Comment 15 Philippe Normand 2023-02-17 01:29:43 PST
Try WEBKIT_DISABLE_SANDBOX_THIS_IS_DANGEROUS=1 instead of WEBKIT_FORCE_SANDBOX?
Comment 16 Kdwk 2023-02-17 01:38:04 PST
Created attachment 465048 [details]
gst.log

The requested log.
Comment 17 Philippe Normand 2023-02-17 01:41:43 PST
Now with GST_DEBUG="3,webkit*:6,*CAPS*:5"
Comment 18 Kdwk 2023-02-17 04:00:57 PST
Created attachment 465051 [details]
gst.log

Requested log file(1)
Comment 19 Philippe Normand 2023-02-17 04:55:13 PST
openh264dec0 is still used instead of the va decoder... Are you sure you set the rank as explained in comment 2 ?

flatpak run --command=gst-inspect-1.0 org.gnome.Epiphany.Devel vah264dec

If the rank shown is still NONE, rm $HOME/.var/app/org.gnome.Epiphany.Devel/cache/gstreamer-1.0/registry.x86_64.bin

and:

flatpak --env="GST_PLUGIN_FEATURE_RANK=vah264dec:MAX,vah265dec:MAX,vavp8dec:MAX,vavp9dec:MAX" run --command=gst-inspect-1.0 org.gnome.Epiphany.Devel vah264dec
Comment 20 Kdwk 2023-02-17 05:01:55 PST
(In reply to Philippe Normand from comment #19)
> openh264dec0 is still used instead of the va decoder... Are you sure you set
> the rank as explained in comment 2 ?

I set it in the org.gnome.Platform//master runtime by running `flatpak run --command=/bin/bash org.gnome.Platform` and then running `GST_PLUGIN_FEATURE_RANK=vah264dec:MAX,vah265dec:MAX,vavp8dec:MAX,vavp9dec:MAX`.

> 
> flatpak run --command=gst-inspect-1.0 org.gnome.Epiphany.Devel vah264dec

Factory Details:
  Rank                     none (0)
  Long-name                VA-API H.264 Decoder
  Klass                    Codec/Decoder/Video/Hardware
  Description              VA-API based H.264 video decoder
  Author                   Víctor Jáquez <vjaquez@igalia.com>

Plugin Details:
  Name                     va
  Description              VA-API codecs plugin
  Filename                 /usr/lib/x86_64-linux-gnu/gstreamer-1.0/libgstva.so
  Version                  1.20.5
  License                  LGPL
  Source module            gst-plugins-bad
  Source release date      2022-12-19
  Binary package           GStreamer Bad Plug-ins source release

> 
> If the rank shown is still NONE, rm
> $HOME/.var/app/org.gnome.Epiphany.Devel/cache/gstreamer-1.0/registry.x86_64.
> bin
> 
> and:
> 
> flatpak
> --env="GST_PLUGIN_FEATURE_RANK=vah264dec:MAX,vah265dec:MAX,vavp8dec:MAX,
> vavp9dec:MAX" run --command=gst-inspect-1.0 org.gnome.Epiphany.Devel
> vah264dec

Factory Details:
  Rank                     primary + 2147483391 (2147483647)
  Long-name                VA-API H.264 Decoder
  Klass                    Codec/Decoder/Video/Hardware
  Description              VA-API based H.264 video decoder
  Author                   Víctor Jáquez <vjaquez@igalia.com>

Plugin Details:
  Name                     va
  Description              VA-API codecs plugin
  Filename                 /usr/lib/x86_64-linux-gnu/gstreamer-1.0/libgstva.so
  Version                  1.20.5
  License                  LGPL
  Source module            gst-plugins-bad
  Source release date      2022-12-19
  Binary package           GStreamer Bad Plug-ins source release
Comment 21 Kdwk 2023-02-17 05:04:24 PST
As of now, the problem persists.
Comment 22 Philippe Normand 2023-02-17 05:08:48 PST
(In reply to kdwkleung from comment #21)
> As of now, the problem persists.

New log please :) I look forward seeing openh264dec not mentioned in that one.
Comment 23 Kdwk 2023-02-17 05:29:54 PST
Created attachment 465053 [details]
gst.log

Requested log file(2)
Comment 24 Philippe Normand 2023-02-17 05:35:12 PST
(In reply to Philippe Normand from comment #22)
> (In reply to kdwkleung from comment #21)
> > As of now, the problem persists.
> 
> New log please :) I look forward seeing openh264dec not mentioned in that
> one.

grep disagrees. Look, I don't know what you're doing exactly, but you're experiencing the bug because this decoder is used, it's not a hardware decoder.
Comment 25 Philippe Normand 2023-02-17 05:40:42 PST
vah264dec is working fine for me in that page loaded from Ephy TP. Closing.
Comment 26 Kdwk 2023-02-17 06:03:14 PST
Unfortunately it appears the env var got reset before Epiphany is opened when set with your method. I got it to persist by setting it in Flatseal.

The gst-inspect-1.0 now consistently reports vah264dec getting max rank.

However, the problem persists. This time I'm able to get a new log file. I promise, I checked with both the Text Editor find tool and grep that the file does not contain a single instance of "openh264dec".
Comment 27 Kdwk 2023-02-17 06:03:52 PST
Created attachment 465054 [details]
gst.log

Requested log file(3)
Comment 28 Kdwk 2023-02-17 06:21:01 PST
Setting WEBKIT_GST_DMABUF_SINK_ENABLED=1 does make CPU usage go down, but the video is basically visually corrupt.
Comment 29 Philippe Normand 2023-02-17 06:25:07 PST
(In reply to kdwkleung from comment #28)
> Setting WEBKIT_GST_DMABUF_SINK_ENABLED=1 does make CPU usage go down, but
> the video is basically visually corrupt.

Thanks, so same behaviour as in bug 251017 :( Let's close this as duplicate because I have no further ideas beyond the issue tracked in bug 251017.

*** This bug has been marked as a duplicate of bug 251017 ***