Upgraded OS and MythTV and VAAPI Hardware Acceleration Playback Does Not Work Reliably/Erratic?

Have a MythTV related problem? Ask for help from other MythTV users here.

Moderator: Forum Moderators

Post Reply
mtvf2894
Junior
Posts: 81
Joined: Sat Apr 10, 2021 2:33 pm
Great Britain

Upgraded OS and MythTV and VAAPI Hardware Acceleration Playback Does Not Work Reliably/Erratic?

Post by mtvf2894 »

VAAPI was working (reasonably) well in Ubuntu 20.10 and v31 but ever since moving up to 22.04 (new install) and v32 VAAPI has been very erratic sometimes working but very often failing.

I know when it has failed as playback takes much longer to start and it falls back to CPU playback.

Have even tried the Use Ffmpeg Original Mpegts Demuxer setting (even though the problem is not limited to mpeg TS files) and it doesn't help.

vainfo at the bash prompt always outputs what is expected and seems to match System Status - Video Decoders in the frontend.

There seems to be no pattern, sometimes it works fine then it seems to stop working every couple of hours.

Is there anything I am missing or can try to get it to make it work better with hardware accelerated playback?

The frontend logs are full of entries like the following repeated 50 times before CPU playback is used (probably why it takes longer to start the recording).

Code: Select all

mythfrontend.real: mythfrontend[2997]: I Decoder mythplayervideoui.cpp:143 (HandleDecoderCallback) PlayerVideo: Queuing callback for VAAPI context creation
mythfrontend.real: mythfrontend[2997]: I CoreContext mythplayervideoui.cpp:159 (ProcessCallbacks) PlayerVideo: Executing VAAPI context creation
mythfrontend.real: mythfrontend[2997]: I CoreContext opengl/mythvaapiinterop.cpp:140 (InitaliseDisplay) VAAPIInterop: Created VAAPI 1.14 display for GL-VAAPI-DRM (Mesa Gallium driver 22.0.1 for AMD RENOIR (LLVM 13.0.1, DRM 3.42, 5.15.0-41-generic))
mythfrontend.real: mythfrontend[2997]: E CoreContext decoders/mythvaapicontext.cpp:346 (InitialiseContext) VAAPIDec: Failed to initialise VAAPI frames context
mythfrontend.real: mythfrontend[2997]: E Decoder decoders/avformatdecoder.cpp:3474 (ProcessVideoPacket) AFD: video avcodec_send_packet error: Invalid argument (-22) gotpicture:0
Thanks
Current: v32 now v33.1 / Lubuntu 22.04 / AMD APU
Previous: v31 / Lubuntu 20.10 / AMD APU
Historic: Mythbuntu / NVIDIA GFX
mtvf2894
Junior
Posts: 81
Joined: Sat Apr 10, 2021 2:33 pm
Great Britain

Re: Upgraded OS and MythTV and VAAPI Hardware Acceleration Playback Does Not Work Reliably/Erratic?

Post by mtvf2894 »

Quick update I have found that if I keep trying to replay the same recording it will eventually work.

If one particular file is being difficult trying to playback a different recording in a different format (e.g. hd-264 vs sd-mpg2) will work and then going back to the difficult file this will then work fine. Very strange.

Playback will either fail and completely crash the frontend or the frontend will play the file but using the CPU instead of hardware acceleration.

Will the possible ffmpeg sync in the upcoming v33 release possibly help with this problem?

Thanks
Current: v32 now v33.1 / Lubuntu 22.04 / AMD APU
Previous: v31 / Lubuntu 20.10 / AMD APU
Historic: Mythbuntu / NVIDIA GFX
mtvf2894
Junior
Posts: 81
Joined: Sat Apr 10, 2021 2:33 pm
Great Britain

Re: Upgraded OS and MythTV and VAAPI Hardware Acceleration Playback Does Not Work Reliably/Erratic?

Post by mtvf2894 »

Noticed the "FFmpeg to version 5.1" pull request appeared a couple of days ago
https://github.com/MythTV/mythtv/pull/627
This is a large pull request I think so whether it will make it to v33 cross fingers.

