Using Clapper for hardware-accelerated video playback

Has anyone had success using Clapper for video playback? The flatpak works pretty much out of the box on the Pinephone, but when I download a video with yt-dlp (resulting in a .webm file), run Clapper, and try to open the video file, I get the following error:

(com.github.rafostar.Clapper:2): Clapper-CRITICAL **: 01:35:36.931: Error from element /GstPlayBin:playbin/GstURIDecodeBin:uridecodebin0/GstDecodeBin:decodebin0/v4l2slvp9dec:v4l2slvp9dec0: GStreamer encountered a general resource error.
Could not enable the decoder driver.
../subprojects/gst-plugins-bad/sys/v4l2codecs/gstv4l2codecvp9dec.c(510): gst_v4l2_codec_vp9_dec_negotiate (): /GstPlayBin:playbin/GstURIDecodeBin:uridecodebin0/GstDecodeBin:decodebin0/v4l2slvp9dec:v4l2slvp9dec0:
VIDIOC_STREAMON(SINK) failed: Cannot allocate memory

Of course, compiling mpv with v4l support is always an option (as described in Notes on building ffmpeg and mpv to use the hardware H.264 decoder) but I was hoping this would be a simpler solution.

Edit: Iā€™ve made some progress. I uninstalled the flatpak and built Clapper from source. Not sure if that changed anything, but what may have changed is I installed libgtk-4-media-gstreamer and libgtk-4-bin. Now when I try to open the video file, this is the output:

(com.github.rafostar.Clapper:9173): Clapper-CRITICAL **: 02:42:41.878: Error from element /GstPlayBin3:playbin3/GstURIDecodeBin3:uridecodebin3-0/GstDecodebin3:decodebin3-0/v4l2slvp9dec:v4l2slvp9dec0: No space left on the resource.
Not enough memory to allocate source buffers.
../sys/v4l2codecs/gstv4l2codecvp9dec.c(562): gst_v4l2_codec_vp9_dec_decide_allocation (): /GstPlayBin3:playbin3/GstURIDecodeBin3:uridecodebin3-0/GstDecodebin3:decodebin3-0/v4l2slvp9dec:v4l2slvp9dec0

The video file is pretty big (2.1 GiB) so I tried a smaller one (111 MiB) and playback works just fine with playbin3 enabled. I wonder if thereā€™s a way to get it to play the larger video, but for now this is a start.

Edit 2: Playback works ā€œjust fineā€ 90% of the time, but doing other things like changing the volume while the video is playing will cause artifacts. I was able to get the larger video to play by forcing yt-dlp to download at 1080p instead of the default 4k, bringing the file size down to a much more reasonable ~300 MiB.

Yeah! Iā€™ve had a lot of success with Clapper. I use it almost every night! :slight_smile:

On the newer Debianā€™ised Reform sysimagev3- the flatpak just works for me, without tweaks. Even very high bitrate streams e.g. ~30GB 1080p Bluray remuxes, or 1080p60fps Youtube videos- in both of those cases, CPU decoding simply would not work. Clapper can play those smoothly with hardware accel. Iā€™ve actually had more success than with mpv.

I think one of your issues is vp9? I donā€™t know if the decoder is missing in hardware, or somewhere in the software stack - but Iā€™ve only had success with h264. Instruct yt-dlp to ignore vp9.

Also, not sure if this matters, but make sure your user is in all the relevant looking groups listed in /etc/group? (video, drm, blah blah. I canā€™t check right now as I donā€™t have access to my Reform)

Just checked: only group ā€˜videoā€™ should matter if at all

You guys do know that Clapper Flatpak can stream youtube videos without the need of using yt-dlp to download them earlier, right?

1 Like

Huh just tried it- thatā€™s pretty cool. It switched to 1080p, ignored vp9, and used accel. Excellent!

Soon you will not need the flatpak anymore because I packaged clapper for Debian and uploaded it to unstable. Itā€™s currently waiting in the NEW queue for ftp-master review: clapper - Debian NEW package overview

To allow for hardware acceleration on the reform you need to have the environment variable GST_CLAPPER_USE_PLAYBIN3=1 set which will use gstreamer playbin3 instead of playbin. This will happen automatically if this gets merged: etc/profile.d/reform.sh: enable harware acceleration in clapper (!18) Ā· Merge requests Ā· Reform / MNT Reform Tools Ā· GitLab

The flatpak contains some custom-built gstreamer but it turns out the version shipped by Debian is sufficient, given you have above environment variable set. Thanks to @flowy for finding the variable in the docs: Hardware acceleration Ā· Rafostar/clapper Wiki Ā· GitHub

2 Likes

Interesting, streaming only works with the Flatpak for me. Looks like a much better option than messing with yt-dlp parameters.

Looking forward to @joschā€™s packaged version!

Yes, I think streaming is in Flatpak only for some reason. Wonā€™t GST_CLAPPER_USE_PLAYBIN3=1 negatively impact Flatpak where this option is unnecessary? It is marked as experimental feature in settings after all.

IDK, but there seem to be a Clapper matrix chat channel. Maybe somebody can go and ask the dev?

Meh. Hardware accel on our systems wonā€™t work without it. So I donā€™t care if itā€™s experimental or not- I need hardware accel. If I could use CPU decoding all the time I would, but thatā€™s not possible for most of the (higher bitrate) streams I play.

No. Flatpak ver is supposed to work without it. Thats what linked above clapper wiki says.

Yes, by setting that environment variable we avoid having to build our own gstreamer version as well. There is nothing really stopping is from building our own gstreamer other than having the available person-power to maintain our custom gstreamer build. If there is anybody willing to maintain it, then I can help to make this happen and then we donā€™t need to use that environment variable.

Starting today you can now just sudo apt install clapper to install it: clapper - Debian Package Tracker

With a recent enough reform-tools version you get hardware acceleration that way without Flatpak. If your reform-tools version is too old, set the GST_CLAPPER_USE_PLAYBIN3=1 environment variable for clapper.

5 Likes

Is URI opening supported on the packaged version of Clapper? I havenā€™t been able to get it to work. When I try to open a URL I get the following error printed if running Clapper from a terminal:

(com.github.rafostar.Clapper:4697): Clapper-CRITICAL **: 20:51:19.129: Error from element /GstPlayBin3:playbin3/GstURIDecodeBin3:uridecodebin3-0/GstURISourceBin:urisourcebin0/GstSoupHTTPSrc:souphttpsrc0: GStreamer encountered a general stream error.
Internal data stream error.
../libs/gst/base/gstbasesrc.c(3127): gst_base_src_loop (): /GstPlayBin3:playbin3/GstURIDecodeBin3:uridecodebin3-0/GstURISourceBin:urisourcebin0/GstSoupHTTPSrc:souphttpsrc0:
streaming stopped, reason not-linked (-1)

This happens both with and without using GST_CLAPPER_USE_PLAYBIN3=1.

URI opening from video streaming services like youtube, twitch, etc. only works in Flatpak unfortunately.

Iā€™m curious as to why that is? The bug still seems to be present even now as Iā€™m getting the exact same error as @Jt0 was with an up to date system and the latest clapper package still in Jan 2023.

Is this a gstreamer issue thatā€™s patched over in the flatpak? Or an issue with clapper itself?

1 Like