Build environment for Win10 64bit:
1. Download msys2-x86_64-xxx.exe from  http://www.msys2.org/
2. intall msys2 to default path C:\msys64\
3. Run MSYS2
4. execute pacman -Syu (confirm with "y" on prompt)
5, when prompted terminate shell and re-run MSYS2
6. Execute pacman -Su (confirm with "y" on prompt)
7. Run (confirm with "y" on prompts)
pacman -S make
pacman -S diffutils
pacman -S yasm
pacman -S mingw-w64-x86_64-gcc
pacman -S mingw-w64-i686-gcc
pacman -S mingw-w64-x86_64-gtk3
pacman -S mingw-w64-i686-gtk3

9. Download http://ftp.gnome.org/pub/gnome/binaries/win64/dependencies/pkg-config_0.23-2_win64.zip
10. Unzip and copy pkg-config.exe to E:\msys64\mingw64\bin
11. Download http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/pkg-config_0.26-1_win32.zip
12. Unzip and copy pkg-config.exe to E:\msys64\mingw32\bin


11. Copy  to intl.dll in two folders:

cd C:\msys64\\mingw32\bin
cp libintl-8.dll intl.dll
cd C:\msys64\\mingw64\bin
cp libintl-8.dll intl.dll


12. in E:\msys64\mingw64\x86_64-w64-mingw32\lib rename libpthread.dll.a libwinpthread.dll.a - change extension to a-org, 
13. In E:\msys64\mingw64\lib rename libbz2.dll.a libz.dll.a libiconv.dll.a liblzma.dll.a optionally libSDL.dll.a - change extension to a-org, 
14. in E:\msys64\mingw32\i686-w64-mingw32\lib rename libpthread.dll.a libwinpthread.dll.a - change extension to a-org, 
15. In E:\msys64\mingw32\lib rename libbz2.dll.a libz.dll.a libiconv.dll.a liblzma.dll.a optionally libSDL.dll.a - change extension to a-org, 


Getting source code:
1. In this directory:
2. Run E:\msys64\msys2_shell.cmd -mingw64
3. cd /e/dev/ffmpeg
4. run ./get_sourcecode


Build 64
1. Run E:\msys64\msys2_shell.cmd -mingw64
2. cd /e/dev/ffmpeg
3. ./ffmpeg-build-win release 64

Build 32
1. Run E:\msys64\msys2_shell.cmd -mingw32
2. cd /e/dev/ffmpeg
3. ./ffmpeg-build-win release 32





Build with VC++
---------------
1. Navigate to cd e:/dev/ffmpeg/ffmpeg-4.1.3
2. Edit the "configure" file, due to openSSL and zlib
NOTE: this change is not needed for mingw builds (Windows)

you should find the following code (32 & 64bit): (for openssl)
------------------------------------------------

enabled openssl           && { check_pkg_config openssl openssl openssl/ssl.h OPENSSL_init_ssl ||
                               check_pkg_config openssl openssl openssl/ssl.h SSL_library_init ||
                               check_lib	openssl		openssl/ssl.h SSL_library_init -lssl -lcrypto ||
                               check_lib	openssl		openssl/ssl.h SSL_library_init -lssl32 -leay32 ||
                               check_lib	openssl		openssl/ssl.h SSL_library_init -lssl -lcrypto -lws2_32 -lgdi32 ||
                               die "ERROR: openssl not found"; }

replace it with the code below:


For Windows:

enabled openssl           && { check_pkg_config openssl openssl openssl/ssl.h OPENSSL_init_ssl ||
                               check_pkg_config openssl openssl openssl/ssl.h SSL_library_init ||
                               check_lib	openssl		openssl/ssl.h OPENSSL_init_ssl -llibssl -llibcrypto -lzlib -lws2_32 -lgdi32 -luser32 -ladvapi32 -lcrypt32 ||
                               check_lib	openssl		openssl/ssl.h SSL_library_init -lssl -lcrypto ||
                               check_lib	openssl		openssl/ssl.h SSL_library_init -lssl32 -leay32 ||
                               check_lib	openssl		openssl/ssl.h SSL_library_init -lssl -lcrypto -lws2_32 -lgdi32 ||
                               die "ERROR: openssl not found"; }

