Merge pull request #295691 from Atemu/ffmpeg-version-interface

ffmpeg: make version a regular parameter and use callPackage pattern
This commit is contained in:
Atemu 2024-03-16 20:57:38 +00:00 committed by GitHub
commit 0b9f28b5d4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 126 additions and 108 deletions

View file

@ -1,29 +0,0 @@
import ./generic.nix {
version = "4.4.4";
hash = "sha256-Q8bkuF/1uJfqttJJoObnnLX3BEduv+qxsvOrVhMvRjA=";
extraPatches = [
{
name = "libsvtav1-1.5.0-compat-compressed_ten_bit_format.patch";
url = "https://git.ffmpeg.org/gitweb/ffmpeg.git/patch/031f1561cd286596cdb374da32f8aa816ce3b135";
hash = "sha256-mSnmAkoNikDpxcN+A/hpB7mUbbtcMvm4tG6gZFuroe8=";
}
{
# Backport fix for binutils-2.41.
name = "binutils-2.41.patch";
url = "https://git.ffmpeg.org/gitweb/ffmpeg.git/patch/effadce6c756247ea8bae32dc13bb3e6f464f0eb";
hash = "sha256-vlBUMJ1bORQHRNpuzc5iXsTWwS/CN5BmGIA8g7H7mJE=";
}
# The upstream patch isnt for ffmpeg 4, but it will apply with a few tweaks.
# Fixes a crash when built with clang 16 due to UB in ff_seek_frame_binary.
{
name = "utils-fix_crash_in_ff_seek_frame_binary.patch";
url = "https://git.ffmpeg.org/gitweb/ffmpeg.git/patch/ab792634197e364ca1bb194f9abe36836e42f12d";
hash = "sha256-UxZ4VneZpw+Q/UwkEUDNdb2nOx1QnMrZ40UagspNTxI=";
postFetch = ''
substituteInPlace "$out" \
--replace libavformat/seek.c libavformat/utils.c \
--replace 'const AVInputFormat *const ' 'const AVInputFormat *'
'';
}
];
}

View file

@ -1,6 +0,0 @@
import ./generic.nix {
version = "5.1.4";
hash = "sha256-2jUL1/xGUf7aMooST2DW41KE7bC+BtgChXmj0sAJZ90=";
extraPatches = [
];
}

View file

@ -1,6 +0,0 @@
import ./generic.nix {
version = "6.1.1";
hash = "sha256-Q0c95hbCVUHQWPoh5uC8uzMylmB4BnWg+VhXEgSouzo=";
extraPatches = [
];
}

View file

@ -0,0 +1,58 @@
{ callPackage, darwin }:
let
mkFFmpeg =
initArgs: ffmpegVariant:
callPackage ./generic.nix (
{
inherit (darwin.apple_sdk.frameworks)
Cocoa
CoreServices
CoreAudio
CoreMedia
AVFoundation
MediaToolbox
VideoDecodeAcceleration
VideoToolbox
;
}
// (initArgs // { inherit ffmpegVariant; })
);
v4 = {
version = "4.4.4";
hash = "sha256-Q8bkuF/1uJfqttJJoObnnLX3BEduv+qxsvOrVhMvRjA=";
};
v5 = {
version = "5.1.4";
hash = "sha256-2jUL1/xGUf7aMooST2DW41KE7bC+BtgChXmj0sAJZ90=";
};
v6 = {
version = "6.1.1";
hash = "sha256-Q0c95hbCVUHQWPoh5uC8uzMylmB4BnWg+VhXEgSouzo=";
};
in
rec {
ffmpeg_4 = mkFFmpeg v4 "small";
ffmpeg_4-headless = mkFFmpeg v4 "headless";
ffmpeg_4-full = mkFFmpeg v4 "full";
ffmpeg_5 = mkFFmpeg v5 "small";
ffmpeg_5-headless = mkFFmpeg v5 "headless";
ffmpeg_5-full = mkFFmpeg v5 "full";
ffmpeg_6 = mkFFmpeg v6 "small";
ffmpeg_6-headless = mkFFmpeg v6 "headless";
ffmpeg_6-full = mkFFmpeg v6 "full";
# Please make sure this is updated to the latest version on the next major
# update to ffmpeg
# Packages which use ffmpeg as a library, should pin to the relevant major
# version number which the upstream support.
ffmpeg = ffmpeg_6;
ffmpeg-headless = ffmpeg_6-headless;
ffmpeg-full = ffmpeg_6-full;
}

