Build ffmpeg-master #35
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| env: | |
| MSYS2_PATH_TYPE: inherit | |
| SDK_VER: 10.0.22621.0 | |
| REF_NAME: ${{ inputs.ref_name||github.ref_name }} | |
| name: Build | |
| run-name: Build ${{inputs.ref_name||github.ref_name}} | |
| on: | |
| push: | |
| branches: | |
| - ffmpeg-master | |
| workflow_call: | |
| inputs: | |
| ref_name: | |
| description: "Tag" | |
| required: false | |
| type: string | |
| release_name: | |
| description: "Custom release name" | |
| required: false | |
| type: string | |
| changelog: | |
| description: "Custom changelog content" | |
| required: false | |
| type: string | |
| jobs: | |
| prepare: | |
| uses: ./.github/workflows/cache.yml | |
| with: | |
| ref_name: ${{inputs.ref_name||github.ref_name}} | |
| build: | |
| needs: prepare | |
| strategy: | |
| matrix: | |
| arch: [amd64, arm64] | |
| fail-fast: false | |
| runs-on: windows-2022 | |
| env: | |
| name: ffmpeg-${{ inputs.ref_name||github.ref_name }}-gpl-${{matrix.arch}}-static | |
| release_name: ffmpeg-gpl-${{matrix.arch}}-static | |
| target: ${{contains(matrix.arch,'arm')&&format('amd64_{0}',matrix.arch)||matrix.arch}} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{env.REF_NAME}} | |
| # submodules: recursive | |
| - name: Setup Env | |
| shell: bash | |
| id: setup | |
| run: | | |
| echo "installationPath=$(vswhere -all -legacy -property installationPath)">>$GITHUB_OUTPUT | |
| # KEY=$(git ls-tree -r ${{env.REF_NAME}}|grep ^160000|sort -d|md5sum|cut -d' ' -f1) | |
| # echo "cache-key=$KEY" >>$GITHUB_OUTPUT | |
| - name: Restore cached submodules | |
| id: cache-submodules-restore | |
| uses: actions/cache@v4 | |
| with: | |
| path: .git/modules | |
| # key: ${{ runner.os }}-${{steps.setup.outputs.cache-key}}-submodules | |
| key: ${{ needs.prepare.outputs.cache-key }} | |
| - name: Pull submodules | |
| shell: bash | |
| run: | | |
| git submodule update --init --recursive --depth 1 | |
| - uses: msys2/setup-msys2@v2 | |
| with: | |
| install: >- | |
| diffutils | |
| make | |
| zip | |
| pkgconf | |
| yasm | |
| nasm | |
| libtool | |
| bison | |
| automake | |
| autoconf | |
| quilt | |
| clang | |
| - name: Setup Python for Meson | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.x" | |
| - name: Install Meson and Ninja | |
| shell: cmd | |
| run: | | |
| pip install meson ninja | |
| - name: Install Vulkan SDK | |
| uses: jakoch/install-vulkan-sdk-action@v1 | |
| with: | |
| install_runtime: true | |
| cache: false | |
| optional_components: com.lunarg.vulkan.arm64 | |
| - name: Test Vulkan Installation | |
| shell: cmd | |
| run: | | |
| echo Vulkan Installation Check: | |
| echo ============================ | |
| echo VULKAN_SDK: %VULKAN_SDK% | |
| echo. | |
| echo Directory Structure: | |
| echo =================== | |
| echo VULKAN root subdirectories: | |
| dir "%VULKAN_SDK%" /b /ad | |
| echo. | |
| echo Checking for x64 lib directory: | |
| if exist "%VULKAN_SDK%\Lib" ( | |
| echo x64 lib directory found, contents: | |
| dir "%VULKAN_SDK%\Lib" /b /ad | |
| ) | |
| echo. | |
| echo Checking for arm64 lib directory: | |
| if exist "%VULKAN_SDK%\Lib-ARM64" ( | |
| echo arm64 lib directory found, contents: | |
| dir "%VULKAN_SDK%\Lib-ARM64" /b /ad | |
| ) | |
| echo. | |
| echo Header Files: | |
| if exist "%VULKAN_SDK%\Include\vulkan\vulkan.h" ( | |
| echo vulkan.h: FOUND | |
| ) else ( | |
| echo vulkan.h: NOT FOUND | |
| ) | |
| echo. | |
| echo Library Directories: | |
| if exist "%VULKAN_SDK%\Lib" ( | |
| echo x64 Lib: FOUND | |
| ) else ( | |
| echo x64 Lib: NOT FOUND | |
| ) | |
| if exist "%VULKAN_SDK%\Lib-ARM64" ( | |
| echo ARM64 Lib: FOUND | |
| ) else ( | |
| echo ARM64 Lib: NOT FOUND | |
| ) | |
| echo. | |
| echo Key Libraries: | |
| if exist "%VULKAN_SDK%\Lib\vulkan-1.lib" ( | |
| echo x64 vulkan-1.lib: FOUND | |
| ) else ( | |
| echo x64 vulkan-1.lib: NOT FOUND | |
| ) | |
| if exist "%VULKAN_SDK%\Lib-ARM64\vulkan-1.lib" ( | |
| echo ARM64 vulkan-1.lib: FOUND | |
| ) else ( | |
| echo ARM64 vulkan-1.lib: NOT FOUND | |
| ) | |
| - name: Install CUDA Toolkit | |
| if: matrix.arch == 'amd64' | |
| uses: N-Storm/cuda-toolkit@master | |
| id: cuda-toolkit | |
| with: | |
| cuda: "12.6.3" | |
| sub-packages: '["nvcc", "cudart", "npp_dev"]' | |
| - name: Test CUDA Installation | |
| if: matrix.arch == 'amd64' | |
| shell: cmd | |
| run: | | |
| CALL "${{steps.setup.outputs.installationPath}}\VC\Auxiliary\Build\vcvarsall.bat" ${{env.target}} ${{env.SDK_VER}} | |
| echo CUDA Installation Check: | |
| echo ======================== | |
| echo CUDA_PATH: %CUDA_PATH% | |
| nvcc --version | findstr "release" | |
| echo. | |
| echo Directory Structure: | |
| echo =================== | |
| echo CUDA root subdirectories: | |
| dir "%CUDA_PATH%" /b /ad | |
| echo. | |
| echo Checking for lib directory: | |
| if exist "%CUDA_PATH%\lib" ( | |
| echo lib directory found, contents: | |
| dir "%CUDA_PATH%\lib" /b /ad | |
| ) | |
| echo. | |
| echo Searching for .lib files: | |
| dir "%CUDA_PATH%" /s /b 2>nul | findstr /i "\.lib$" | |
| echo. | |
| echo Searching for NPP headers: | |
| dir "%CUDA_PATH%" /s /b 2>nul | findstr /i "npp.*\.h$" | |
| echo. | |
| echo NPP Libraries Check: | |
| if exist "%CUDA_PATH%\lib\x64\nppc.lib" ( | |
| echo nppc.lib: FOUND | |
| ) else ( | |
| echo nppc.lib: NOT FOUND | |
| ) | |
| if exist "%CUDA_PATH%\include\npp.h" ( | |
| echo npp.h: FOUND | |
| ) else ( | |
| echo npp.h: NOT FOUND | |
| ) | |
| echo. | |
| echo CUDA Compilation Test: | |
| echo __global__ void test() {} > test.cu | |
| nvcc -c test.cu -o test.obj | |
| if exist test.obj ( | |
| echo CUDA compilation test: PASSED | |
| del test.obj test.cu | |
| ) else ( | |
| echo CUDA compilation test: FAILED | |
| exit 1 | |
| ) | |
| - name: Remove MSYS2 link | |
| shell: msys2 {0} | |
| run: | | |
| rm $(which link) | |
| rm -rf /usr/local | |
| - name: Build dav1d | |
| if: ${{ success() }} | |
| shell: cmd | |
| run: | | |
| CALL "${{steps.setup.outputs.installationPath}}\VC\Auxiliary\Build\vcvarsall.bat" ${{env.target}} ${{env.SDK_VER}} | |
| REM Add MSYS2 tools (nasm, yasm) to PATH | |
| set PATH=D:\a\_temp\msys64\usr\bin;%PATH% | |
| REM Build dav1d (AV1 decoder) | |
| echo Building dav1d... | |
| cd dav1d | |
| REM Create cross-file for ARM64 builds | |
| if "${{matrix.arch}}" == "arm64" ( | |
| echo [binaries] > cross.txt | |
| echo c = 'cl' >> cross.txt | |
| echo ar = 'lib' >> cross.txt | |
| echo [host_machine] >> cross.txt | |
| echo system = 'windows' >> cross.txt | |
| echo cpu_family = 'aarch64' >> cross.txt | |
| echo cpu = 'aarch64' >> cross.txt | |
| echo endian = 'little' >> cross.txt | |
| REM Disable assembly for ARM64 cross-compilation | |
| meson setup build --cross-file cross.txt --prefix=D:\a\_temp\msys64\usr\local --buildtype=release --default-library=static -Denable_tools=false -Denable_tests=false -Denable_asm=false -Db_vscrt=mt | |
| ) else ( | |
| meson setup build --prefix=D:\a\_temp\msys64\usr\local --buildtype=release --default-library=static -Denable_tools=false -Denable_tests=false -Db_vscrt=mt | |
| ) | |
| if %errorlevel% neq 0 exit /b %errorlevel% | |
| meson compile -C build | |
| if %errorlevel% neq 0 exit /b %errorlevel% | |
| meson install -C build | |
| if %errorlevel% neq 0 exit /b %errorlevel% | |
| REM Meson installs as libdav1d.a, but FFmpeg expects dav1d.lib | |
| REM Copy the library with both naming conventions | |
| if exist D:\a\_temp\msys64\usr\local\lib\libdav1d.a ( | |
| echo Found static library: D:\a\_temp\msys64\usr\local\lib\libdav1d.a | |
| copy D:\a\_temp\msys64\usr\local\lib\libdav1d.a D:\a\_temp\msys64\usr\local\lib\dav1d.lib | |
| copy D:\a\_temp\msys64\usr\local\lib\libdav1d.a D:\a\_temp\msys64\usr\local\lib\libdav1d.lib | |
| ) else ( | |
| echo ERROR: Static library libdav1d.a not found! | |
| exit /b 1 | |
| ) | |
| cd .. | |
| - name: Build zimg | |
| if: ${{ success() }} | |
| shell: cmd | |
| run: | | |
| CALL "${{steps.setup.outputs.installationPath}}\VC\Auxiliary\Build\vcvarsall.bat" ${{env.target}} ${{env.SDK_VER}} | |
| echo Applying zimg patch (ignoring errors if already applied)... | |
| git apply --ignore-whitespace "%CD%\patches\zimg.patch" || ver > nul | |
| REM Build zimg using MSBuild | |
| echo Building zimg... | |
| cd zimg\_msvc | |
| REM Determine platform for MSBuild | |
| if "${{matrix.arch}}" == "arm64" ( | |
| set PLATFORM=ARM64 | |
| ) else ( | |
| set PLATFORM=x64 | |
| ) | |
| MSBuild zimg\zimg.vcxproj -p:Configuration=Release -p:Platform=%PLATFORM% | |
| if %errorlevel% neq 0 exit /b %errorlevel% | |
| REM Install headers | |
| if not exist D:\a\_temp\msys64\usr\local\include\zimg mkdir D:\a\_temp\msys64\usr\local\include\zimg | |
| copy ..\src\zimg\api\zimg.h D:\a\_temp\msys64\usr\local\include\zimg\ | |
| REM The path to the created library is relative to the vcxproj | |
| set LIB_PATH=zimg\%PLATFORM%\Release\z.lib | |
| REM Install the library | |
| if not exist D:\a\_temp\msys64\usr\local\lib mkdir D:\a\_temp\msys64\usr\local\lib | |
| if exist %LIB_PATH% ( | |
| echo Found static library: %LIB_PATH% | |
| copy "%LIB_PATH%" D:\a\_temp\msys64\usr\local\lib\zimg.lib | |
| copy "%LIB_PATH%" D:\a\_temp\msys64\usr\local\lib\libzimg.lib | |
| ) else ( | |
| echo ERROR: Static library z.lib not found at %LIB_PATH%! | |
| exit /b 1 | |
| ) | |
| REM Create pkg-config file | |
| if not exist D:\a\_temp\msys64\usr\local\lib\pkgconfig mkdir D:\a\_temp\msys64\usr\local\lib\pkgconfig | |
| ( | |
| echo prefix=/usr/local | |
| echo exec_prefix=${prefix} | |
| echo libdir=${exec_prefix}/lib | |
| echo includedir=${prefix}/include | |
| echo. | |
| echo Name: zimg | |
| echo Description: Scaling, colorspace conversion, and dithering library | |
| echo Version: 3.0 | |
| echo Libs: -L${libdir} -lzimg | |
| echo Cflags: -I${includedir}/zimg | |
| ) > D:\a\_temp\msys64\usr\local\lib\pkgconfig\zimg.pc | |
| cd ..\.. | |
| - name: Build LAME | |
| if: ${{ success() }} | |
| shell: cmd | |
| run: | | |
| CALL "${{steps.setup.outputs.installationPath}}\VC\Auxiliary\Build\vcvarsall.bat" ${{env.target}} ${{env.SDK_VER}} | |
| REM Build LAME MP3 encoder | |
| echo Building LAME... | |
| cd lame | |
| REM Copy configMS.h to config.h | |
| copy configMS.h config.h | |
| REM Set architecture-specific options and machine type | |
| if "${{matrix.arch}}" == "arm64" ( | |
| REM Patch Makefile.MSVC to use correct machine type for ARM64 | |
| powershell -Command "(Get-Content Makefile.MSVC) -replace 'MACHINE = /machine:I386', 'MACHINE = /machine:ARM64' | Set-Content Makefile.MSVC" | |
| ) else ( | |
| REM Patch Makefile.MSVC to use correct machine type for x64 | |
| powershell -Command "(Get-Content Makefile.MSVC) -replace 'MACHINE = /machine:I386', 'MACHINE = /machine:X64' | Set-Content Makefile.MSVC" | |
| ) | |
| REM Also remove obsolete compiler flags that cause warnings | |
| powershell -Command "(Get-Content Makefile.MSVC) -replace '/QIfdiv /QI0f /YX', '' | Set-Content Makefile.MSVC" | |
| REM Build static library only (no frontend) using documented approach | |
| REM comp=msvc ensures we use Microsoft compiler | |
| REM asm=no disables assembly optimizations (safer for cross-compilation) | |
| REM CFG=RH uses Robert's optimizations (default) | |
| nmake -f Makefile.MSVC comp=msvc asm=no libmp3lame-static.lib | |
| if %errorlevel% neq 0 exit /b %errorlevel% | |
| REM Install headers and library | |
| if not exist D:\a\_temp\msys64\usr\local\include\lame mkdir D:\a\_temp\msys64\usr\local\include\lame | |
| copy include\lame.h D:\a\_temp\msys64\usr\local\include\lame\ | |
| if not exist D:\a\_temp\msys64\usr\local\lib mkdir D:\a\_temp\msys64\usr\local\lib | |
| REM Copy library with both naming conventions for maximum compatibility | |
| if exist output\libmp3lame-static.lib ( | |
| echo Found static library: output\libmp3lame-static.lib | |
| copy output\libmp3lame-static.lib D:\a\_temp\msys64\usr\local\lib\libmp3lame.lib | |
| copy output\libmp3lame-static.lib D:\a\_temp\msys64\usr\local\lib\mp3lame.lib | |
| copy output\libmp3lame-static.lib D:\a\_temp\msys64\usr\local\lib\lame.lib | |
| ) else ( | |
| echo ERROR: Static library libmp3lame-static.lib not found! | |
| exit /b 1 | |
| ) | |
| REM Create pkg-config file - use absolute path for MSVC compatibility | |
| if not exist D:\a\_temp\msys64\usr\local\lib\pkgconfig mkdir D:\a\_temp\msys64\usr\local\lib\pkgconfig | |
| ( | |
| echo prefix=/usr/local | |
| echo exec_prefix=${prefix} | |
| echo libdir=${exec_prefix}/lib | |
| echo includedir=${prefix}/include | |
| echo. | |
| echo Name: libmp3lame | |
| echo Description: LAME MP3 encoding library | |
| echo Version: 3.100 | |
| echo Libs: -LD:/a/_temp/msys64/usr/local/lib -lmp3lame | |
| echo Cflags: -I${includedir}/lame | |
| ) > D:\a\_temp\msys64\usr\local\lib\pkgconfig\libmp3lame.pc | |
| cd .. | |
| - name: Build | |
| shell: cmd | |
| run: | | |
| CALL "${{steps.setup.outputs.installationPath}}\VC\Auxiliary\Build\vcvarsall.bat" ${{env.target}} ${{env.SDK_VER}} | |
| msys2 -c "export CUDA_PATH=\"$CUDA_PATH\" VULKAN_SDK=\"$VULKAN_SDK\"; ./build.sh ${{matrix.arch}}" | |
| - name: Debug log | |
| if: ${{ failure() }} | |
| shell: bash | |
| run: | | |
| echo [Debug] | |
| cat FFmpeg/ffbuild/config.log | |
| cat FFmpeg/ffbuild/config.mak | |
| cat FFmpeg/config.h | |
| - name: Pack | |
| shell: msys2 {0} | |
| run: | | |
| CWD=$(pwd) | |
| cd /usr/local | |
| # # Add SDK libraries to the package | |
| # mkdir -p sdk | |
| # # Add Vulkan SDK libraries (architecture-specific) | |
| # if [[ -n "$VULKAN_SDK" && -d "$VULKAN_SDK" ]]; then | |
| # echo "Adding Vulkan SDK libraries..." | |
| # mkdir -p sdk/vulkan | |
| # cp -r "$VULKAN_SDK/Include" sdk/vulkan/ 2>/dev/null || true | |
| # if [[ "${{matrix.arch}}" == "arm64" ]]; then | |
| # cp -r "$VULKAN_SDK/Lib-ARM64" sdk/vulkan/Lib/ 2>/dev/null || true | |
| # else | |
| # cp -r "$VULKAN_SDK/Lib" sdk/vulkan/ 2>/dev/null || true | |
| # fi | |
| # # Add Vulkan runtime DLLs | |
| # cp -r "$VULKAN_SDK/runtime" sdk/vulkan/ 2>/dev/null || true | |
| # cp -r "$VULKAN_SDK/Bin" sdk/vulkan/ 2>/dev/null || true | |
| # fi | |
| # # Add CUDA SDK libraries (x64 only) | |
| # if [[ "${{matrix.arch}}" == "amd64" && -n "$CUDA_PATH" && -d "$CUDA_PATH" ]]; then | |
| # echo "Adding CUDA SDK libraries..." | |
| # mkdir -p sdk/cuda | |
| # cp -r "$CUDA_PATH/include" sdk/cuda/ 2>/dev/null || true | |
| # cp -r "$CUDA_PATH/lib/x64" sdk/cuda/lib/ 2>/dev/null || true | |
| # # Add CUDA runtime DLLs | |
| # cp -r "$CUDA_PATH/bin" sdk/cuda/ 2>/dev/null || true | |
| # fi | |
| zip -9 ${CWD}/${{env.name}}.zip -r . | |
| cd ${CWD} | |
| sha1sum ${{env.name}}.zip >${{env.name}}.sha1 | |
| - name: Generate changelog | |
| shell: bash | |
| run: | | |
| # Use custom changelog if provided, otherwise generate from git commits | |
| if [ -n "${{ inputs.changelog }}" ]; then | |
| echo "${{ inputs.changelog }}" > changelog | |
| else | |
| echo "Generating changelog from git commits..." | |
| # For autobuild tags, find the previous autobuild tag | |
| # For other tags, find the previous tag of any kind | |
| if [[ "${{env.REF_NAME}}" == autobuild-* ]]; then | |
| LAST_TAG=$(git tag -l 'autobuild-*' | grep -v "^${{env.REF_NAME}}$" | sort -V | tail -n 1) | |
| else | |
| LAST_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "") | |
| fi | |
| { | |
| echo "## Changes" | |
| echo "" | |
| if [ -z "$LAST_TAG" ]; then | |
| echo "Showing last 10 commits:" | |
| echo "" | |
| git log -10 --pretty=format:"- %s (%h)" --no-merges | |
| else | |
| echo "Changes since $LAST_TAG:" | |
| echo "" | |
| CHANGELOG=$(git log ${LAST_TAG}..HEAD --pretty=format:"- %s (%h)" --no-merges) | |
| if [ -z "$CHANGELOG" ]; then | |
| echo "No new commits since last tag" | |
| else | |
| echo "$CHANGELOG" | |
| fi | |
| fi | |
| } > changelog | |
| fi | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{env.name}} | |
| path: | | |
| ${{env.name}}.zip | |
| ${{env.name}}.sha1 | |
| changelog | |
| retention-days: 30 | |
| - name: Prepare release files | |
| if: ${{ inputs.release_name != '' }} | |
| shell: bash | |
| run: | | |
| # Rename files for release | |
| cp ${{env.name}}.zip ${{env.release_name}}.zip | |
| cp ${{env.name}}.sha1 ${{env.release_name}}.sha1 | |
| - name: Release | |
| if: ${{ inputs.release_name != '' }} | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{env.REF_NAME}} | |
| name: ${{ inputs.release_name }} | |
| body_path: changelog | |
| prerelease: ${{contains(env.REF_NAME,'dev')}} | |
| files: | | |
| ${{env.release_name}}.zip | |
| ${{env.release_name}}.sha1 |