which basically adds:
                               check_lib	openssl		openssl/ssl.h OPENSSL_init_ssl -llibssl -llibcrypto -lzlib -lws2_32 -lgdi32 -luser32 -ladvapi32 -lcrypt32 ||
to enable the check for the openssl staic library to succeed


For Linux:

enabled openssl           && { check_pkg_config openssl openssl openssl/ssl.h OPENSSL_init_ssl ||
                               check_pkg_config openssl openssl openssl/ssl.h SSL_library_init ||
                               check_lib	openssl		openssl/ssl.h OPENSSL_init_ssl -llibssl -llibcrypto -lz -lpthread -ldl ||
                               check_lib	openssl		openssl/ssl.h SSL_library_init -lssl -lcrypto ||
                               check_lib	openssl		openssl/ssl.h SSL_library_init -lssl32 -leay32 ||
                               check_lib	openssl		openssl/ssl.h SSL_library_init -lssl -lcrypto -lws2_32 -lgdi32 ||
                               die "ERROR: openssl not found"; }

which basically adds:
                               check_lib	openssl		openssl/ssl.h OPENSSL_init_ssl -llibssl -llibcrypto -lz -lpthread -ldl ||
to enable the check for the openssl staic library to succeed



Build 64 with VC++
------------------
1. Run 64 bit VC env variable command prompt
2. Navigate to E:\msys64
3. Add path to zlib
     set include=X:\dvtP4\AMF\Thirdparty\ffmpeg\ffmpeg-4.1.3\zlib\x64; %include%
     set lib=X:\dvtP4\AMF\Thirdparty\ffmpeg\ffmpeg-4.1.3\zlib\x64; %lib%
4. Add path to openssl lib
     set include=%include%;X:\dvtP4\AMF\Thirdparty\ffmpeg\ffmpeg-4.1.3\openssl\x64\include
     set lib=%lib%;X:\dvtP4\AMF\Thirdparty\ffmpeg\ffmpeg-4.1.3\openssl\x64\lib
     set path=%path%;X:\dvtP4\AMF\Thirdparty\ffmpeg\ffmpeg-4.1.3\openssl\x64\include
5. Run E:\msys64\msys2_shell.cmd -mingw64 -use-full-path
6. Navigate to cd /e/dev/ffmpeg
7. Run ./ffmpeg-build-win release 64 msvc

Build 32 with VC++
------------------
1. Run 32 bit VC env variable command prompt
2. Navigate to E:\msys64
3. Add path to zlib
     set include=X:\dvtP4\AMF\Thirdparty\ffmpeg\ffmpeg-4.1.3\zlib\x86; %include%
     set lib=X:\dvtP4\AMF\Thirdparty\ffmpeg\ffmpeg-4.1.3\zlib\x86; %lib%
4. Add path to openssl lib
     set include=%include%;X:\dvtP4\AMF\Thirdparty\ffmpeg\ffmpeg-4.1.3\openssl\x86\include
     set lib=%lib%;X:\dvtP4\AMF\Thirdparty\ffmpeg\ffmpeg-4.1.3\openssl\x86\lib
     set path=%path%;X:\dvtP4\AMF\Thirdparty\ffmpeg\ffmpeg-4.1.3\openssl\x86\include
5. For 32 bit add the following code in zlib.h: (for zlib)
     #undef ZEXPORT
     #define ZEXPORT __stdcall
   so ffmpeg will link properly with zlib
6. Run E:\msys64\msys2_shell.cmd -mingw32 -use-full-path
7. Navigate to cd /e/dev/ffmpeg
8. Run ./ffmpeg-build-win release 32 msvc


