contrib: ffmpeg: use a newer version of FFmpeg that is multithread safe with DXVA
[vlc.git] / contrib / src / ffmpeg / rules.mak
1 # FFmpeg
2
3 #Uncomment the one you want
4 #USE_LIBAV ?= 1
5 #USE_FFMPEG ?= 1
6
7 ifdef USE_FFMPEG
8 FFMPEG_HASH=66963d4b8d302611553e7928063c1cb2ff0efdff
9 FFMPEG_SNAPURL := http://git.videolan.org/?p=ffmpeg.git;a=snapshot;h=$(FFMPEG_HASH);sf=tgz
10 FFMPEG_GITURL := http://git.videolan.org/git/ffmpeg.git
11 else
12 FFMPEG_HASH=b3825723dceffc64240da7b0e562bd1fd024da26
13 FFMPEG_SNAPURL := http://git.libav.org/?p=libav.git;a=snapshot;h=$(FFMPEG_HASH);sf=tgz
14 FFMPEG_GITURL := git://git.libav.org/libav.git
15 endif
16
17 FFMPEG_BASENAME := $(subst .,_,$(subst \,_,$(subst /,_,$(FFMPEG_HASH))))
18
19 FFMPEGCONF = \
20         --cc="$(CC)" \
21         --pkg-config="$(PKG_CONFIG)" \
22         --disable-doc \
23         --disable-encoder=vorbis \
24         --disable-decoder=opus \
25         --enable-libgsm \
26         --enable-libopenjpeg \
27         --disable-debug \
28         --disable-avdevice \
29         --disable-devices \
30         --disable-avfilter \
31         --disable-filters \
32         --disable-protocol=concat \
33         --disable-bsfs \
34         --disable-bzlib \
35         --disable-avresample
36
37 ifdef USE_FFMPEG
38 FFMPEGCONF += \
39         --disable-swresample \
40         --disable-iconv \
41         --disable-avisynth \
42         --disable-nvenc
43 ifdef HAVE_DARWIN_OS
44 FFMPEGCONF += \
45         --disable-videotoolbox
46 endif
47 endif
48
49 DEPS_ffmpeg = zlib gsm openjpeg
50
51 # Optional dependencies
52 ifndef BUILD_NETWORK
53 FFMPEGCONF += --disable-network
54 endif
55 ifdef BUILD_ENCODERS
56 FFMPEGCONF += --enable-libmp3lame --enable-libvpx --disable-decoder=libvpx_vp8 --disable-decoder=libvpx_vp9
57 ifndef USE_FFMPEG
58 FFMPEGCONF += --disable-decoder=libvpx
59 endif
60 DEPS_ffmpeg += lame $(DEPS_lame) vpx $(DEPS_vpx)
61 else
62 FFMPEGCONF += --disable-encoders --disable-muxers
63 endif
64
65 # Small size
66 ifdef WITH_OPTIMIZATION
67 ifdef ENABLE_SMALL
68 FFMPEGCONF += --enable-small
69 endif
70 ifeq ($(ARCH),arm)
71 ifdef HAVE_ARMV7A
72 FFMPEGCONF += --enable-thumb
73 endif
74 endif
75 else
76 FFMPEGCONF += --optflags=-O0
77 endif
78
79 ifdef HAVE_CROSS_COMPILE
80 FFMPEGCONF += --enable-cross-compile --disable-programs
81 ifndef HAVE_DARWIN_OS
82 FFMPEGCONF += --cross-prefix=$(HOST)-
83 endif
84 endif
85
86 # ARM stuff
87 ifeq ($(ARCH),arm)
88 FFMPEGCONF += --arch=arm
89 ifdef HAVE_NEON
90 FFMPEGCONF += --enable-neon
91 endif
92 ifdef HAVE_ARMV7A
93 FFMPEGCONF += --cpu=cortex-a8
94 endif
95 ifdef HAVE_ARMV6
96 FFMPEGCONF += --cpu=armv6 --disable-neon
97 endif
98 endif
99
100 # ARM64 stuff
101 ifeq ($(ARCH),aarch64)
102 FFMPEGCONF += --arch=aarch64
103 endif
104
105 # MIPS stuff
106 ifeq ($(ARCH),mipsel)
107 FFMPEGCONF += --arch=mips
108 endif
109 ifeq ($(ARCH),mips64el)
110 FFMPEGCONF += --arch=mips64
111 endif
112
113 # x86 stuff
114 ifeq ($(ARCH),i386)
115 ifndef HAVE_DARWIN_OS
116 FFMPEGCONF += --arch=x86
117 endif
118 endif
119
120 # x86_64 stuff
121 ifeq ($(ARCH),x86_64)
122 ifndef HAVE_DARWIN_OS
123 FFMPEGCONF += --arch=x86_64
124 endif
125 endif
126
127 # Darwin
128 ifdef HAVE_DARWIN_OS
129 FFMPEGCONF += --arch=$(ARCH) --target-os=darwin
130 ifdef USE_FFMPEG
131 FFMPEGCONF += --disable-lzma
132 endif
133 ifeq ($(ARCH),x86_64)
134 FFMPEGCONF += --cpu=core2
135 endif
136 ifdef HAVE_IOS
137 FFMPEGCONF += --enable-pic --extra-ldflags="$(EXTRA_CFLAGS)"
138 ifdef HAVE_NEON
139 FFMPEGCONF += --as="$(AS)"
140 endif
141 endif
142 ifdef HAVE_MACOSX
143 FFMPEGCONF += --enable-vda
144 endif
145 endif
146
147 # Linux
148 ifdef HAVE_LINUX
149 FFMPEGCONF += --target-os=linux --enable-pic
150
151 endif
152
153 ifdef HAVE_ANDROID
154 # broken text relocations
155 ifeq ($(ANDROID_ABI), x86)
156 FFMPEGCONF +=  --disable-mmx --disable-mmxext --disable-inline-asm
157 endif
158 ifeq ($(ANDROID_ABI), x86_64)
159 FFMPEGCONF +=  --disable-mmx --disable-mmxext --disable-inline-asm
160 endif
161 ifdef HAVE_NEON
162 ifeq ($(ANDROID_ABI), armeabi-v7a)
163 FFMPEGCONF += --as='gas-preprocessor.pl -as-type clang -arch arm $(CC)'
164 endif
165 endif
166 endif
167
168 # Windows
169 ifdef HAVE_WIN32
170 ifndef HAVE_VISUALSTUDIO
171 DEPS_ffmpeg += d3d11
172 ifndef HAVE_MINGW_W64
173 DEPS_ffmpeg += directx
174 endif
175 endif
176 FFMPEGCONF += --target-os=mingw32
177 FFMPEGCONF += --enable-w32threads
178 ifndef HAVE_WINSTORE
179 FFMPEGCONF += --enable-dxva2
180 else
181 FFMPEGCONF += --disable-dxva2
182 endif
183
184 ifdef USE_FFMPEG
185 FFMPEGCONF += --enable-memalign-hack
186 endif
187
188 ifdef HAVE_WIN64
189 FFMPEGCONF += --cpu=athlon64 --arch=x86_64
190 else
191 ifeq ($(ARCH),i386) # 32bits intel
192 FFMPEGCONF+= --cpu=i686 --arch=x86
193 else
194 ifdef HAVE_ARMV7A
195 FFMPEGCONF+= --arch=arm
196 endif
197 endif
198 endif
199
200 else # !Windows
201 FFMPEGCONF += --enable-pthreads
202 endif
203
204 # Solaris
205 ifdef HAVE_SOLARIS
206 ifeq ($(ARCH),x86_64)
207 FFMPEGCONF += --cpu=core2
208 endif
209 FFMPEGCONF += --target-os=sunos --enable-pic
210 endif
211
212 # Build
213 PKGS += ffmpeg
214 ifeq ($(call need_pkg,"libavcodec >= 55.0.0 libavformat >= 53.21.0 libswscale"),)
215 PKGS_FOUND += ffmpeg
216 endif
217
218 FFMPEGCONF += --nm="$(NM)" --ar="$(AR)"
219
220 $(TARBALLS)/ffmpeg-$(FFMPEG_BASENAME).tar.xz:
221         $(call download_git,$(FFMPEG_GITURL),,$(FFMPEG_HASH))
222
223 .sum-ffmpeg: $(TARBALLS)/ffmpeg-$(FFMPEG_BASENAME).tar.xz
224         $(call check_githash,$(FFMPEG_HASH))
225         touch $@
226
227 ffmpeg: ffmpeg-$(FFMPEG_BASENAME).tar.xz .sum-ffmpeg
228         rm -Rf $@ $@-$(FFMPEG_BASENAME)
229         mkdir -p $@-$(FFMPEG_BASENAME)
230         tar xvJf "$<" --strip-components=1 -C $@-$(FFMPEG_BASENAME)
231         $(MOVE)
232
233 .ffmpeg: ffmpeg
234         cd $< && $(HOSTVARS) ./configure \
235                 --extra-ldflags="$(LDFLAGS)" $(FFMPEGCONF) \
236                 --prefix="$(PREFIX)" --enable-static --disable-shared
237         cd $< && $(MAKE) install-libs install-headers
238         touch $@