2021-02-05 17:12:51 +00:00
{ lib , stdenv , buildPackages , fetchurl , pkg-config , addOpenGLRunpath , perl , texinfo , yasm
2020-04-24 23:36:52 +00:00
, alsaLib , bzip2 , fontconfig , freetype , gnutls , libiconv , lame , libass , libogg
, libssh , libtheora , libva , libdrm , libvorbis , libvpx , lzma , libpulseaudio , soxr
, x264 , x265 , xvidcore , zlib , libopus , speex , nv-codec-headers , dav1d
, openglSupport ? false , libGLU ? null , libGL ? null
, libmfxSupport ? false , intel-media-sdk ? null
, libaomSupport ? false , libaom ? null
# Build options
, runtimeCpuDetectBuild ? true # Detect CPU capabilities at runtime
, multithreadBuild ? true # Multithreading via pthreads/win32 threads
, sdlSupport ? ! stdenv . isAarch32 , SDL ? null , SDL2 ? null
, vdpauSupport ? ! stdenv . isAarch32 , libvdpau ? null
# Developer options
, debugDeveloper ? false
, optimizationsDeveloper ? true
, extraWarningsDeveloper ? false
# Darwin frameworks
, Cocoa , darwinFrameworks ? [ Cocoa ]
# Inherit generics
, branch , sha256 , version , patches ? [ ] , . . .
} :
/* M a i n t a i n e r n o t e s :
*
* THIS IS A MINIMAL BUILD OF FFMPEG , do not include dependencies unless
* a build that depends on ffmpeg requires them to be compiled into ffmpeg ,
* see ` ffmpeg-full' for an ffmpeg build with all features included .
*
* Need fixes to support Darwin :
* pulseaudio
*
* Known issues :
* 0 .6 - fails to compile ( unresolved ) ( so far , only disabling a number of
* features works , but that is not a feasible solution )
* 0 .6 .90 - mmx : compile errors ( fix : disable for 0 .6 . 9 0 - rc0 )
* 1 .1 - libsoxr : compile error ( fix : disable for 1 .1 )
* Support was initially added in 1 .1 before soxr api change , fix
* would probably be to add soxr-1 .0
* ALL - Cross-compiling will disable features not present on host OS
* ( e . g . dxva2 support [ DirectX ] will not be enabled unless natively
* compiled on Cygwin )
*
* /
let
inherit ( stdenv ) isDarwin isFreeBSD isLinux isAarch32 ;
2021-02-05 17:12:51 +00:00
inherit ( lib ) optional optionals optionalString enableFeature filter ;
2020-04-24 23:36:52 +00:00
cmpVer = builtins . compareVersions ;
reqMin = requiredVersion : ( cmpVer requiredVersion branch != 1 ) ;
reqMatch = requiredVersion : ( cmpVer requiredVersion branch == 0 ) ;
ifMinVer = minVer : flag : if reqMin minVer then flag else null ;
# Version specific fix
verFix = withoutFix : fixVer : withFix : if reqMatch fixVer then withFix else withoutFix ;
# Disable dependency that needs fixes before it will work on Darwin or Arm
disDarwinOrArmFix = origArg : minVer : fixArg : if ( ( isDarwin || isAarch32 ) && reqMin minVer ) then fixArg else origArg ;
vaapiSupport = reqMin " 0 . 6 " && ( ( isLinux || isFreeBSD ) && ! isAarch32 ) ;
vpxSupport = reqMin " 0 . 6 " && ! isAarch32 ;
in
assert openglSupport -> libGL != null && libGLU != null ;
assert libmfxSupport -> intel-media-sdk != null ;
assert libaomSupport -> libaom != null ;
stdenv . mkDerivation rec {
pname = " f f m p e g " ;
inherit version ;
src = fetchurl {
url = " h t t p s : / / w w w . f f m p e g . o r g / r e l e a s e s / ${ pname } - ${ version } . t a r . b z 2 " ;
inherit sha256 ;
} ;
2021-02-05 17:12:51 +00:00
postPatch = " p a t c h S h e b a n g s . " ;
2020-04-24 23:36:52 +00:00
inherit patches ;
outputs = [ " b i n " " d e v " " o u t " " m a n " ]
++ optional ( reqMin " 1 . 0 " ) " d o c " ; # just dev-doc
setOutputFlags = false ; # doesn't accept all and stores configureFlags in libs!
configurePlatforms = [ ] ;
configureFlags = filter ( v : v != null ) ( [
" - - a r c h = ${ stdenv . hostPlatform . parsed . cpu . name } "
" - - t a r g e t _ o s = ${ stdenv . hostPlatform . parsed . kernel . name } "
# License
" - - e n a b l e - g p l "
" - - e n a b l e - v e r s i o n 3 "
# Build flags
" - - e n a b l e - s h a r e d "
( ifMinVer " 0 . 6 " " - - e n a b l e - p i c " )
( enableFeature runtimeCpuDetectBuild " r u n t i m e - c p u d e t e c t " )
" - - e n a b l e - h a r d c o d e d - t a b l e s "
] ++
( if multithreadBuild then (
if stdenv . isCygwin then
[ " - - d i s a b l e - p t h r e a d s " " - - e n a b l e - w 3 2 t h r e a d s " ]
else # Use POSIX threads by default
[ " - - e n a b l e - p t h r e a d s " " - - d i s a b l e - w 3 2 t h r e a d s " ] )
else
[ " - - d i s a b l e - p t h r e a d s " " - - d i s a b l e - w 3 2 t h r e a d s " ] )
++ [
( ifMinVer " 0 . 9 " " - - d i s a b l e - o s 2 t h r e a d s " ) # We don't support OS/2
" - - e n a b l e - n e t w o r k "
( ifMinVer " 2 . 4 " " - - e n a b l e - p i x e l u t i l s " )
# Executables
" - - e n a b l e - f f m p e g "
" - - d i s a b l e - f f p l a y "
( ifMinVer " 0 . 6 " " - - e n a b l e - f f p r o b e " )
( if reqMin " 4 " then null else " - - d i s a b l e - f f s e r v e r " )
# Libraries
( ifMinVer " 0 . 6 " " - - e n a b l e - a v c o d e c " )
( ifMinVer " 0 . 6 " " - - e n a b l e - a v d e v i c e " )
" - - e n a b l e - a v f i l t e r "
( ifMinVer " 0 . 6 " " - - e n a b l e - a v f o r m a t " )
( ifMinVer " 1 . 0 " " - - e n a b l e - a v r e s a m p l e " )
( ifMinVer " 1 . 1 " " - - e n a b l e - a v u t i l " )
" - - e n a b l e - p o s t p r o c "
( ifMinVer " 0 . 9 " " - - e n a b l e - s w r e s a m p l e " )
" - - e n a b l e - s w s c a l e "
# Docs
( ifMinVer " 0 . 6 " " - - d i s a b l e - d o c " )
# External Libraries
2020-09-25 04:45:31 +00:00
" - - e n a b l e - l i b a s s "
2020-04-24 23:36:52 +00:00
" - - e n a b l e - b z l i b "
" - - e n a b l e - g n u t l s "
( ifMinVer " 1 . 0 " " - - e n a b l e - f o n t c o n f i g " )
( ifMinVer " 0 . 7 " " - - e n a b l e - l i b f r e e t y p e " )
" - - e n a b l e - l i b m p 3 l a m e "
( ifMinVer " 1 . 2 " " - - e n a b l e - i c o n v " )
" - - e n a b l e - l i b t h e o r a "
( ifMinVer " 2 . 1 " " - - e n a b l e - l i b s s h " )
( ifMinVer " 0 . 6 " ( enableFeature vaapiSupport " v a a p i " ) )
( ifMinVer " 3 . 4 " ( enableFeature vaapiSupport " l i b d r m " ) )
( enableFeature vdpauSupport " v d p a u " )
" - - e n a b l e - l i b v o r b i s "
( ifMinVer " 0 . 6 " ( enableFeature vpxSupport " l i b v p x " ) )
( ifMinVer " 2 . 4 " " - - e n a b l e - l z m a " )
( ifMinVer " 2 . 2 " ( enableFeature openglSupport " o p e n g l " ) )
( ifMinVer " 4 . 2 " ( enableFeature libmfxSupport " l i b m f x " ) )
( ifMinVer " 4 . 2 " ( enableFeature libaomSupport " l i b a o m " ) )
( disDarwinOrArmFix ( ifMinVer " 0 . 9 " " - - e n a b l e - l i b p u l s e " ) " 0 . 9 " " - - d i s a b l e - l i b p u l s e " )
( ifMinVer " 2 . 5 " ( if sdlSupport && reqMin " 3 . 2 " then " - - e n a b l e - s d l 2 " else if sdlSupport then " - - e n a b l e - s d l " else null ) ) # autodetected before 2.5, SDL1 support removed in 3.2 for SDL2
( ifMinVer " 1 . 2 " " - - e n a b l e - l i b s o x r " )
" - - e n a b l e - l i b x 2 6 4 "
" - - e n a b l e - l i b x v i d "
" - - e n a b l e - z l i b "
( ifMinVer " 2 . 8 " " - - e n a b l e - l i b o p u s " )
" - - e n a b l e - l i b s p e e x "
( ifMinVer " 2 . 8 " " - - e n a b l e - l i b x 2 6 5 " )
( ifMinVer " 4 . 2 " ( enableFeature ( dav1d != null ) " l i b d a v 1 d " ) )
# Developer flags
( enableFeature debugDeveloper " d e b u g " )
( enableFeature optimizationsDeveloper " o p t i m i z a t i o n s " )
( enableFeature extraWarningsDeveloper " e x t r a - w a r n i n g s " )
" - - d i s a b l e - s t r i p p i n g "
# Disable mmx support for 0.6.90
( verFix null " 0 . 6 . 9 0 " " - - d i s a b l e - m m x " )
] ++ optionals ( stdenv . hostPlatform != stdenv . buildPlatform ) [
" - - c r o s s - p r e f i x = ${ stdenv . cc . targetPrefix } "
" - - e n a b l e - c r o s s - c o m p i l e "
] ++ optional stdenv . cc . isClang " - - c c = c l a n g " ) ;
depsBuildBuild = [ buildPackages . stdenv . cc ] ;
2021-02-05 17:12:51 +00:00
nativeBuildInputs = [ addOpenGLRunpath perl pkg-config texinfo yasm ] ;
2020-04-24 23:36:52 +00:00
buildInputs = [
bzip2 fontconfig freetype gnutls libiconv lame libass libogg libssh libtheora
libvorbis lzma soxr x264 x265 xvidcore zlib libopus speex nv-codec-headers
] ++ optionals openglSupport [ libGL libGLU ]
++ optional libmfxSupport intel-media-sdk
2020-06-18 07:06:33 +00:00
++ optional libaomSupport libaom
2020-04-24 23:36:52 +00:00
++ optional vpxSupport libvpx
++ optionals ( ! isDarwin && ! isAarch32 ) [ libpulseaudio ] # Need to be fixed on Darwin and ARM
++ optional ( ( isLinux || isFreeBSD ) && ! isAarch32 ) libva
++ optional ( ( isLinux || isFreeBSD ) && ! isAarch32 ) libdrm
++ optional isLinux alsaLib
++ optionals isDarwin darwinFrameworks
++ optional vdpauSupport libvdpau
++ optional sdlSupport ( if reqMin " 3 . 2 " then SDL2 else SDL )
++ optional ( reqMin " 4 . 2 " ) dav1d ;
enableParallelBuilding = true ;
doCheck = false ; # fails
# ffmpeg 3+ generates pkg-config (.pc) files that don't have the
# form automatically handled by the multiple-outputs hooks.
postFixup = ''
moveToOutput bin " $ b i n "
moveToOutput share/ffmpeg/examples " $ d o c "
for pc in '' ${ ! outputDev } / l i b / p k g c o n f i g / * . p c ; d o
substituteInPlace $ pc \
- - replace " i n c l u d e d i r = $ o u t " " i n c l u d e d i r = ' ' ${ ! outputInclude } "
done
'' + o p t i o n a l S t r i n g s t d e n v . i s L i n u x ''
2020-06-18 07:06:33 +00:00
# Set RUNPATH so that libnvcuvid and libcuda in /run/opengl-driver(-32)/lib can be found.
2020-04-24 23:36:52 +00:00
# See the explanation in addOpenGLRunpath.
2020-06-18 07:06:33 +00:00
addOpenGLRunpath $ out/lib/libavcodec.so
addOpenGLRunpath $ out/lib/libavutil.so
2020-04-24 23:36:52 +00:00
'' ;
installFlags = [ " i n s t a l l - m a n " ] ;
passthru = {
inherit vaapiSupport vdpauSupport ;
} ;
2021-02-05 17:12:51 +00:00
meta = with lib ; {
2020-04-24 23:36:52 +00:00
description = " A c o m p l e t e , c r o s s - p l a t f o r m s o l u t i o n t o r e c o r d , c o n v e r t a n d s t r e a m a u d i o a n d v i d e o " ;
homepage = " h t t p : / / w w w . f f m p e g . o r g / " ;
longDescription = ''
FFmpeg is the leading multimedia framework , able to decode , encode , transcode ,
mux , demux , stream , filter and play pretty much anything that humans and machines
have created . It supports the most obscure ancient formats up to the cutting edge .
No matter if they were designed by some standards committee , the community or
a corporation .
'' ;
license = licenses . gpl3 ;
platforms = platforms . all ;
maintainers = with maintainers ; [ codyopel ] ;
inherit branch ;
} ;
}