Build 64 with gcc under Linux
-----------------------------
1. add path to zlib and openssl by modifying the ffmpeg-build-linux
     extracflags='--extra-cflags=-I/home/rhuts/Desktop/ffmpeg/zlib-1.2.11/bin/lib64,-I/home/rhuts/Desktop/ffmpeg/openssl-1.1.1c/lnx64/include'
     extralinkflags='--extra-ldflags=-Wl,-rpath=$ORIGIN,-L/home/rhuts/Desktop/ffmpeg/zlib-1.2.11/bin/lib64,-L/home/rhuts/Desktop/ffmpeg/openssl-1.1.1c/lnx64/lib'
2. Run ./ffmpeg-build-linux release 64 linux


Build 32 with gcc under Linux
-----------------------------
NOTE: WITH ALL THE CHANGES, IT LOOKS LIKE THE 32 BIT LINUX BUILD STILL PRODUCESS 64 BIT CODE
--------------------------------------------------------------------------------------------
1. add path to zlib and openssl by modifying the ffmpeg-build-linux
     extracflags='--extra-cflags=-I/home/rhuts/Desktop/ffmpeg/zlib-1.2.11/bin/lib32,-I/home/rhuts/Desktop/ffmpeg/openssl-1.1.1c/lnx32/include'
     extralinkflags='--extra-ldflags=-Wl,-rpath=$ORIGIN,-L/home/rhuts/Desktop/ffmpeg/zlib-1.2.11/bin/lib32,-L/home/rhuts/Desktop/ffmpeg/openssl-1.1.1c/lnx32/lib'
2. Run ./ffmpeg-build-linux release 32 linux



