Add HEIC decoder #5129
Workflow file for this run
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
| name: Linux CPU x86 | ||
| 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: | ||
| generate-matrix: | ||
| uses: pytorch/test-infra/.github/workflows/generate_binary_build_matrix.yml@main | ||
| with: | ||
| package-type: wheel | ||
| os: linux | ||
| test-infra-repository: pytorch/test-infra | ||
| test-infra-ref: main | ||
| with-xpu: disable | ||
| with-rocm: disable | ||
| with-cuda: disable | ||
| build-python-only: "disable" | ||
| build: | ||
| needs: generate-matrix | ||
| strategy: | ||
| fail-fast: false | ||
| name: Build and Upload wheel | ||
| uses: pytorch/test-infra/.github/workflows/build_wheels_linux.yml@main | ||
| with: | ||
| repository: meta-pytorch/torchcodec | ||
| ref: "" | ||
| test-infra-repository: pytorch/test-infra | ||
| test-infra-ref: main | ||
| build-matrix: ${{ needs.generate-matrix.outputs.matrix }} | ||
| pre-script: packaging/pre_build_script.sh | ||
| post-script: packaging/post_build_script.sh | ||
| smoke-test-script: packaging/fake_smoke_test.py | ||
| package-name: torchcodec | ||
| trigger-event: ${{ github.event_name }} | ||
| build-platform: "python-build-package" | ||
| build-command: "BUILD_AGAINST_ALL_FFMPEG_FROM_S3=1 python -m build --wheel -vvv --no-isolation" | ||
| also-upload-to-gpu-arch-versions: "xpu" | ||
| install-and-test: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| python-version: ['3.10'] | ||
| ffmpeg-version-for-tests: ['4', '5', '6', '7', '8'] | ||
| needs: build | ||
| steps: | ||
| - name: Check out repo | ||
| uses: actions/checkout@v6 | ||
| - name: Remove src/ folder | ||
| run: bash packaging/remove_src.sh | ||
| - name: Setup conda env | ||
| uses: conda-incubator/setup-miniconda@v3 | ||
| with: | ||
| auto-update-conda: true | ||
| # Using miniforge instead of miniconda ensures that the default | ||
| # conda channel is conda-forge instead of main/default. This ensures | ||
| # ABI consistency between dependencies: | ||
| # https://conda-forge.org/docs/user/transitioning_from_defaults/ | ||
| miniforge-version: latest | ||
| activate-environment: test | ||
| python-version: ${{ matrix.python-version }} | ||
| - name: Update pip | ||
| run: python -m pip install --upgrade pip | ||
| - name: Install PyTorch | ||
| run: bash packaging/install_pytorch.sh cpu "torch torchvision" | ||
| - uses: actions/download-artifact@v4 | ||
| with: | ||
| name: meta-pytorch_torchcodec__${{ matrix.python-version }}_cpu_x86_64 | ||
| path: dist/ | ||
| - name: Install torchcodec from the wheel | ||
| run: bash packaging/install_torchcodec_wheel.sh | ||
| - name: Install ffmpeg, post build | ||
| run: bash packaging/install_ffmpeg.sh ${{ matrix.ffmpeg-version-for-tests }} | ||
| - name: Install test dependencies | ||
| run: bash packaging/install_test_dependencies.sh | ||
| - name: Run Python tests | ||
| run: | | ||
| FAIL_WITHOUT_JPEG=1 FAIL_WITHOUT_PNG=1 FAIL_WITHOUT_WEBP=1 FAIL_WITHOUT_AVIF=1 FAIL_WITHOUT_HEIC=1 pytest --override-ini="addopts=-v" test | ||
| install-and-test-no-ffmpeg: | ||
| # Asserts that torchcodec works WITHOUT FFmpeg installed: the package must | ||
| # import, the FFmpeg-free image decoders must work, and the FFmpeg-backed | ||
| # entry points must fail with a clear error. | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| python-version: ['3.10'] | ||
| needs: build | ||
| steps: | ||
| - name: Check out repo | ||
| uses: actions/checkout@v6 | ||
| - name: Remove src/ folder | ||
| run: bash packaging/remove_src.sh | ||
| - name: Setup conda env | ||
| uses: conda-incubator/setup-miniconda@v3 | ||
| with: | ||
| auto-update-conda: true | ||
| miniforge-version: latest | ||
| activate-environment: test | ||
| python-version: ${{ matrix.python-version }} | ||
| - name: Update pip | ||
| run: python -m pip install --upgrade pip | ||
| - name: Install PyTorch | ||
| run: bash packaging/install_pytorch.sh cpu "torch torchvision" | ||
| - uses: actions/download-artifact@v4 | ||
| with: | ||
| name: meta-pytorch_torchcodec__${{ matrix.python-version }}_cpu_x86_64 | ||
| path: dist/ | ||
| - name: Install torchcodec from the wheel | ||
| run: bash packaging/install_torchcodec_wheel.sh | ||
| - name: Install test dependencies | ||
| run: bash packaging/install_test_dependencies.sh | ||
| # Deliberately NO "Install ffmpeg" step here. | ||
| - name: Assert FFmpeg is absent and torchcodec still imports | ||
| run: | | ||
| source packaging/helpers.sh | ||
| assert_ffmpeg_not_installed | ||
| python -c "import torchcodec; from torchcodec._core import ops; assert not ops._FFMPEG_AVAILABLE, 'FFmpeg was unexpectedly loaded'; print('OK: torchcodec imported without FFmpeg')" | ||
| - name: Run FFmpeg-free Python tests | ||
| run: | | ||
| FAIL_WITHOUT_JPEG=1 FAIL_WITHOUT_PNG=1 FAIL_WITHOUT_WEBP=1 FAIL_WITHOUT_AVIF=1 FAIL_WITHOUT_HEIC=1 \ | ||
| pytest --override-ini="addopts=-v" test/test_ffmpeg_optional.py test/test_decoders.py::TestImageDecoder | ||
| install-and-test-no-heic: | ||
| # Asserts the optional-libheif guarantee: with libheif NOT installed, | ||
| # torchcodec must still import and decode every other format, and only an | ||
| # actual HEIC decode should fail (with an actionable ImportError). | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| python-version: ['3.10'] | ||
| ffmpeg-version-for-tests: ['7'] | ||
| needs: build | ||
| steps: | ||
| - name: Check out repo | ||
| uses: actions/checkout@v6 | ||
| - name: Remove src/ folder | ||
| run: bash packaging/remove_src.sh | ||
| - name: Setup conda env | ||
| uses: conda-incubator/setup-miniconda@v3 | ||
| with: | ||
| auto-update-conda: true | ||
| miniforge-version: latest | ||
| activate-environment: test | ||
| python-version: ${{ matrix.python-version }} | ||
| - name: Update pip | ||
| run: python -m pip install --upgrade pip | ||
| - name: Install PyTorch | ||
| run: bash packaging/install_pytorch.sh cpu "torch torchvision" | ||
| - uses: actions/download-artifact@v4 | ||
| with: | ||
| name: meta-pytorch_torchcodec__${{ matrix.python-version }}_cpu_x86_64 | ||
| path: dist/ | ||
| - name: Install torchcodec from the wheel | ||
| run: bash packaging/install_torchcodec_wheel.sh | ||
| - name: Install ffmpeg, post build | ||
| run: bash packaging/install_ffmpeg.sh ${{ matrix.ffmpeg-version-for-tests }} | ||
| # Deliberately install test deps WITHOUT libheif. | ||
| - name: Install test dependencies (no libheif) | ||
| run: TORCHCODEC_TEST_WITHOUT_HEIC=1 bash packaging/install_test_dependencies.sh | ||
| - name: Assert HEIC tests are skipped, and the rest still pass | ||
| run: | | ||
| # heic_is_available() is False, so needs_heic tests skip; every other | ||
| # image decoder is still required. | ||
| FAIL_WITHOUT_JPEG=1 FAIL_WITHOUT_PNG=1 FAIL_WITHOUT_WEBP=1 FAIL_WITHOUT_AVIF=1 \ | ||
| pytest --override-ini="addopts=-v" test/test_decoders.py::TestImageDecoder | ||
| - name: Assert decode_heic raises an actionable error without libheif | ||
| run: | | ||
| python -c "import torchcodec; print('OK: torchcodec imported without libheif')" | ||
| python -c " | ||
| import torch | ||
| from torchcodec.decoders._image_decoders import decode_heic | ||
| from test.utils import HEIC_TEST_FILES | ||
| heic = HEIC_TEST_FILES[0] | ||
| try: | ||
| decode_heic(str(heic.path)) | ||
| raise SystemExit('decode_heic should have raised without libheif') | ||
| except ImportError as e: | ||
| assert 'libheif' in str(e), str(e) | ||
| print('OK: decode_heic raised an actionable ImportError') | ||
| " | ||
| install-and-test-no-ffmpeg: | ||
| # Asserts that torchcodec works WITHOUT FFmpeg installed: the package must | ||
| # import, the FFmpeg-free image decoders must work, and the FFmpeg-backed | ||
| # entry points must fail with a clear error. | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| python-version: ['3.10'] | ||
| needs: build | ||
| steps: | ||
| - name: Check out repo | ||
| uses: actions/checkout@v6 | ||
| - name: Remove src/ folder | ||
| run: bash packaging/remove_src.sh | ||
| - name: Setup conda env | ||
| uses: conda-incubator/setup-miniconda@v3 | ||
| with: | ||
| auto-update-conda: true | ||
| miniforge-version: latest | ||
| activate-environment: test | ||
| python-version: ${{ matrix.python-version }} | ||
| - name: Update pip | ||
| run: python -m pip install --upgrade pip | ||
| - name: Install PyTorch | ||
| run: bash packaging/install_pytorch.sh cpu "torch torchvision" | ||
| - uses: actions/download-artifact@v4 | ||
| with: | ||
| name: meta-pytorch_torchcodec__${{ matrix.python-version }}_cpu_x86_64 | ||
| path: dist/ | ||
| - name: Install torchcodec from the wheel | ||
| run: bash packaging/install_torchcodec_wheel.sh | ||
| - name: Install test dependencies | ||
| run: bash packaging/install_test_dependencies.sh | ||
| # Deliberately NO "Install ffmpeg" step here. | ||
| - name: Assert FFmpeg is absent and torchcodec still imports | ||
| run: | | ||
| source packaging/helpers.sh | ||
| assert_ffmpeg_not_installed | ||
| python -c "import torchcodec; from torchcodec._core import ops; assert not ops._FFMPEG_AVAILABLE, 'FFmpeg was unexpectedly loaded'; print('OK: torchcodec imported without FFmpeg')" | ||
| - name: Run FFmpeg-free Python tests | ||
| run: | | ||
| FAIL_WITHOUT_JPEG=1 FAIL_WITHOUT_PNG=1 FAIL_WITHOUT_WEBP=1 FAIL_WITHOUT_AVIF=1 \ | ||
| pytest --override-ini="addopts=-v" test/test_ffmpeg_optional.py test/test_decoders.py::TestImageDecoder | ||
| install-and-test-third-party-interface: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| python-version: ['3.10'] | ||
| ffmpeg-version-for-tests: ['8'] | ||
| needs: build | ||
| steps: | ||
| - name: Check out repo | ||
| uses: actions/checkout@v3 | ||
| - name: Remove src/ folder | ||
| run: bash packaging/remove_src.sh | ||
| - name: Setup conda env | ||
| uses: conda-incubator/setup-miniconda@v3 | ||
| with: | ||
| auto-update-conda: true | ||
| # Using miniforge instead of miniconda ensures that the default | ||
| # conda channel is conda-forge instead of main/default. This ensures | ||
| # ABI consistency between dependencies: | ||
| # https://conda-forge.org/docs/user/transitioning_from_defaults/ | ||
| miniforge-version: latest | ||
| activate-environment: test | ||
| python-version: ${{ matrix.python-version }} | ||
| - name: Update pip | ||
| run: python -m pip install --upgrade pip | ||
| - name: Install PyTorch | ||
| run: bash packaging/install_pytorch.sh cpu "torch torchvision" | ||
| - uses: actions/download-artifact@v4 | ||
| with: | ||
| name: meta-pytorch_torchcodec__${{ matrix.python-version }}_cpu_x86_64 | ||
| path: dist/ | ||
| - name: Install torchcodec from the wheel | ||
| run: bash packaging/install_torchcodec_wheel.sh | ||
| - name: Install ffmpeg, post build | ||
| run: bash packaging/install_ffmpeg.sh ${{ matrix.ffmpeg-version-for-tests }} | ||
| - name: Install pkg-config | ||
| run: | | ||
| conda install pkg-config -c conda-forge | ||
| - name: Install test dependencies | ||
| run: bash packaging/install_test_dependencies.sh | ||
| - name: Run Python tests | ||
| run: | | ||
| pytest --override-ini="addopts=-v" test/third-party-interface | ||