MichaIng / DietPi

Lightweight justice for your single-board computer!
https://dietpi.com/
GNU General Public License v2.0
4.81k stars 494 forks source link

DietPi-Software | Jellyfin: Included FFmpeg fails on RPi Bullseye #4821

Closed alpgul closed 2 years ago

alpgul commented 2 years ago

Creating a bug report/issue

Required Information

Additional Information (if applicable)

Steps to reproduce

  1. I downloaded diet pi and made all its updates.
  2. I downloaded jellyfin with dietpi-software.
  3. I got libmmal_core.so error.
  4. I installed ffmpeg with dietpi-software. and I defined ffmpeg folder(/usr/bin/ffmpeg) in jellyfin. I solved libmmal_core.so error.
  5. Jellyfin was very slow. I activated the omx setting in jellyfin playback.
  6. Now i am getting this error[h264_omx @ 0x2f93200] libOMX_Core.so not found [h264_omx @ 0x2f93200] libOmxCore.so not found. Why am I constantly dealing with errors? Is the installation wrong from the beginning?

Expected behaviour

Actual behaviour

Extra details

MichaIng commented 2 years ago

Basically the Jellyfin FFmpeg package needs to be rebuild onto current RPi Bullseye, as there were quite some breaking changes recently, including the libmmal_core.so problem, and the pretty related libOMX_Core.so one. I reported it upstream already: https://github.com/jellyfin/jellyfin-ffmpeg/issues/75

alpgul commented 2 years ago

@MichaIng What I understand is ffmpeg in Jellyfin is old version.I installed the updated version of ffmpeg so it doesn't work well. Can I delete the updated ffmpeg and make it work with the old ffmpeg in jellyfin? or can I manually install and run the old version of ffmpeg that should run Jellyfin? Also, if the application has errors, shouldn't you remove the software from the dietpi-software list?

Joulinar commented 2 years ago

Basically source of the issue is a package from Raspbian repository changing location/name of some important libraries. Now, this would need to respect by Jellyfin FFmpeg package. Means going to a different version of Jellyfin FFmpeg package will not change anything I guess.

Could you share following pls.

ls -la /usr/lib/arm-linux-gnueabihf |grep libOmxCore

alpgul commented 2 years ago

I ran ls -la /usr/lib/arm-linux-gnueabihf |grep libOmxCore . It resulted empty line. I installed ffmpeg with dietpi-software.

MichaIng commented 2 years ago

Quite some of those libraries have gone with latest RPi userland packages. So yes I think installing the dedicated FFmpeg package and configuring Jellyfin to use this is currently the way to go.

legends2k commented 2 years ago

@MichaIng Just FYI. Despite installing ffmpeg directly and setting it in Jellyfin over jellyfin-ffmpeg, I still see libOmxCore.so missing error.

MichaIng commented 2 years ago

Could you try to really purge jellyfin-ffmpeg:

apt purge jellyfin-ffmpeg
barukh27 commented 2 years ago

Manage to solve it in my case. Thanks!

I've run: apt purge jellyfin-ffmpeg Then install ffmpeg

And in the Jellyfin options for ffmpeg select the route: /usr/share/ffmpeg

MichaIng commented 2 years ago

Great, many thanks for the feedback 👍.

toast003 commented 2 years ago

Manage to solve it in my case. Thanks!

I've run: apt purge jellyfin-ffmpeg Then install ffmpeg

And in the Jellyfin options for ffmpeg select the route: /usr/share/ffmpeg

I tried purging jellyfin-ffmpeg, but when I do that apt wants to uninstall jellyfin with it

MichaIng commented 2 years ago

You are right, the latest release v10.7.7 meta package now depends on jellyfin-ffmpeg as well 🤔. That wasn't the case earlier. However, it should also be possible to only install ffmpeg and switch the setting. Else, actually jellyfin is just a meta package, so what you could do:

apt-mark manual jellyfin-server jellyfin-web
apt purge jellyfin-ffmpeg
apt install ffmpeg

This way the server and web component stays installed, the meta package gets removed together with jellyfin-ffmpeg, but it doesn't matter then.

