NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.91k stars 13.95k forks source link

Package request: vivaldi-ffmpeg-codecs on aarch64 #304751

Open vxld100 opened 6 months ago

vxld100 commented 6 months ago

Project description

The vivaldi browser is packaged for aarch64, but the proprietary video codecs are unfortunately only available on x86_64. This makes the browser very limited. Having them also available on the aarch64 side of linux would make the browser viable on this platform too.

Tag Maintainers:

@betaboon @cawilliamson @FPtje


Add a :+1: reaction to issues you find important.

betaboon commented 6 months ago

I'm actually not using vivaldi anymore, thus i can't really help.

FPtje commented 6 months ago

Thanks for the request. The awkward part of this package is that it is taken from IIRC this snap. That snap is only available for AMD64 and i386. As noted in my last PR that updates the package (https://github.com/NixOS/nixpkgs/pull/243786#issue-1806531197), it would be better to build it from source. That would probably make an aarch64 build possible as well.

I remember doing some research on this, and that it turned out to be a minefield. If you download the official deb from the Vivaldi website, and open data.tar.xz/opt/vivaldi/update-ffmpeg (which is how you would get ffmpeg on Debian based systems), you're met with the following snippet in the script:

# Temporarily disable on ARM systems because there are no suitable libs (2023-05-26)
case amd64 in
  arm*|aarch64)
    echo "No suitable FFMpeg libs to enable proprietary media are currently available"
    exit 0
    ;;
esac

If you Google the problem, you see some posts for Fedora and Arch asking about aarch64 ffmpeg. Some of those posts had a solution in February last year, but that solution no longer works.

I'm afraid that getting this to work on aarch64 is going to be very difficult, at the very least until the Vivaldi devs themselves find a way to support it in general. Once they do, we could just take their update-ffmpeg script and package the essence of it in a Nix derivation. That's what the current derivation is anyway.

chewblacka commented 6 months ago

If you Google the problem, you see some posts for Fedora and Arch asking about aarch64 ffmpeg. Some of those posts had a solution in February last year, but that solution no longer works.

Do you have any more info on the solution not working? I managed to extract libffmpeg.so from the snap following the instructions here: https://discussion.fedoraproject.org/t/ffmpeg-support-for-chromium-browsers-on-aarch64/85306

The x86 download worked, but I have no way of testing it on aarch64.

There is also the vivaldi-codecs-ffmpeg-extra-bin package on AUR which extracts libffmpeg.so from the ubuntu deb files for the various architectures.

FPtje commented 6 months ago

The problem was that out-of-date versions started crashing. That's why I made the PR at https://github.com/NixOS/nixpkgs/pull/243786. That crash was reproducable on x86-64, and I'm not sure if it would reproduce on aarch64.

What I understand is that Vivaldi official changed from grabbing it from those Ubuntu deb files to using the snap. That snap no longer has the aarch64.

chewblacka commented 6 months ago

Although the website doesn't show the aarch64 snap, it does seem to be available. If you do curl -H "Snap-Device-Series: 16" http://api.snapcraft.io/v2/snaps/info/chromium >> chromium.info and then search within that for arm64 we can get the url to download the latest stable arm64 snap (released 2024-04-15):

https://api.snapcraft.io/api/v1/snaps/download/XKEcBqPM06H1Z7zGOdG5fbICuf8NWK5R_2822.snap

The url for amd64 is

https://api.snapcraft.io/api/v1/snaps/download/XKEcBqPM06H1Z7zGOdG5fbICuf8NWK5R_2828.snap

chewblacka commented 6 months ago

p.s. something like this would work:

{ squashfsTools, fetchurl, lib, stdenv }:

stdenv.mkDerivation rec {
  pname = "chromium-codecs-ffmpeg-extra";
  version = "124.0.6367.60";

  filename = if stdenv.isx86_64 then "XKEcBqPM06H1Z7zGOdG5fbICuf8NWK5R_2828.snap" else "XKEcBqPM06H1Z7zGOdG5fbICuf8NWK5R_2822.snap";
  src = fetchurl {
    url = "https://api.snapcraft.io/api/v1/snaps/download/${filename}";
    hash = if stdenv.isx86_64 then "sha256-7kSqb5MYZoTDzqkwP/47fkCtULGUeZvUis+SKQB39Q4=" else "sha256-DyguGWdzVTwRaCI7pfya2iHkftkCrUgrtakie6jakXs=";
  };

  buildInputs = [ squashfsTools ];

  unpackPhase = ''
    unsquashfs -dest . $src
  '';

  installPhase = ''
    install -vD usr/lib/chromium-browser/libffmpeg.so $out/lib/libffmpeg.so
  '';

  meta = with lib; {
    description = "Additional support for proprietary codecs for Vivaldi";
    homepage    = "https://ffmpeg.org/";
    sourceProvenance = with sourceTypes; [ binaryNativeCode ];
    license     = licenses.lgpl21;
    maintainers = with maintainers; [ betaboon cawilliamson fptje ];
    platforms   = [ "x86_64-linux" "aarch64-linux" ];
  };
}
chewblacka commented 6 months ago

Ooops, I copied the curl command wrongly (the quotes were incorrect), so it wasn't downloading. Have amended. Everything should be working now. The only issue is the version numbers can differ between architectures. e.g. currently amd64 is on 124.0.6367.60 but arm64 is on 123.0.6312.122

FPtje commented 6 months ago

That looks like it might work. Could you make a pull request with that change?

Due to personal circumstance I myself am a little less available, and as a non-frequent contributor I'm still not 100% on the procedures for Prs, but I'll do my best to review if you make a PR.

chewblacka commented 5 months ago

I'm having trouble testing this. Whenever I install vivaldi (on x86_64) it seems to play most videos fine even though proprietaryCodecs are disabled by default. If I try to build with proprietaryCodecs enabled, it doesn't seem to enable any more videos to play. I need a website with a video that plays fine with proprietaryCodecs enabled but doesn't play without them.

vxld100 commented 5 months ago

Vivaldi has a site that is intended for this. I remember that on my aarch64 installation it wasn't playing.

chewblacka commented 5 months ago

Vivaldi has a site that is intended for this. I remember that on my aarch64 installation it wasn't playing.

Ok thanks, that is the site I was using. The problem is I can't get that video to not play in x86_64. It plays fine in vivaldi whether codecs are enabled or not.

FPtje commented 5 months ago

It could be that the X86-64 Vivaldi derivation somehow already has those baked in, but the aarch64 doesn't :thinking:

mynery commented 4 months ago

p.s. something like this would work:

{ squashfsTools, fetchurl, lib, stdenv }:

stdenv.mkDerivation rec {
  pname = "chromium-codecs-ffmpeg-extra";
  version = "124.0.6367.60";

  filename = if stdenv.isx86_64 then "XKEcBqPM06H1Z7zGOdG5fbICuf8NWK5R_2828.snap" else "XKEcBqPM06H1Z7zGOdG5fbICuf8NWK5R_2822.snap";
  src = fetchurl {
    url = "https://api.snapcraft.io/api/v1/snaps/download/${filename}";
    hash = if stdenv.isx86_64 then "sha256-7kSqb5MYZoTDzqkwP/47fkCtULGUeZvUis+SKQB39Q4=" else "sha256-DyguGWdzVTwRaCI7pfya2iHkftkCrUgrtakie6jakXs=";
  };

  buildInputs = [ squashfsTools ];

  unpackPhase = ''
    unsquashfs -dest . $src
  '';

  installPhase = ''
    install -vD usr/lib/chromium-browser/libffmpeg.so $out/lib/libffmpeg.so
  '';

  meta = with lib; {
    description = "Additional support for proprietary codecs for Vivaldi";
    homepage    = "https://ffmpeg.org/";
    sourceProvenance = with sourceTypes; [ binaryNativeCode ];
    license     = licenses.lgpl21;
    maintainers = with maintainers; [ betaboon cawilliamson fptje ];
    platforms   = [ "x86_64-linux" "aarch64-linux" ];
  };
}

Just wanted to say that this worked perfectly for me, but I also had to modify the vivaldi package itself. There is opt/${vivaldiName}/lib/libffmpeg.so present in vivaldi as is and if I remove that and replace it to a symlink to the result of the above, I can use everything I expect.

Is this something the package needs to be adjusted for? I am not that deep into how upstream works. I think at the least there could be an option to make such a symlink.