Not 100% convinced it will help as even though I upgraded the OS I think something probably changed between MythTV v31 and v32 which made hardware acceleration not work as well as it did. Even then it was not perfect for my AMD APU as hardware accelerated deinterlacers did not work or at least they were not reported as being used in the Playback Data OSD amongst other minorish things.
Current: v32 now v33.1 / Lubuntu 22.04 / AMD APU
Previous: v31 / Lubuntu 20.10 / AMD APU
Historic: Mythbuntu / NVIDIA GFX
ljpage
Newcomer
Posts: 13
Joined: Wed Jan 27, 2016 4:28 pm
Channel Islands

Re: Upgraded OS and MythTV and VAAPI Hardware Acceleration Playback Does Not Work Reliably/Erratic?

Post by ljpage »

I am running the stock Ubuntu 22.04 install of mythfrontend on Intel and AMD hardware. The VAAPI (on Intel) is stuttery when starting live TV.

I upgraded from Ubuntu 18.04 and Mythtv 29 (which was working perfectly smoothly using VAAPI and VDPAU decoders and deinterlacers). In v29 there were two options for audio sync. The "new" method never seemed to settle down with the frame rate varying wildly causing severe eye strain. This "new" method seems to be the only one available in v32. I (think I) have eased the stuttering by increasing the audio buffer size under Setup->Video->Advanced Playback.

As regards VAAPI on AMD processors, I would have expected to use VDPAU with AMD/Radion and in fact when I built the fixes/32 version from source I had to configure it to not include VAAPI on my AMD laptop otherwise mythfrontend crashed on startup. Despite this I do not seem to be able to make use of VDPAU as whatever settings I try I get ffmpeg/GL decoding/deinterlacing (though this does work quite well).
mtvf2894
Junior
Posts: 81
Joined: Sat Apr 10, 2021 2:33 pm
Great Britain

Re: Upgraded OS and MythTV and VAAPI Hardware Acceleration Playback Does Not Work Reliably/Erratic?

Post by mtvf2894 »

Unfortunately after upgrading to v33.1 I still have to battle to get MythTV Frontend to work with VAAPI/Hardware Playback Acceleration.

I play a recording, the frontend crashes*, I reopen the frontend, play the recording and repeat this process with no other changes and it will eventually succeed and playback using VAAPI/Hardware Playback Acceleration. Once it plays one recording successfully with VAAPI/Hardware Playback Acceleration all future playbacks work with VAAPI/Hardware acceleration no problems whatsoever until you reboot. Then you just repeat the process to get it playing back correctly again.

It is all very strange. To make things stranger on rare occasions it sometimes doesn't crash the frontend it will fall back to just FFMPEG playback.
Current: v32 now v33.1 / Lubuntu 22.04 / AMD APU
Previous: v31 / Lubuntu 20.10 / AMD APU
Historic: Mythbuntu / NVIDIA GFX
blm-ubunet
Senior
Posts: 265
Joined: Sun Jun 15, 2014 1:08 am
Cambodia

Re: Upgraded OS and MythTV and VAAPI Hardware Acceleration Playback Does Not Work Reliably/Erratic?

Post by blm-ubunet »

I believe it should fail back to ffmpeg & the crash is the erronous behaviour.
Seems like it is not initializing things correctly for VAAPI.
I doubt the ffmpeg version in mythtv will make any difference.

Between 31 & 32 all video decoding was re-structured (render branch) but that developer left project just before all problems were fixed.
https://www.mythtv.org/wiki/2019-render
I found picture quality with VDPAU went downhill so I compile a specific version (& disable python bindings)..

VAAPI requires openGL painter & there is recommendation to use this:
export QT_XCB_GL_INTEGRATION="xcb_egl"

Else you could compile from source & checkout an old release or install v31.
Problem is the database schema changes & likely break python bindings.

May be possible to call an external player like MPV, I've been considering that as best solution.
mtvf2894
Junior
Posts: 81
Joined: Sat Apr 10, 2021 2:33 pm
Great Britain

Re: Upgraded OS and MythTV and VAAPI Hardware Acceleration Playback Does Not Work Reliably/Erratic?

Post by mtvf2894 »

Thanks for suggestions.

I have tried adding export QT_XCB_GL_INTEGRATION="xcb_egl" to my .profile but it hasn't helped. Is there a better place as I am not sure if this is the correct place - not even sure this will be picked up by the time mythfrontend.real is executed? Not sure if this type of setting should be in xorg.conf though.