toast003 commented 2 years ago

Thanks! Although what you said did work, ffmpeg is still complaining about two libraries that have almost the same name (libOMX_Core.so and libOmxCore.so) :thinking: Also don't think it's important, but I did upgrade dietpi from the 32bit buster image to bullseye, and transcoding did work before the update

MichaIng commented 2 years ago

This library is indeed not part of libraspberrypi0 on Bullseye anymore. Actually I even cannot find it on recent Buster versions of libraspberrypi0 as it (OpenMAX) generally seems to be deprecated: https://github.com/raspberrypi/firmware/issues/1366

Does the errors show up as well when you call the ffmpeg CLI? Probably it is Jellyfin itself which is still build against obsolete library and not (only) the FFmpeg implementation.


Ah now it makes sense, since Jellyfin has the OMX setting, so then it looks explicitly for those libraries of course, which are not available anymore. And I was blind, it is available on the latest libraspberrypi0 on Buster, but not on Bullseye and not on the 64-bit version of this package. So basically OpenMAX is deprecated and not shipped with current RPi firmware/userland anymore, so Jellyfin would need to hide the OMX setting, or add a hint to avoid confusion, when those libraries are missing, or remove it for the Bullseye and 64-bit builds of Jellyfin: https://beta.raspberrypi.org/forums/viewtopic.php?t=281884

But without OpenMAX, performance seems to be worse. MMAL seems to be used then, or h264_v4l2m2m: https://www.willusher.io/general/2020/11/15/hw-accel-encoding-rpi4

There are some firmware components by default disabled on Raspberry Pi/DietPi, basically the camera module components which provide h264 decoding as well, so it could be tried to enable it via dietpi-config > Display Options > RPi Camera (reboot required). This loads the additional firmware components and removes the related kernel modules from the blacklist.


Another related link: https://raspberrypi.stackexchange.com/questions/108613 So sounds like V4L2 seems to be the way to go and looks like being natively supported by FFmpeg, actually, and on RPi at least when enabling the extended firmware (RPi camera option).

toast003 commented 2 years ago

Tried using ffmpeg with h264_v4l2m2m after enabling the camera, and now it says that it can't find a valid device, even if there there are more modules loaded and there are things on /dev/v4l Edit: running ffmpeg as sudo works, although I'm not sure why...

MichaIng commented 2 years ago

Another related topic on the RPi forum: https://forums.raspberrypi.com/viewtopic.php?t=316381

Have you enabled KMS?

/boot/dietpi/func/dietpi-set_hardware rpi-opengl vc4-kms-v3d

Through when it says that it doesn't find a valid device, it sounds like it tries to encode instead of decode 🤔. Something like this may work:

ffplay -codec:v h264_v4l2m2m file.mkv
toast003 commented 2 years ago

I don't have a display connected to the Pi, so I don't think kms would do anything, and I figured out that ffmpeg didn't find a valid device because my user wasn't on the video group. I have added both my user and the jellyfin user to the video group, and it works now!

MichaIng commented 2 years ago

Ah, makes sense, of course also that KMS is irrelevant for playback at the client 😉. The jellyfin user should have been added to the video group on install.

How is CPU load on the RPi when playing a high resolution h264 video?

toast003 commented 2 years ago

Tried playing a video on jellyfin now and while it doesn't work, it does find a valid device, so that's something ¯_(ツ)_/¯

Here's the end of jellyfin's transcode log:

Stream mapping:
  Stream #0:0 -> #0:0 (hevc (native) -> h264 (h264_v4l2m2m))
  Stream #0:1 -> #0:1 (flac (native) -> aac (native))
Press [q] to stop, [?] for help
[h264_v4l2m2m @ 0x191a110] Using device /dev/video11
[h264_v4l2m2m @ 0x191a110] driver 'bcm2835-codec' on card 'bcm2835-codec-encode' in mplane mode
[h264_v4l2m2m @ 0x191a110] requesting formats: output=YU12 capture=H264
[h264_v4l2m2m @ 0x191a110] Encoder requires yuv420p pixel format.
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
[aac @ 0x12885b0] Qavg: 65536.000
[aac @ 0x12885b0] 2 frames left in the queue on closing
Conversion failed!
MichaIng commented 2 years ago