View file

@ -1,7 +1,15 @@
{ version, hash, extraPatches ? [] }:
{ lib, stdenv, buildPackages, removeReferencesTo, addOpenGLRunpath, pkg-config, perl, texinfo, yasm { lib, stdenv, buildPackages, removeReferencesTo, addOpenGLRunpath, pkg-config, perl, texinfo, yasm
# You can fetch any upstream version using this derivation by specifying version and hash
# NOTICE: Always use this argument to override the version. Do not use overrideAttrs.
, version # ffmpeg ABI version. Also declare this if you're overriding the source.
, hash ? "" # hash of the upstream source for the given ABI version
, source ? fetchgit {
url = "https://git.ffmpeg.org/ffmpeg.git";
rev = "n${version}";
inherit hash;
}
, ffmpegVariant ? "small" # Decides which dependencies are enabled by default , ffmpegVariant ? "small" # Decides which dependencies are enabled by default
# Build with headless deps; excludes dependencies that are only necessary for # Build with headless deps; excludes dependencies that are only necessary for
@ -305,7 +313,7 @@
*/ */
let let
inherit (lib) optional optionals optionalString enableFeature versionAtLeast; inherit (lib) optional optionals optionalString enableFeature versionOlder versionAtLeast;
in in
@ -346,12 +354,7 @@ assert buildSwscale -> buildAvutil;
stdenv.mkDerivation (finalAttrs: { stdenv.mkDerivation (finalAttrs: {
pname = "ffmpeg" + (optionalString (ffmpegVariant != "small") "-${ffmpegVariant}"); pname = "ffmpeg" + (optionalString (ffmpegVariant != "small") "-${ffmpegVariant}");
inherit version; inherit version;
src = source;
src = fetchgit {
url = "https://git.ffmpeg.org/ffmpeg.git";
rev = "n${finalAttrs.version}";
inherit hash;
};
postPatch = '' postPatch = ''
patchShebangs . patchShebangs .
@ -362,15 +365,40 @@ stdenv.mkDerivation (finalAttrs: {
--replace /usr/local/lib/frei0r-1 ${frei0r}/lib/frei0r-1 --replace /usr/local/lib/frei0r-1 ${frei0r}/lib/frei0r-1
''; '';
patches = map (patch: fetchpatch patch) (extraPatches patches = map (patch: fetchpatch patch) ([ ]
++ (lib.optional (lib.versionAtLeast finalAttrs.version "6" && lib.versionOlder finalAttrs.version "6.1") ++ optionals (versionOlder version "5") [
{
name = "libsvtav1-1.5.0-compat-compressed_ten_bit_format.patch";
url = "https://git.ffmpeg.org/gitweb/ffmpeg.git/patch/031f1561cd286596cdb374da32f8aa816ce3b135";
hash = "sha256-mSnmAkoNikDpxcN+A/hpB7mUbbtcMvm4tG6gZFuroe8=";
}
{
# Backport fix for binutils-2.41.
name = "binutils-2.41.patch";
url = "https://git.ffmpeg.org/gitweb/ffmpeg.git/patch/effadce6c756247ea8bae32dc13bb3e6f464f0eb";
hash = "sha256-vlBUMJ1bORQHRNpuzc5iXsTWwS/CN5BmGIA8g7H7mJE=";
}
# The upstream patch isnt for ffmpeg 4, but it will apply with a few tweaks.
# Fixes a crash when built with clang 16 due to UB in ff_seek_frame_binary.
{
name = "utils-fix_crash_in_ff_seek_frame_binary.patch";
url = "https://git.ffmpeg.org/gitweb/ffmpeg.git/patch/ab792634197e364ca1bb194f9abe36836e42f12d";
hash = "sha256-UxZ4VneZpw+Q/UwkEUDNdb2nOx1QnMrZ40UagspNTxI=";
postFetch = ''
substituteInPlace "$out" \
--replace libavformat/seek.c libavformat/utils.c \
--replace 'const AVInputFormat *const ' 'const AVInputFormat *'
'';
}
]
++ (lib.optional (lib.versionAtLeast version "6" && lib.versionOlder version "6.1")
{ # this can be removed post 6.1 { # this can be removed post 6.1
name = "fix_aacps_tablegen"; name = "fix_aacps_tablegen";
url = "https://git.ffmpeg.org/gitweb/ffmpeg.git/patch/814178f92647be2411516bbb82f48532373d2554"; url = "https://git.ffmpeg.org/gitweb/ffmpeg.git/patch/814178f92647be2411516bbb82f48532373d2554";
hash = "sha256-FQV9/PiarPXCm45ldtCsxGHjlrriL8DKpn1LaKJ8owI="; hash = "sha256-FQV9/PiarPXCm45ldtCsxGHjlrriL8DKpn1LaKJ8owI=";
} }
) )
++ (lib.optional (lib.versionAtLeast finalAttrs.version "6.1" && lib.versionOlder finalAttrs.version "6.2") ++ (lib.optional (lib.versionAtLeast version "6.1" && lib.versionOlder version "6.2")
{ # this can be removed post 6.1 { # this can be removed post 6.1
name = "fix_build_failure_due_to_PropertyKey_EncoderID"; name = "fix_build_failure_due_to_PropertyKey_EncoderID";
url = "https://git.ffmpeg.org/gitweb/ffmpeg.git/patch/cb049d377f54f6b747667a93e4b719380c3e9475"; url = "https://git.ffmpeg.org/gitweb/ffmpeg.git/patch/cb049d377f54f6b747667a93e4b719380c3e9475";
@ -431,7 +459,7 @@ stdenv.mkDerivation (finalAttrs: {
(enableFeature buildAvdevice "avdevice") (enableFeature buildAvdevice "avdevice")
(enableFeature buildAvfilter "avfilter") (enableFeature buildAvfilter "avfilter")
(enableFeature buildAvformat "avformat") (enableFeature buildAvformat "avformat")
] ++ optionals (lib.versionOlder finalAttrs.version "5") [ ] ++ optionals (lib.versionOlder version "5") [
# Ffmpeg > 4 doesn't know about the flag anymore # Ffmpeg > 4 doesn't know about the flag anymore
(enableFeature buildAvresample "avresample") (enableFeature buildAvresample "avresample")
] ++ [ ] ++ [
@ -462,7 +490,7 @@ stdenv.mkDerivation (finalAttrs: {
*/ */
(enableFeature withAlsa "alsa") (enableFeature withAlsa "alsa")
(enableFeature withAom "libaom") (enableFeature withAom "libaom")
] ++ optionals (versionAtLeast finalAttrs.version "6.1") [ ] ++ optionals (versionAtLeast version "6.1") [
(enableFeature withAribcaption "libaribcaption") (enableFeature withAribcaption "libaribcaption")
] ++ [ ] ++ [
(enableFeature withAss "libass") (enableFeature withAss "libass")
@ -487,7 +515,7 @@ stdenv.mkDerivation (finalAttrs: {
(enableFeature withGme "libgme") (enableFeature withGme "libgme")
(enableFeature withGnutls "gnutls") (enableFeature withGnutls "gnutls")
(enableFeature withGsm "libgsm") (enableFeature withGsm "libgsm")
] ++ optionals (versionAtLeast finalAttrs.version "6.1") [ ] ++ optionals (versionAtLeast version "6.1") [
(enableFeature withHarfbuzz "libharfbuzz") (enableFeature withHarfbuzz "libharfbuzz")
] ++ [ ] ++ [
(enableFeature withIconv "iconv") (enableFeature withIconv "iconv")
@ -510,7 +538,7 @@ stdenv.mkDerivation (finalAttrs: {
(enableFeature withOpenjpeg "libopenjpeg") (enableFeature withOpenjpeg "libopenjpeg")
(enableFeature withOpenmpt "libopenmpt") (enableFeature withOpenmpt "libopenmpt")
(enableFeature withOpus "libopus") (enableFeature withOpus "libopus")
] ++ optionals (versionAtLeast finalAttrs.version "5.0") [ ] ++ optionals (versionAtLeast version "5.0") [
(enableFeature withPlacebo "libplacebo") (enableFeature withPlacebo "libplacebo")
] ++ [ ] ++ [
(enableFeature withPulse "libpulse") (enableFeature withPulse "libpulse")
@ -518,7 +546,7 @@ stdenv.mkDerivation (finalAttrs: {
(enableFeature withRtmp "librtmp") (enableFeature withRtmp "librtmp")
(enableFeature withSamba "libsmbclient") (enableFeature withSamba "libsmbclient")
(enableFeature withSdl2 "sdl2") (enableFeature withSdl2 "sdl2")
] ++ optionals (versionAtLeast finalAttrs.version "5.0") [ ] ++ optionals (versionAtLeast version "5.0") [
(enableFeature withShaderc "libshaderc") (enableFeature withShaderc "libshaderc")
] ++ [ ] ++ [
(enableFeature withSoxr "libsoxr") (enableFeature withSoxr "libsoxr")
@ -616,7 +644,7 @@ stdenv.mkDerivation (finalAttrs: {
++ optionals withModplug [ libmodplug ] ++ optionals withModplug [ libmodplug ]
++ optionals withMp3lame [ lame ] ++ optionals withMp3lame [ lame ]
++ optionals withMysofa [ libmysofa ] ++ optionals withMysofa [ libmysofa ]
++ optionals (withNvdec || withNvenc) [ (if (lib.versionAtLeast finalAttrs.version "6") then nv-codec-headers-12 else nv-codec-headers) ] ++ optionals (withNvdec || withNvenc) [ (if (lib.versionAtLeast version "6") then nv-codec-headers-12 else nv-codec-headers) ]
++ optionals withOgg [ libogg ] ++ optionals withOgg [ libogg ]
++ optionals withOpenal [ openal ] ++ optionals withOpenal [ openal ]
++ optionals withOpencl [ ocl-icd opencl-headers ] ++ optionals withOpencl [ ocl-icd opencl-headers ]
@ -626,7 +654,7 @@ stdenv.mkDerivation (finalAttrs: {
++ optionals withOpenjpeg [ openjpeg ] ++ optionals withOpenjpeg [ openjpeg ]
++ optionals withOpenmpt [ libopenmpt ] ++ optionals withOpenmpt [ libopenmpt ]
++ optionals withOpus [ libopus ] ++ optionals withOpus [ libopus ]
++ optionals withPlacebo [ (if (lib.versionAtLeast finalAttrs.version "6.1") then libplacebo else libplacebo_5) vulkan-headers ] ++ optionals withPlacebo [ (if (lib.versionAtLeast version "6.1") then libplacebo else libplacebo_5) vulkan-headers ]
++ optionals withPulse [ libpulseaudio ] ++ optionals withPulse [ libpulseaudio ]
++ optionals withRav1e [ rav1e ] ++ optionals withRav1e [ rav1e ]
++ optionals withRtmp [ rtmpdump ] ++ optionals withRtmp [ rtmpdump ]
@ -725,7 +753,7 @@ stdenv.mkDerivation (finalAttrs: {
meta = with lib; { meta = with lib; {
description = "A complete, cross-platform solution to record, convert and stream audio and video"; description = "A complete, cross-platform solution to record, convert and stream audio and video";
homepage = "https://www.ffmpeg.org/"; homepage = "https://www.ffmpeg.org/";
changelog = "https://github.com/FFmpeg/FFmpeg/blob/n${finalAttrs.version}/Changelog"; changelog = "https://github.com/FFmpeg/FFmpeg/blob/n${version}/Changelog";
longDescription = '' longDescription = ''
FFmpeg is the leading multimedia framework, able to decode, encode, transcode, FFmpeg is the leading multimedia framework, able to decode, encode, transcode,
mux, demux, stream, filter and play pretty much anything that humans and machines mux, demux, stream, filter and play pretty much anything that humans and machines

View file

@ -3,16 +3,20 @@
, lib , lib
}: }:
ffmpeg_6-full.overrideAttrs (old: rec { let
pname = "jellyfin-ffmpeg";
version = "6.0.1-3"; version = "6.0.1-3";
in
src = fetchFromGitHub { (ffmpeg_6-full.override {
inherit version; # Important! This sets the ABI.
source = fetchFromGitHub {
owner = "jellyfin"; owner = "jellyfin";
repo = "jellyfin-ffmpeg"; repo = "jellyfin-ffmpeg";
rev = "v${version}"; rev = "v${version}";
hash = "sha256-UINiXO61nB/AL0HJJy7G7emujakk/mQv81aUioyJz0Y="; hash = "sha256-UINiXO61nB/AL0HJJy7G7emujakk/mQv81aUioyJz0Y=";
}; };
}).overrideAttrs (old: {
pname = "jellyfin-ffmpeg";
# Clobber upstream patches as they don't apply to the Jellyfin fork # Clobber upstream patches as they don't apply to the Jellyfin fork
patches = []; patches = [];

View file

@ -20946,50 +20946,19 @@ with pkgs;
linbox = callPackage ../development/libraries/linbox { }; linbox = callPackage ../development/libraries/linbox { };
ffmpeg_4 = callPackage ../development/libraries/ffmpeg/4.nix { inherit (callPackage ../development/libraries/ffmpeg { })
inherit (darwin.apple_sdk.frameworks) ffmpeg_4
Cocoa CoreServices CoreAudio CoreMedia AVFoundation MediaToolbox ffmpeg_4-headless
VideoDecodeAcceleration VideoToolbox; ffmpeg_4-full
}; ffmpeg_5
ffmpeg_4-headless = ffmpeg_4.override { ffmpeg_5-headless
ffmpegVariant = "headless"; ffmpeg_5-full
}; ffmpeg_6
ffmpeg_4-full = ffmpeg_4.override { ffmpeg_6-headless
ffmpegVariant = "full"; ffmpeg_6-full
}; ffmpeg
ffmpeg-headless
ffmpeg_5 = callPackage ../development/libraries/ffmpeg/5.nix { ffmpeg-full;
inherit (darwin.apple_sdk.frameworks)
Cocoa CoreServices CoreAudio CoreMedia AVFoundation MediaToolbox
VideoDecodeAcceleration VideoToolbox;
};
ffmpeg_5-headless = ffmpeg_5.override {
ffmpegVariant = "headless";
};
ffmpeg_5-full = ffmpeg_5.override {
ffmpegVariant = "full";
};
ffmpeg_6 = callPackage ../development/libraries/ffmpeg/6.nix {
inherit (darwin.apple_sdk.frameworks)
Cocoa CoreServices CoreAudio CoreMedia AVFoundation MediaToolbox
VideoDecodeAcceleration VideoToolbox;
};
ffmpeg_6-headless = ffmpeg_6.override {
ffmpegVariant = "headless";
};
ffmpeg_6-full = ffmpeg_6.override {
ffmpegVariant = "full";
};
# Aliases
# Please make sure this is updated to the latest version on the next major
# update to ffmpeg
# Packages which use ffmpeg as a library, should pin to the relevant major
# version number which the upstream support.
ffmpeg = ffmpeg_6;
ffmpeg-headless = ffmpeg_6-headless;
ffmpeg-full = ffmpeg_6-full;
ffmpegthumbnailer = callPackage ../development/libraries/ffmpegthumbnailer { }; ffmpegthumbnailer = callPackage ../development/libraries/ffmpegthumbnailer { };