Compile zlib for EXR support
----------------------------
Grab the zlib sources version 1.2.11.  (http://zlib.net/)

Windows:
1. Edit win32/Makefile.msc so that it uses -MT instead of -MD, since this is how FFmpeg is built as well.
2. Edit zconf.h and remove its inclusion of unistd.h. This gets erroneously included when building FFmpeg.
3. Run nmake -f win32/Makefile.msc.
   Alternatively, under \zlib-1.2.11\contrib\vstudio\vc14 there is a VisualStudio project for building zlib.
   I would suggest using VisualStudio as it's easier to change the settings.
   For x86, compile the ReleaseWithoutAsm - the asm code seems to be causing a crash in the openSSL unit tests
   For x64, Release version (which includes asm), passed the openSSL unit tests
4. Move zlib.lib, zconf.h, and zlib.h to somewhere MSVC can see.

Linux:
32 bit:
1. CFLAGS="-m32" ./configure --static
2. make
64 bit:
1. ./configure --static --64
2. make

(to check x86/x64 for compiled library version in Linux: "objdump -f libz.a | grep ^architecture")



Compile openssl
---------------
1. Grab the OpenSSL sources.  (https://www.openssl.org/)

OpenSSL 1.1.1

2. Read INSTALL and NOTES.WIN (or NOTES.UNIX)

3. Windows: 
   a. Download and install Perl.  
	 - Perl. We recommend ActiveState Perl, available from
	   https://www.activestate.com/ActivePerl. Another viable alternative
	   appears to be Strawberry Perl, http://strawberryperl.com.
	   You also need the perl module Text::Template, available on CPAN.
	   Please read NOTES.PERL for more information.

   b. Download and install NASM.  
	 - Netwide Assembler, a.k.a. NASM, available from https://www.nasm.us,
	   is required. Note that NASM is the only supported assembler. Even
	   though Microsoft provided assembler is NOT supported, contemporary
	   64-bit version is exercised through continuous integration of
	   VC-WIN64A-masm target.

   c. Run 32/64 bit VC env variable command prompt (depending on configuration required)

   d. Add NASM to the path
	set path=%PATH%;X:\dvtP4\AMF\Thirdparty\ffmpeg\ffmpeg-4.1.3\openssl\nasm-2.14.02


    $ perl Configure { VC-WIN32 | VC-WIN64A } 	// generate build configuration

perl Configure VC-WIN64A 
     --prefix=X:\dvtP4\AMF\Thirdparty\ffmpeg\ffmpeg-4.1.3\openssl\x64 			// where to copy the files when "nmake install" runs
     no-shared										// don't use dlls
     -static										// generate static library
     zlib 										// use zlib
     --with-zlib-include=X:\dvtP4\AMF\Thirdparty\ffmpeg\ffmpeg-4.1.3\zlib\x64 		// path to zlib include
     --with-zlib-lib=X:\dvtP4\AMF\Thirdparty\ffmpeg\ffmpeg-4.1.3\zlib\x64\zlib.lib	// full path\name to zlib static lib

perl Configure VC-WIN32 --prefix=X:\dvtP4\AMF\Thirdparty\ffmpeg\ffmpeg-4.1.3\openssl\x86 no-shared -static zlib --with-zlib-include=X:\dvtP4\AMF\Thirdparty\ffmpeg\ffmpeg-4.1.3\zlib\x86 --with-zlib-lib=X:\dvtP4\AMF\Thirdparty\ffmpeg\ffmpeg-4.1.3\zlib\x86\zlib.lib


Note: while Configure is running, it pops up a window suggesting that nmake is not in the path, and offering to download dmake. Ignore this message! If you are running a VS2015/VS2017 command window, as suggested above, nmake is certainly in your path.

notepad makefile
     replace CNF_CFLAGS=/Gs0 /GF /Gy
     with    CNF_CFLAGS=/Gs0 /GF /Gy /MT /MP
	/MT to eliminate the linking to runtime DLLs (like VCRUNTIME140.dll)
	/MP for multi-processor compilation - though I haven't seen any build performance difference than without it

for 32 bit version (64 bit was OK) the makefile requires -D"ZLIB_WINAPI" added to CNF_CPPFLAGS, otherwise the linker will complain in the end due to different calling conventions used for the zlib when created and what openssl is requesting.
     Ex: CNF_CPPFLAGS=-D"ZLIB" -D"ZLIB_WINAPI" ... (other options/defines)

    $ nmake					// build the files
    $ nmake test				// validate the build
    $ nmake install				// copy required files to specified output directory


4. Linux 
NOTE: do NOT use the "-static" flag in the command line - it builds BUT all the unit tests fail

copy the libz.a file into the directory where openssl is - even by providing the path for zlib and lib, it would not link until I put the libz.a file here: /home/rhuts/Desktop/ffmpeg/openssl-1.1.1c (obviosuly, use the 64 bit zlib for a 64 bit build and a 32bit zlib library for 32 bit build)


64 bit:
    $ ./config --prefix=/home/rhuts/Desktop/ffmpeg/openssl-1.1.1c/lnx64 no-shared zlib --with-zlib-include=/home/rhuts/Desktop/ffmpeg/zlib-1.2.11/bin/lib64 --with-zlib-lib=/home/rhuts/Desktop/ffmpeg/zlib-1.2.11/bin/lib64/libz.a '-Wl,-rpath,$(LIBRPATH)'


32 bit:
perl Configure linux-x86 -m32 --prefix=/home/rhuts/Desktop/ffmpeg/openssl-1.1.1c/lnx32 no-shared no-asm zlib --with-zlib-include=/home/rhuts/Desktop/ffmpeg/zlib-1.2.11/bin/lib32 --with-zlib-lib=/home/rhuts/Desktop/ffmpeg/zlib-1.2.11/bin/lib32/libz.a '-Wl,-rpath,$(LIBRPATH)'


    $ make					// build the files
    $ make test					// validate the build
    $ make install				// copy required files to specified output directory
