1@rem Copyright 2024 Huawei Technologies Co., Ltd 2@rem 3@rem Licensed under the Apache License, Version 2.0 (the "License"); 4@rem you may not use this file except in compliance with the License. 5@rem You may obtain a copy of the License at 6@rem 7@rem http://www.apache.org/licenses/LICENSE-2.0 8@rem 9@rem Unless required by applicable law or agreed to in writing, software 10@rem distributed under the License is distributed on an "AS IS" BASIS, 11@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12@rem See the License for the specific language governing permissions and 13@rem limitations under the License. 14@rem ============================================================================ 15@echo off 16 17echo Start compile FFmpeg software at: %date% %time% 18 19SET MINGW64_NAME="mingw64.exe" 20SET PROCESS_NAME=mintty.exe 21SET TEMP_FILE="temp.txt" 22 23where %MINGW64_NAME% > %TEMP_FILE% 24if errorlevel 1 ( 25 echo The software 'MSYS2' is not installed, please refer to the link https://www.mindspore.cn/install to install it first. 26 EXIT /b 1 27) 28SET /p file_path=<%TEMP_FILE% 29del %TEMP_FILE% 30 31SET MSYS64_PATH=%file_path:~0,-12% 32SET FFMPEG_DLL_SOURCE_PATH=%MSYS64_PATH%\home\ffmpeg\install_ffmpeg_lib\bin 33SET FFMPEG_COMPILE_SOURCE_PATH=%MSYS64_PATH%\home\ffmpeg\install_ffmpeg_lib 34SET FFMPEG_DLL_PATH=%BASE_PATH%\build\mindspore\ffmpeg_lib 35SET FFMPEG_ERROR_LOG=%MSYS64_PATH%\home\ffmpeg\ffbuild\config.log 36 37 38SET SOFTWARE_NAME=FFmpeg 39SET SOFTWARE_VERSION=5.1.2 40SET FFMPEG_GITHUB_DOWNLOAD_PATH=https://ffmpeg.org/releases/ffmpeg-%SOFTWARE_VERSION%.tar.gz 41SET FFMPEG_MINDSPORE_DOWNLOAD_PATH=https://tools.mindspore.cn/libs/ffmpeg/ffmpeg-%SOFTWARE_VERSION%.tar.gz 42SET FFMPEG_DOWNLOAD_PATH=%FFMPEG_MINDSPORE_DOWNLOAD_PATH% 43SET FFMPEG_COMPILATION_OPTIONS=--disable-programs --disable-doc --disable-postproc --disable-libxcb --disable-hwaccels --disable-static --enable-shared --disable-decoder=av1 --toolchain=msvc 44SET FFMPEG_SHA256_CONTEXT=%SOFTWARE_NAME%-%SOFTWARE_VERSION%-%FFMPEG_GITHUB_DOWNLOAD_PATH%-%FFMPEG_MINDSPORE_DOWNLOAD_PATH%-%FFMPEG_COMPILATION_OPTIONS% 45SET FFMPEG_LIB_NAME=avcodec-avdevice-avfilter-avformat-avutil-swresample-swscale 46 47 48IF "%ENABLE_FFMPEG_DOWNLOAD%"=="ON" ( 49 SET FFMPEG_DOWNLOAD_PATH=%FFMPEG_MINDSPORE_DOWNLOAD_PATH% 50) ELSE ( 51 SET FFMPEG_DOWNLOAD_PATH=%FFMPEG_GITHUB_DOWNLOAD_PATH% 52) 53 54 55pushd %MSYS64_PATH% 56 57rem calculate the hash value of the ffmpeg cache 58SET HASH_TEMP_FILE="hash_temp.txt" 59SET HASH_FILE="hash_file.txt" 60echo %FFMPEG_SHA256_CONTEXT% > %HASH_FILE% 61certutil -hashfile "%HASH_FILE%" SHA256 > %HASH_TEMP_FILE% 62 63for /f "skip=1 delims=" %%i in (hash_temp.txt) do ( 64 SET OUT_HASH_VALUE=%%i 65 goto :endloop 66) 67:endloop 68echo Finish calculate sha256 69 70echo The hash value of FFmpeg is: %OUT_HASH_VALUE% 71del %HASH_TEMP_FILE% 72del %HASH_FILE% 73 74SET FFMPEG_CACHE_DIR=%MSYS64_PATH%\home\mslib\%SOFTWARE_NAME%_%SOFTWARE_VERSION%_%OUT_HASH_VALUE% 75echo Get cache dir is: %FFMPEG_CACHE_DIR% 76 77rem Check whether the cache directory exists 78IF EXIST %FFMPEG_CACHE_DIR% ( 79 echo The cache file: %FFMPEG_CACHE_DIR% is exist 80 call :dll_file_exist 81 if errorlevel 1 ( 82 echo Checking DLL file failed 83 rd /s /q %FFMPEG_CACHE_DIR% 84 mkdir %FFMPEG_CACHE_DIR% 85 ) else ( 86 echo Checking DLL file success 87 xcopy %FFMPEG_CACHE_DIR% %FFMPEG_DLL_PATH% /E /I /Y 88 popd 89 echo End cache FFmpeg software at: %date% %time% 90 EXIT /b 0 91 ) 92) ELSE ( 93 echo The cache file is not exist, need to recompile. 94 mkdir %FFMPEG_CACHE_DIR% 95) 96 97 98rem Execute compilation 99start cmd /c "msys2_shell.cmd -mingw64 -no-start -c 'cd /home; rm -rf ffmpeg; mkdir ffmpeg; cd /home/ffmpeg; wget %FFMPEG_DOWNLOAD_PATH%; tar -xzvf ffmpeg-%SOFTWARE_VERSION%.tar.gz; mkdir build; mkdir install_ffmpeg_lib; cd build; ../ffmpeg-%SOFTWARE_VERSION%/configure --prefix=/home/ffmpeg/install_ffmpeg_lib %FFMPEG_COMPILATION_OPTIONS%; make -j4; make install'" 100 101 102ping 127.0.0.1 -n 10 >nul 103echo Start compile FFmpeg. Please wait a moment. 104echo ... 105 106:LOOP 107tasklist | findstr /i "%PROCESS_NAME%" >nul 108if errorlevel 1 ( 109 echo The process %PROCESS_NAME% is not running. 110 goto :END_LOOP 111) 112ping 127.0.0.1 -n 5 >nul 113goto LOOP 114 115:END_LOOP 116echo FFmpeg compile is ended. Continuing the next processing 117 118 119 120xcopy %FFMPEG_COMPILE_SOURCE_PATH% %FFMPEG_DLL_PATH% /E /I /Y 121xcopy %FFMPEG_COMPILE_SOURCE_PATH% %FFMPEG_CACHE_DIR% /E /I /Y 122 123call :dll_file_exist 124if errorlevel 1 ( 125 echo FFmpeg compile failed. Please check the file %FFMPEG_ERROR_LOG% for detailed error messages. 126 rd /s /q %FFMPEG_CACHE_DIR% 127 EXIT /b 1 128) else ( 129 echo FFmpeg compile success 130) 131 132popd 133 134echo End complie FFmpeg software at: %date% %time% 135EXIT /b 0 136 137:dll_file_exist 138 for %%a in ("%FFMPEG_LIB_NAME:-=" "%") do ( 139 echo Checking for %%a... 140 141 if exist "%FFMPEG_CACHE_DIR%\bin\%%a*.dll" ( 142 echo The file %%a is found in %FFMPEG_CACHE_DIR% 143 ) else ( 144 echo The file %%a is not found in %FFMPEG_CACHE_DIR% 145 EXIT /b 1 146 ) 147 )