Yes v32 / 22.04 is when the problems started. I think you posted suggestions in viewtopic.php?f=36&t=5036 where I also mentioned the problem.

What is weird is the logic they say doing the same thing again and again and expecting different results is stupid but in this case it works! It is hard to "blame" MythTV but equally as hard to "blame" the OS/drivers.

The fact that is does crash the frontend I seem to think something is not quite correct in MythTV as it should fallback and not crash the frontend.

I have just rebooted several times to see if the "export" helped. Three times in a row it worked fine. Forth time playback crashes the frontend. Immediately reloaded frontend it then worked fine. Equally after a reboot it may immediately not work and it takes four or five reloads of the frontend but it does eventually sort itself out.

It is an annoyance but if the hardware playback doesn't work I just keep restarting until it does. Once it has worked once it continues to work faultlessly until the machine needs to be rebooted or the frontend is exited.
Current: v32 now v33.1 / Lubuntu 22.04 / AMD APU
Previous: v31 / Lubuntu 20.10 / AMD APU
Historic: Mythbuntu / NVIDIA GFX
blm-ubunet
Senior
Posts: 265
Joined: Sun Jun 15, 2014 1:08 am
Cambodia

Re: Upgraded OS and MythTV and VAAPI Hardware Acceleration Playback Does Not Work Reliably/Erratic?

Post by blm-ubunet »

I have vague recollection that VAAPI needed to know some server like namespace.. and at one point the user had to enter the name..

I would think the export env var in .profile will only apply to process spawned by the that user.
So I guess it depends on how you launch FE..
I use MythWelcome run as "user" (not mythtv).
But I believe there is a global all-users profile conf file.

To be sure, I would launch frontend directly in shell & not that silly ubuntu wrapper script.

And a warm restart reboot may not be equivalent to cold start.
There are no coincidences just seemly inexplicable observations/patterns until one day they're not.

And as was mentioned above, VDPAU is supposed to be an option on some AMD hardware.
There is a required package mesa-vdpau-drivers for VDPAU on AMD.

Another option is generic VDPAU (for mythtv to use) with openGL & VAAPI backend:
libvdpau-va-gl
this would let something else handle VAAPI init/setup.
Last edited by blm-ubunet on Thu Apr 06, 2023 10:09 pm, edited 1 time in total.
User avatar
kmdewaal
Developer
Posts: 640
Joined: Wed Dec 07, 2016 8:01 pm
Netherlands

Re: Upgraded OS and MythTV and VAAPI Hardware Acceleration Playback Does Not Work Reliably/Erratic?

Post by kmdewaal »

First question, does your vaapi playback work correct with vlc or mpv? Try playback with these two with vaapi enabled/selected. You may need to give explicit command line options to select the use of vaapi.
If vlc and mpv do always play correct it might be feasible to do a bit of reverse-engineering on the way that vlc, mpv and mythtv do initialize video playback with vaapi.
Please create a github issue for this on https://github.com/MythTV/mythtv/issues.
This does not guarantee it will get fixed but it helps to capture everything about this issue in a place where it can be found again.
It would also help if you can create a backtrace of crash and attach that to the issue.
For this you can start mythfrontend from gdb, and when it has crashed capture the output of "thread apply all bt full" which gives a backtrace of all threads.
mtvf2894
Junior
Posts: 81
Joined: Sat Apr 10, 2021 2:33 pm
Great Britain

Re: Upgraded OS and MythTV and VAAPI Hardware Acceleration Playback Does Not Work Reliably/Erratic?

Post by mtvf2894 »

kmdewaal wrote:
Thu Apr 06, 2023 5:10 pm
First question, does your vaapi playback work correct with vlc or mpv?
For this you can start mythfrontend from gdb, and when it has crashed capture the output of "thread apply all bt full" which gives a backtrace of all threads.
Thanks I have seen this and will be researching further with both VLC and gdb and report the results.
Current: v32 now v33.1 / Lubuntu 22.04 / AMD APU
Previous: v31 / Lubuntu 20.10 / AMD APU
Historic: Mythbuntu / NVIDIA GFX
Post Reply