From 88b301be7fee5de2231ca40ecda83164cd5064e8 Mon Sep 17 00:00:00 2001 From: Scott Schneider Date: Wed, 11 Sep 2024 12:38:04 -0700 Subject: [PATCH] Adding Mac to S3 non-GPL FFmpeg compile --- .../{wheel.yaml => linux_wheel.yaml} | 0 .github/workflows/macos_wheel.yaml | 90 +++++++++ ...fetch_and_expose_non_gpl_ffmpeg_libs.cmake | 180 +++++++++++++++--- 3 files changed, 241 insertions(+), 29 deletions(-) rename .github/workflows/{wheel.yaml => linux_wheel.yaml} (100%) create mode 100644 .github/workflows/macos_wheel.yaml diff --git a/.github/workflows/wheel.yaml b/.github/workflows/linux_wheel.yaml similarity index 100% rename from .github/workflows/wheel.yaml rename to .github/workflows/linux_wheel.yaml diff --git a/.github/workflows/macos_wheel.yaml b/.github/workflows/macos_wheel.yaml new file mode 100644 index 00000000..2ea9de96 --- /dev/null +++ b/.github/workflows/macos_wheel.yaml @@ -0,0 +1,90 @@ +name: Build and test MacOS + +on: + pull_request: + push: + branches: + - nightly + - main + - release/* + tags: + - v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+ + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref_name }}-${{ github.ref_type == 'branch' && github.sha }}-${{ github.event_name == 'workflow_dispatch' }} + cancel-in-progress: true + +permissions: + id-token: write + contents: write + +defaults: + run: + shell: bash -l -eo pipefail {0} + +jobs: + install-and-test: + runs-on: macos-m1-stable + strategy: + fail-fast: false + matrix: + python-version: ['3.9'] + ffmpeg-version-for-tests: ['4.4.2', '5.1.2', '6.1.1', '7.0.1'] + if: ${{ always() }} + steps: + - name: Setup conda env + uses: conda-incubator/setup-miniconda@v3 + with: + auto-update-conda: true + miniconda-version: "latest" + activate-environment: test + python-version: ${{ matrix.python-version }} + - name: Update pip + run: python -m pip install --upgrade pip + - name: Install PyTorch + run: | + python -m pip install --pre torch --index-url https://download.pytorch.org/whl/nightly/cpu + - name: Check out repo + uses: actions/checkout@v3 + - name: Install compile from source dependencies + run: | + conda install cmake pkg-config -c conda-forge + - name: Install test dependencies + run: | + python -m pip install --pre torchvision --index-url https://download.pytorch.org/whl/nightly/cpu + # Ideally we would find a way to get those dependencies from pyproject.toml + python -m pip install numpy pytest pillow + - name: Install torchcodec from source, building against non-GPL FFmpeg + run: | + BUILD_AGAINST_ALL_FFMPEG_FROM_S3=1 pip install -e ".[dev]" --no-build-isolation + - name: Inspect dir + run: | + echo "pwd" + pwd + echo "" + echo "ls -lh" + ls -lh + echo "" + echo "ls -lh src/torchcodec" + echo "" + echo "otool -L src/torchcodec/libtorchcodec4.dylib" + otool -L src/torchcodec/libtorchcodec4.dylib + ls -lh src/torchcodec + - name: Install ffmpeg, post build + run: | + # Ideally we would have checked for that before installing the wheel, + # but we need to checkout the repo to access this file, and we don't + # want to checkout the repo before installing the wheel to avoid any + # side-effect. It's OK. + source packaging/helpers.sh + assert_ffmpeg_not_installed + + conda install "ffmpeg=${{ matrix.ffmpeg-version-for-tests }}" -c conda-forge + ffmpeg -version + - name: Smoke test + run: | + python test/decoders/manual_smoke_test.py + - name: Run Python tests + run: | + pytest test diff --git a/src/torchcodec/decoders/_core/fetch_and_expose_non_gpl_ffmpeg_libs.cmake b/src/torchcodec/decoders/_core/fetch_and_expose_non_gpl_ffmpeg_libs.cmake index 1c35791c..d932ab31 100644 --- a/src/torchcodec/decoders/_core/fetch_and_expose_non_gpl_ffmpeg_libs.cmake +++ b/src/torchcodec/decoders/_core/fetch_and_expose_non_gpl_ffmpeg_libs.cmake @@ -8,33 +8,150 @@ if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0") endif() include(FetchContent) + set( base_url - https://pytorch.s3.amazonaws.com/torchcodec/ffmpeg/2024-06-11/linux_x86_64 + https://pytorch.s3.amazonaws.com/torchcodec/ffmpeg/2024-09-08 ) + +if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") + set( + platform_url + ${base_url}/linux_x86_64 + ) + + set( + f4_hash + c920e8064878b8d10648ee440659878974363374d08f1edb17f1ac435ca3afbf + ) + set( + f5_hash + 39f70050338616dd0dee461bbb0e7ea1f68d80693310182efb8acceded5e84e8 + ) + set( + f6_hash + c1c08d796b177f566a9650d8e945e62925041f95d6016fd4266d6337ae782444 + ) + set( + f7_hash + 18a00d44f45cd57a8fe1ca32397496f17c9f359492a536cb2d46c6494a1d4b17 + ) + + set( + f4_library_file_names + libavutil.so.56 + libavcodec.so.58 + libavformat.so.58 + libavdevice.so.58 + libavfilter.so.7 + ) + set( + f5_library_file_names + libavutil.so.57 + libavcodec.so.59 + libavformat.so.59 + libavdevice.so.59 + libavfilter.so.8 + ) + set( + f6_library_file_names + libavutil.so.58 + libavcodec.so.60 + libavformat.so.60 + libavdevice.so.60 + libavfilter.so.9 + ) + set( + f7_library_file_names + libavutil.so.59 + libavcodec.so.61 + libavformat.so.61 + libavdevice.so.61 + libavfilter.so.10 + ) +elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") + set( + platform_url + ${base_url}/macos_arm64 + ) + set( + f4_hash + 8d4e2ee26b6b65eb520402189aea11534fb39aecfb2f01232d96fedd5cd16e94 + ) + set( + f5_hash + 79cdfe9c04b480dcaff0deb61aba60d88681918e8bc6f7de27c751c77622f436 + ) + set( + f6_hash + a5f37393ef17617bea4844a1423a945cbcff145c69281dc70dc31db09282cc8a + ) + set( + f7_hash + e9ea739e5fc5f14741324f2b9ccbfe92f13e574f2cbad49488ba88a8ad8f4d49 + ) + set( + f4_library_file_names + libavutil.56.dylib + libavcodec.58.dylib + libavformat.58.dylib + libavdevice.58.dylib + libavfilter.7.dylib + ) + set( + f5_library_file_names + libavutil.57.dylib + libavcodec.59.dylib + libavformat.59.dylib + libavdevice.59.dylib + libavfilter.8.dylib + ) + set( + f6_library_file_names + libavutil.58.dylib + libavcodec.60.dylib + libavformat.60.dylib + libavdevice.60.dylib + libavfilter.9.dylib + ) + set( + f7_library_file_names + libavutil.59.dylib + libavcodec.61.dylib + libavformat.61.dylib + libavdevice.61.dylib + libavfilter.10.dylib + ) +else() + message( + FATAL_ERROR + "Unsupported operating system: ${CMAKE_SYSTEM_NAME}" + ) +endif() + FetchContent_Declare( f4 - URL ${base_url}/ffmpeg_4.4.4.tar.gz + URL ${platform_url}/4.4.4.tar.gz URL_HASH - SHA256=a564721e51038d01ead4bbc7a482398929101ca4c80e5ce5c42042637235a297 + SHA256=${f4_hash} ) FetchContent_Declare( f5 - URL ${base_url}/ffmpeg_5.1.4.tar.gz + URL ${platform_url}/5.1.4.tar.gz URL_HASH - SHA256=d9c2d3a355c091ddc3205ae73426d0d6402ad8a31212dc920daabbaa5fdae944 + SHA256=${f5_hash} ) FetchContent_Declare( f6 - URL ${base_url}/ffmpeg_6.1.1.tar.gz + URL ${platform_url}/6.1.1.tar.gz URL_HASH - SHA256=7ee5830dc09fed7270aa575650474ab16e18477551e5511f256ce92daa30b136 + SHA256=${f6_hash} ) FetchContent_Declare( f7 - URL ${base_url}/ffmpeg_7.0.1.tar.gz + URL ${platform_url}/7.0.1.tar.gz URL_HASH - SHA256=fa4cda7aa67fcd58428017f7ebd2a981b0c6babba7ec89f71d6840877712ddcd + SHA256=${f7_hash} ) FetchContent_MakeAvailable(f4 f5 f6 f7) @@ -50,39 +167,44 @@ target_include_directories(ffmpeg5 INTERFACE ${f5_SOURCE_DIR}/include) target_include_directories(ffmpeg6 INTERFACE ${f6_SOURCE_DIR}/include) target_include_directories(ffmpeg7 INTERFACE ${f7_SOURCE_DIR}/include) +list( + TRANSFORM f4_library_file_names + PREPEND ${f4_SOURCE_DIR}/lib/ + OUTPUT_VARIABLE f4_library_paths +) +list( + TRANSFORM f5_library_file_names + PREPEND ${f5_SOURCE_DIR}/lib/ + OUTPUT_VARIABLE f5_library_paths +) +list( + TRANSFORM f6_library_file_names + PREPEND ${f6_SOURCE_DIR}/lib/ + OUTPUT_VARIABLE f6_library_paths +) +list( + TRANSFORM f7_library_file_names + PREPEND ${f7_SOURCE_DIR}/lib/ + OUTPUT_VARIABLE f7_library_paths +) + target_link_libraries( ffmpeg4 INTERFACE - ${f4_SOURCE_DIR}/lib/libavutil.so.56 - ${f4_SOURCE_DIR}/lib/libavcodec.so.58 - ${f4_SOURCE_DIR}/lib/libavformat.so.58 - ${f4_SOURCE_DIR}/lib/libavdevice.so.58 - ${f4_SOURCE_DIR}/lib/libavfilter.so.7 + ${f4_library_paths} ) target_link_libraries( ffmpeg5 INTERFACE - ${f5_SOURCE_DIR}/lib/libavutil.so.57 - ${f5_SOURCE_DIR}/lib/libavcodec.so.59 - ${f5_SOURCE_DIR}/lib/libavformat.so.59 - ${f5_SOURCE_DIR}/lib/libavdevice.so.59 - ${f5_SOURCE_DIR}/lib/libavfilter.so.8 + ${f5_library_paths} ) target_link_libraries( ffmpeg6 INTERFACE - ${f6_SOURCE_DIR}/lib/libavutil.so.58 - ${f6_SOURCE_DIR}/lib/libavcodec.so.60 - ${f6_SOURCE_DIR}/lib/libavformat.so.60 - ${f6_SOURCE_DIR}/lib/libavdevice.so.60 - ${f6_SOURCE_DIR}/lib/libavfilter.so.9 + ${f6_library_paths} ) target_link_libraries( ffmpeg7 INTERFACE - ${f7_SOURCE_DIR}/lib/libavutil.so.59 - ${f7_SOURCE_DIR}/lib/libavcodec.so.61 - ${f7_SOURCE_DIR}/lib/libavformat.so.61 - ${f7_SOURCE_DIR}/lib/libavdevice.so.61 - ${f7_SOURCE_DIR}/lib/libavfilter.so.10 + ${f7_library_paths} )