Aanok / jftui

Jellyfin Terminal User Interface
The Unlicense
142 stars 7 forks source link

High CPU Usage and choppy video #23

Closed hstejas closed 3 years ago

hstejas commented 3 years ago

jftui version jftui 0.5.0, libmpv 1.107, libcurl 7.68.0 OpenSSL/1.1.1f, yajl 20100

Describe the bug Dual core Intel celeron machine (4GB RAM) 2x100% CPU usage and choppy video when playing any 720p video (RAM was not full) same video plays fine on Firefox web interface (2x50% CPU usage) jellyfin version 10.7.1

To Reproduce Just played video, Built as per README, installed curl, mpv and yalj dev packages, run make

Expected behavior CPU usage should not be so high, Video should play fine Is there any logs or something I can enable to debug this? or some tweaks that can be done?

Aanok commented 3 years ago

At a glance it seems more likely to me this would be an mpv issue. So if you don't mind, let's try and look into that first.

From the web GUI, find an affected video, click on the three dots in the bottom right of the thumbnail and click on Copy Stream URL.

Run mpv <the url> in a terminal and see if you get the same issue.

If you do, try and download the video (get the file directly, or through the Download entry from the same menu on the web GUI) and see if playing it in mpv locally still gives you trouble.

hstejas commented 3 years ago

@Aanok I don't see the same issue when I run mpv http://<ip>:<port>/items/<id>/download?api_key=<key>. But seems like mpv is using h/w acceleration when I run it manually, but not with jftui? The GPU is the built in Intel one. I also tried with VLC and it ran fine too (CPU 20-30%)

mpv

CPU Usage (2x40%)

Using hardware decoding (vaapi).
AO: [pulse] 48000Hz stereo 2ch float
VO: [gpu] 1280x720 vaapi[nv12]
AV: 00:01:32 / 00:22:59 (6%) A-V:  0.000 Cache: 187s/61MB

jftui

AO: [pulse] 48000Hz stereo 2ch float
VO: [gpu] 1280x720 yuv420p
AV: 00:00:01 / 00:22:59 (0%) A-V:  0.361 Dropped: 23 Cache: 19s/7MB

Audio/Video desynchronisation detected! Possible reasons include too slow
hardware, temporary CPU spikes, broken drivers, and broken files. Audio
position will not match to the video (see A-V status field).

AV: 00:00:10 / 00:22:59 (0%) A-V:  7.018 Dropped: 164 Cache: 167s/53MB
Aanok commented 3 years ago

Do you have an mpv.conf in ${XDG_CONFIG_HOME:-$HOME/.config}/jftui and is it set up for hardware decoding?

hstejas commented 3 years ago

No i didn't have mpv.conf in ~/.config/jftui there was only a settings file, with some jellyfin details I created ~/.config/jftui/mpv.conf and added

vo=gpu
hwdec=vaapi

Didn't see any difference

This seems similar to my issue though https://github.com/mpv-player/mpv/issues/6722 MPV_RENDER_PARAM_X11_DISPLAY I dont see this in jftui code

hstejas commented 3 years ago

From my understanding of the documentaion here, it seems like hw acceleration is not available unless an opengl context is created and passed to mpv.

Aanok commented 3 years ago

Those notes don't apply to jftui, because it lets mpv handle everything re: video playback just like it was the standalone client. There is no explicit rendering surface.

I tried replicating your issue both on my desktop (AMD CPU+GPU) and on the laptop (ThinkPad x220, i5) but I couldn't; if I setup

vo=gpu
hwdec=vaapi

I get hardware decoding both on standalone mpv and jftui.

Try this: symlink your normal mpv.conf alongside jftui's settings file, so we're sure they're the exact same. jftui plays nice with that.

EDIT - you should also be able to turn on hardware acceleration during playback with the Ctrl+h shortcut, maybe try that too.

hstejas commented 3 years ago

ctrl+h worked when creating the symlink I noticed that I had created an mvp.conf instead of mpv.conf. sorry for the wrong info. And mpv.conf with the above content worked. The default /etc/mpv/mpv.conf just has hwdec=vaapi (Ubuntu 20.04)

Should this be added to the readme/docu?

Aanok commented 3 years ago

All right! I had a hunch this was a configuration problem, because there isn't really anything in jftui that messes with video playback at this level.

Documentation can always be improved, but there is mention of this in the README:

jftui will drop into a command line instance of mpv when starting playback. It will use mpv.conf and input.conf files found in $XDG_CONFIG_HOME/jftui (this location can be overridden with the --config-dir argument). It will also try and load scripts found in the same folder, but no guarantees are made about them actually working correctly.

I've been meaning to reorganize docs and info a bit. Maybe include an Asciinema or something like that. A bit of bling :sparkles: