woodruffw / ff2mpv

A Firefox/Chrome add-on for playing URLs in mpv.

Home Page:https://addons.mozilla.org/en-US/firefox/addon/ff2mpv/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

stderr output from native app ff2mpv: libswresample: 4.10.100 -> 4.7.100

Melechtna opened this issue · comments

Describe the bug

I'm given this error when trying to use the extension, but mpv and yt-dlp works in the terminal just fine.

Reproduction steps

Steps to reproduce the behavior:

  1. Find a video
  2. right click
  3. select 'Play with MPV(W)'
  4. See error in console

Expected behavior

It to just launch in MPV as usual

Platform information

  • OS information: NixOS Unstable
  • Firefox version:119
  • MPV version: 0.36.0
  • youtube-dl version: stable@2023.10.13 [b634ba742] (pip)

Thanks for the report. Can you send an example URL that fails to play?

I strongly suspect that this is a distribution level problem (I don't know much about NixOS, but I know they do weird things to paths that Firefox native messaging extensions may depend on).

Another possible candidate: https://bbs.archlinux.org/viewtopic.php?id=287741

Thanks for the report. Can you send an example URL that fails to play?

I strongly suspect that this is a distribution level problem (I don't know much about NixOS, but I know they do weird things to paths that Firefox native messaging extensions may depend on).

Another possible candidate: https://bbs.archlinux.org/viewtopic.php?id=287741

All of them fail to play, but specifically through the extension, MPV itself works just fine, as does yt-dlp. Doesn't matter if it's from Youtube, Odysee, or PornHub. I don't entirely see how the forum post you linked to is related.

I don't entirely see how the forum post you linked to is related.

I didn't go through it fully, it's just another recent example of someone having issues with MPV with a similar stderr readout.

Can you share a bit more about your host? What's your $PATH (redacted if necessary), and does the behavior change if you spawn Firefox from an interactive shell versus from a desktop launcher?

$PATH: /home/user/.local/bin:/home/user/bin:/run/wrappers/bin:/home/user/.local/share/flatpak/exports/bin:/var/lib/flatpak/exports/bin:/home/user/.nix-profile/bin:/nix/profile/bin:/home/user/.local/state/nix/profile/bin:/etc/profiles/per-user/user/bin:/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin

No, it behaves the same in a terminal or through the default launcher. I can provide my nix config if that might help, but if you don't understand them, this may not help. I HAD been installing your script through this https://github.com/NixOS/nixpkgs/blob/nixos-unstable/pkgs/applications/misc/ff2mpv/default.nix#L29 but it didn't seem to work at all using it, and just running the install.sh worked fine until recently.

Got it. I'm a bit stumped then: some users have previously reported problems where yt-dlp or youtube-dl wasn't on the $PATH that Firefox was spawned with, but that doesn't seem to be the issue here.

Does anything stand out in your system logs? The only other thing I can think of is some sandboxing change that kills native extensions (this has been a problem for Fedora users I believe, not sure if it applies to NixOS).

I can provide my nix config if that might help, but if you don't understand them, this may not help.

Others might have the same issue, so IMO it's worth pasting here for indexing purposes.

Got it. I'm a bit stumped then: some users have previously reported problems where yt-dlp or youtube-dl wasn't on the $PATH that Firefox was spawned with, but that doesn't seem to be the issue here.

Does anything stand out in your system logs? The only other thing I can think of is some sandboxing change that kills native extensions (this has been a problem for Fedora users I believe, not sure if it applies to NixOS).

I can provide my nix config if that might help, but if you don't understand them, this may not help.

Others might have the same issue, so IMO it's worth pasting here for indexing purposes.

NixOS doesn't necessarily sandbox, it wraps, which isn't quite the same concept, and again, it was working until recently.

As for my config, here it is minus a few things that aren't relevant/sensitive

https://pastebin.com/fAYv2GXK

NixOS doesn't necessarily sandbox, it wraps, which isn't quite the same concept, and again, it was working until recently.

Got it. The Fedora implementation is built on AppArmor (I think), so if Nix doesn't use that then it isn't relevant.

If it was working until recently and the extension itself hasn't changed (which it shouldn't have, since I haven't made any releases in a while), then I'm inclined to go back to the original theory and say that this is something environmental or otherwise unique to a recent change in NixOS (it isn't affecting me on Ubuntu LTS). But we'll leave this open and see.

NixOS doesn't necessarily sandbox, it wraps, which isn't quite the same concept, and again, it was working until recently.

Got it. The Fedora implementation is built on AppArmor (I think), so if Nix doesn't use that then it isn't relevant.

If it was working until recently and the extension itself hasn't changed (which it shouldn't have, since I haven't made any releases in a while), then I'm inclined to go back to the original theory and say that this is something environmental or otherwise unique to a recent change in NixOS (it isn't affecting me on Ubuntu LTS). But we'll leave this open and see.

Given the error looks like a library conflict with libswresample, probably you aren't seeing the error because Ubuntu is perpetually WAY out of date just to be annoying. I wish it were easier to get a more detailed error report from Firefox, but that's all it gives me in its console when I try to run the extension, and I'd have to go through the arduous task of getting a dev build setup to get anything in an actual terminal since -g doesn't seem to want to work when launching it, even though gdb works just fine on the system. Guess I could just launch it through gdb directly, give me a few.

And now my head just hurts, running it in gdb, it functioned without issue.

Edit: Okay, there's something extra fucky going on. If you run it from the .firefox-wrapped executable, rather than the firefox shortcut, it magically just works, but I don't even have the slightest clue how that even makes sense.

Edit2: to clarify, most applications have a simple link, I.E. type firefox in the console to launch it, that links to the actual executable, which in this case is .firefox-wrapped. The link breaks it, the proper executable makes it function fine, and given it's a simple soft link, that doesn't even make sense.

And now my head just hurts, running it in gdb, it functioned without issue.

Edit: Okay, there's something extra fucky going on. If you run it from the .firefox-wrapped executable, rather than the firefox shortcut, it magically just works, but I don't even have the slightest clue how that even makes sense.

Edit2: to clarify, most applications have a simple link, I.E. type firefox in the console to launch it, that links to the actual executable, which in this case is .firefox-wrapped. The link breaks it, the proper executable makes it function fine, and given it's a simple soft link, that doesn't even make sense.

Thanks for your discovery! Based on this I found that the issue comes from the firefox wrapper adding ffmpeg libs to LD_LIBRARY_PATH, whose version is different from that of mpv's ffmpeg.

First of all, realpath $(which firefox) is a symlink that points to a shell script, which adds tons of libraries to LD_LIBRARY_PATH, including ffmpeg:

$ cat $(realpath $(which firefox)) | grep ffmpeg
LD_LIBRARY_PATH=${LD_LIBRARY_PATH/':''/nix/store/b1c4w2g6lrmwadx7gz2g0vaznbb6dha1-ffmpeg-5.1.3-lib/lib64'':'/':'}
LD_LIBRARY_PATH='/nix/store/b1c4w2g6lrmwadx7gz2g0vaznbb6dha1-ffmpeg-5.1.3-lib/lib64'$LD_LIBRARY_PATH
LD_LIBRARY_PATH=${LD_LIBRARY_PATH/':''/nix/store/b1c4w2g6lrmwadx7gz2g0vaznbb6dha1-ffmpeg-5.1.3-lib/lib'':'/':'}
LD_LIBRARY_PATH='/nix/store/b1c4w2g6lrmwadx7gz2g0vaznbb6dha1-ffmpeg-5.1.3-lib/lib'$LD_LIBRARY_PATH

Then I bisected the libraries and located ffmpeg. That makes sense since libswresample is part of ffmpeg.

As for the workaround, I haven't used this extension so I can't provide a detailed solution. I was trying to launch mpv through uri scheme from firefox when I encountered this problem.

Update: Here is my workaround, which overwrites LD_LIBRARY_PATH in the desktop entry script.

Thanks for your discovery! Based on this I found that the issue comes from the firefox wrapper adding ffmpeg libs to LD_LIBRARY_PATH, whose version is different from that of mpv's ffmpeg.

Wow, what a mess. Thank you for debugging this @tianze0926!

Note: another option specifically for ff2mpv here is probably to unset LD_LIBRARY_PATH, since we shouldn't need any of Firefox's specific overrides anyways.

I'm folding #98 into this, see #98 (comment) for context.

Based on this I found that the issue comes from the firefox wrapper adding ffmpeg libs to LD_LIBRARY_PATH, whose version is different from that of mpv's ffmpeg.

I've unpinned the ffmpeg used by mpv in NixOS/nixpkgs#265069. Now they should use the same ffmpeg (ffmpeg_6). Can you confirm if the workaround is still necessary?

BTW, there is no need to run install.sh on NixOS. Just do this:

programs.firefox = {
    enable = true;
    nativeMessagingHosts.packages = [ pkgs.ff2mpv ];
}