Probably Jellyfin is generating invalid command arguments for this decoder: https://github.com/jellyfin/jellyfin/issues/1901 Is the full command shown in the logs?

toast003 commented 2 years ago
 /usr/bin/ffmpeg -i file:"/mnt/dietpi_userdata/Video/Anime/Weathering With You (2019)/Weathering With You.mkv" -map_metadata -1 -map_chapters -1 -threads 0 -map 0:0 -map 0:1 -map -0:s -codec:v:0 h264_v4l2m2m -pix_fmt nv21 -b:v 20511800 -maxrate 20511800 -bufsize 41023600 -level 41  -force_key_frames:0 "expr:gte(t,0+n_forced*3)" -g:v:0 72 -keyint_min:v:0 72 -sc_threshold:v:0 0 -vf "scale=trunc(min(max(iw\,ih*dar)\,min(1920\,1080*dar))/64)*64:trunc(min(max(iw/dar\,ih)\,min(1920/dar\,1080))/2)*2" -start_at_zero -vsync -1 -codec:a:0 aac -ac 6 -ab 640000 -copyts -avoid_negative_ts disabled -max_muxing_queue_size 2048 -f hls -max_delay 5000000 -hls_time 3 -hls_segment_type mpegts -start_number 0 -hls_segment_filename "/mnt/dietpi_userdata/jellyfin/transcodes/b7ea751daa3ef150bf435565680c2269%d.ts" -hls_playlist_type vod -hls_list_size 0 -y "/mnt/dietpi_userdata/jellyfin/transcodes/b7ea751daa3ef150bf435565680c2269.m3u8"
MichaIng commented 2 years ago

And I guess that command fails the same way on the console, so one of the arguments is invalid in this combination.

toast003 commented 2 years ago

Yup, although I don't think one of the arguments is invalid since the command ffmpeg -i "Weathering With You.mkv" -c:v h264_v4l2m2m test.mkv fails in the exact same way

MichaIng commented 2 years ago

That would encode the video stream as h264 (if this is what you wanted?). ffmpeg -c:v h264_v4l2m2m -i "Weathering With You.mkv" test.mkv would decode a h264 video stream, as far as I understand the man page: https://manpages.debian.org/ffmpeg

toast003 commented 2 years ago

What I wanted to do is use something that uses h264_v4l2m2m to see if it worked or not, but yeah, I need to encode to h264 since firefox can't direct play videos encoded with h265

MichaIng commented 2 years ago

Does it work when specifying the decoder explicitly as well?

ffmpeg -c:v hevc_v4l2m2m -i 'Weathering With You.mkv' -c:v h264_v4l2m2m test.mkv
toast003 commented 2 years ago

No, it fails with "could not find a valid device" again :thinking:

     mimetype        : application/x-truetype-font
[hevc_v4l2m2m @ 0x203b6d0] level=-99
[hevc_v4l2m2m @ 0x203b6d0] Could not find a valid device
[hevc_v4l2m2m @ 0x203b6d0] can't configure decoder
Stream mapping:
  Stream #0:0 -> #0:0 (hevc (hevc_v4l2m2m) -> h264 (h264_v4l2m2m))
  Stream #0:1 -> #0:1 (flac (native) -> vorbis (libvorbis))
  Stream #0:3 -> #0:2 (ass (ssa) -> ass (ssa))
Error while opening decoder for input stream #0:0 : Invalid argument
MichaIng commented 2 years ago

I think this is something to better continue on the Raspberry Pi forum: https://forums.raspberrypi.com/viewforum.php?f=38 It's the ffmpeg and libraspberrypi0 packages for Bullseye (so no OpenMAX support) from archive.raspberrypi.org, so generally it's supposed to work. But I'm also no V/A/FFmpeg specialist, so not sure what may be missing or which flags/options may be required.

MichaIng commented 2 years ago

I'll mark this as closed. The original library errors has been worked around the the decoder issue is something that needs to be discussed at the RPi forum.