1{ lib, stdenv
2, fetchFromGitHub
3, libaom
4, cmake
5, pkg-config
6, zlib
7, libpng
8, libjpeg
9, dav1d
10, libyuv
11, gdk-pixbuf
12, makeWrapper
13}:
14
15let
16 gdkPixbufModuleDir = "${placeholder "out"}/${gdk-pixbuf.moduleDir}";
17 gdkPixbufModuleFile = "${placeholder "out"}/${gdk-pixbuf.binaryDir}/avif-loaders.cache";
18in
19
20stdenv.mkDerivation rec {
21 pname = "libavif";
22 version = "1.1.0";
23
24 src = fetchFromGitHub {
25 owner = "AOMediaCodec";
26 repo = pname;
27 rev = "v${version}";
28 hash = "sha256-yNJiMTWgOKR1c2pxTkLY/uPWGIY4xgH+Ee0r15oroDU=";
29 };
30
31 # reco: encode libaom slowest but best, decode dav1d fastest
32
33 cmakeFlags = [
34 "-DBUILD_SHARED_LIBS=ON"
35 "-DAVIF_CODEC_AOM=ON" # best encoder (slow but small)
36 "-DAVIF_CODEC_DAV1D=ON" # best decoder (fast)
37 "-DAVIF_CODEC_AOM_DECODE=OFF"
38 "-DAVIF_BUILD_APPS=ON"
39 "-DAVIF_BUILD_GDK_PIXBUF=ON"
40 ];
41
42 nativeBuildInputs = [
43 cmake
44 pkg-config
45 gdk-pixbuf
46 makeWrapper
47 ];
48
49 buildInputs = [
50 gdk-pixbuf
51 libaom
52 zlib
53 libpng
54 libjpeg
55 dav1d
56 libyuv
57 ];
58
59 postPatch = ''
60 substituteInPlace contrib/gdk-pixbuf/avif.thumbnailer.in \
61 --replace '@CMAKE_INSTALL_FULL_BINDIR@/gdk-pixbuf-thumbnailer' "$out/libexec/gdk-pixbuf-thumbnailer-avif"
62 '';
63
64 env.PKG_CONFIG_GDK_PIXBUF_2_0_GDK_PIXBUF_MODULEDIR = gdkPixbufModuleDir;
65
66 postInstall = ''
67 GDK_PIXBUF_MODULEDIR=${gdkPixbufModuleDir} \
68 GDK_PIXBUF_MODULE_FILE=${gdkPixbufModuleFile} \
69 gdk-pixbuf-query-loaders --update-cache
70
71 ''
72 # Cross-compiled gdk-pixbuf doesn't support thumbnailers
73 + lib.optionalString (stdenv.hostPlatform == stdenv.buildPlatform) ''
74 mkdir -p "$out/bin"
75 makeWrapper ${gdk-pixbuf}/bin/gdk-pixbuf-thumbnailer "$out/libexec/gdk-pixbuf-thumbnailer-avif" \
76 --set GDK_PIXBUF_MODULE_FILE ${gdkPixbufModuleFile}
77 '';
78
79 meta = with lib; {
80 description = "C implementation of the AV1 Image File Format";
81 longDescription = ''
82 Libavif aims to be a friendly, portable C implementation of the
83 AV1 Image File Format. It is a work-in-progress, but can already
84 encode and decode all AOM supported YUV formats and bit depths
85 (with alpha). It also features an encoder and a decoder
86 (avifenc/avifdec).
87 '';
88 homepage = "https://github.com/AOMediaCodec/libavif";
89 changelog = "https://github.com/AOMediaCodec/libavif/blob/v${version}/CHANGELOG.md";
90 maintainers = with maintainers; [ mkg20001 ];
91 platforms = platforms.all;
92 license = licenses.bsd2;
93 };
94}