|
| 1 | +* Cross Compile FFmpeg for Windows |
| 2 | + |
| 3 | + |
| 4 | +** Host Environment |
| 5 | + |
| 6 | + - Windows10 |
| 7 | + - Cygwin-x86_64 with mingw64-x86_64-gcc-g++ compiler suits |
| 8 | + |
| 9 | +** Requirements |
| 10 | + |
| 11 | + - x264 (e.g. x264-master.tar.bz2) |
| 12 | + - x265 (e.g. x265-v3.4.tar.gz) |
| 13 | + - SDL2 (e.g. SDL2-devel-2.0.16-mingw.tar.gz) |
| 14 | + - fdk-aac (install mingw64-x86_64-fdk-aac with cygwin-x86_64 setup) |
| 15 | + |
| 16 | +** Cross Compile x264 |
| 17 | + |
| 18 | +#+begin_src |
| 19 | + ./configure --prefix=/usr/local --host=mingw32 --cross-prefix=x86_64-w64-mingw32- --enable-shared \ |
| 20 | + --disable-win32thread --disable-asm --enable-pic |
| 21 | + make |
| 22 | + make install |
| 23 | +#+end_src |
| 24 | + |
| 25 | +** Cross Compile x265 |
| 26 | + |
| 27 | +#+begin_src |
| 28 | + cd x265/build/msys |
| 29 | + cp make-x86_64-w64-mingw32-Makefiles.sh my-make-x86_64-w64-mingw32-Makefiles.sh |
| 30 | + sed -i 's/MSYS/Unix/' my-make-x86_64-w64-mingw32-Makefiles.sh |
| 31 | + bash ./my-make-x86_64-w64-mingw32-Makefiles.sh |
| 32 | + make install |
| 33 | +#+end_src |
| 34 | + |
| 35 | +** Install SDL2 |
| 36 | +#+begin_src |
| 37 | + tar -xf SDL2-devel-2.0.16-mingw.tar.gz |
| 38 | + mkdir -p /opt/local |
| 39 | + cp -r SDL2-2.0.16/x86_64-w64-mingw32 /opt/local/ |
| 40 | +#+end_src |
| 41 | + |
| 42 | +** Cross Compile FFmpeg |
| 43 | + |
| 44 | +#+begin_src |
| 45 | + export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/opt/local/x86_64-w64-mingw32/lib/pkgconfig |
| 46 | + vim configure |
| 47 | + sdl2-config -> the absolute path of sdl2-config, e.g. /opt/local/x86_64-w64-mingw32/bin/sdl2-config |
| 48 | + # SDL2_CONFIG="${cross_prefix}sdl2-config" |
| 49 | + SDL2_CONFIG="/opt/local/x86_64-w64-mingw32/bin/sdl2-config" |
| 50 | + ./configure --enable-cross-compile --cross-prefix=x86_64-w64-mingw32- --prefix=/usr/local --arch=x86_64 \ |
| 51 | + --target-os=mingw32 --enable-libx264 --enable-libx265 --disable-w32threads --disable-os2threads \ |
| 52 | + --disable-doc --extra-ldflags="-L/usr/local/lib -L/opt/local/x86_64-w64-mingw32/lib" \ |
| 53 | + --extra-cflags="-I/usr/local/include -I/opt/local/x86_64-w64-mingw32/include" --enable-pthreads \ |
| 54 | + --enable-shared --enable-sdl --enable-libfdk-aac --enable-nonfree --enable-gpl --enable-version3 |
| 55 | + |
| 56 | + make |
| 57 | + make install |
| 58 | +#+end_src |
| 59 | + |
| 60 | +If errors in make, and it's about windres, try the following: |
| 61 | + |
| 62 | +#+begin_src |
| 63 | + x86_64-w64-mingw32-windres -I. libavcodec/avcodecres.rc libavcodec/avcodecres.o |
| 64 | + x86_64-w64-mingw32-windres -I. libavdevice/avdeviceres.rc libavdevice/avdeviceres.o |
| 65 | + x86_64-w64-mingw32-windres -I. libavfilter/avfilterres.rc libavfilter/avfilterres.o |
| 66 | + x86_64-w64-mingw32-windres -I. libavformat/avformatres.rc libavformat/avformatres.o |
| 67 | + x86_64-w64-mingw32-windres -I. libavresample/avresampleres.rc libavresample/avresampleres.o |
| 68 | + x86_64-w64-mingw32-windres -I. libavutil/avutilres.rc libavutil/avutilres.o |
| 69 | + x86_64-w64-mingw32-windres -I. libpostproc/postprocres.rc libpostproc/postprocres.o |
| 70 | + x86_64-w64-mingw32-windres -I. libswresample/swresampleres.rc libswresample/swresampleres.o |
| 71 | + x86_64-w64-mingw32-windres -I. libswscale/swscaleres.rc libswscale/swscaleres.o |
| 72 | +#+end_src |
| 73 | + |
| 74 | +If some other requirements not met, check the components in cygwin setup and install them, mingw64-x86_64- prefix first. |
| 75 | + |
| 76 | +** Make ffmpeg portable |
| 77 | + |
| 78 | +#+begin_src |
| 79 | + mkdir ffmpeg-portable |
| 80 | + cd ffmpeg-portable |
| 81 | + cp /usr/local/bin/*.dll ./ |
| 82 | + cp /usr/local/bin/{ffmpeg.exe,ffplay.exe,ffprobe.exe} ./ |
| 83 | + cp /opt/local/x86_64-w64-mingw32/bin/SDL2.dll ./ |
| 84 | + cp /usr/x86_64-w64-mingw32/sys-root/mingw/bin/libbz2-1.dll ./ |
| 85 | + cp /usr/x86_64-w64-mingw32/sys-root/mingw/bin/libfdk-aac-1.dll ./ |
| 86 | + cp /usr/x86_64-w64-mingw32/sys-root/mingw/bin/libgcc_s_seh-1.dll ./ |
| 87 | + cp /usr/x86_64-w64-mingw32/sys-root/mingw/bin/libstdc++-6.dll ./ |
| 88 | + cp /usr/x86_64-w64-mingw32/sys-root/mingw/bin/libwinpthread-1.dll ./ |
| 89 | + cp /usr/x86_64-w64-mingw32/sys-root/mingw/bin/zlib1.dll ./ |
| 90 | + |
| 91 | + zip -r -9 ffmpeg-portable.zip ffmpeg-portable |
| 92 | +#+end_src |
| 93 | + |
| 94 | +** Use it |
| 95 | +#+begin_src |
| 96 | + cd ffmpeg-portable |
| 97 | + ./ffmpeg -i xxx |
| 98 | + ./ffplay -i xxx |
| 99 | + ./ffprobe -i xxx |
| 100 | +#+end_src |
0 commit comments