Skip to content

Commit

Permalink
Adding Mac to S3 non-GPL FFmpeg compile
Browse files Browse the repository at this point in the history
  • Loading branch information
scotts committed Sep 17, 2024
1 parent ec24944 commit da6df5c
Show file tree
Hide file tree
Showing 8 changed files with 346 additions and 36 deletions.
File renamed without changes.
84 changes: 84 additions & 0 deletions .github/workflows/macos_conda_only.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: MacOS From Source

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: |
conda install pytorch::pytorch torchvision torchaudio -c pytorch
- name: Install compile from source dependencies
run: |
conda install cmake pkg-config "ffmpeg=${{ matrix.ffmpeg-version-for-tests }}" -c conda-forge
- name: Check out repo
uses: actions/checkout@v3

- name: Install torchcodec from source
run: |
pip install -e ".[dev]" --no-build-isolation -vv
- name: Install test dependencies
run: |
conda install numpy pytest pillow
- name: Smoke test
run: |
python test/decoders/manual_smoke_test.py
- name: Run Python tests
continue-on-error: true
run: |
pytest test --capture=fd -k "test_throws_exception_at_eof" -vvv
- name: Print debug text
run: |
echo "pwd"
pwd
echo ""
echo "ls -lh"
ls -lh
echo ""
echo "cat debug.txt"
cat debug.txt
91 changes: 91 additions & 0 deletions .github/workflows/macos_wheel.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
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"
ls -lh src/torchcodec
echo ""
echo "otool -L src/torchcodec/libtorchcodec4.dylib"
otool -L src/torchcodec/libtorchcodec4.dylib
- 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 -vvv
pytest test -k "not test_throws_exception_" -vvv
7 changes: 6 additions & 1 deletion src/torchcodec/decoders/_core/VideoDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <cstdio>
#include <stdexcept>
#include <string_view>
#include <iostream>
#include "torch/types.h"

extern "C" {
Expand All @@ -21,8 +22,8 @@ extern "C" {
}

namespace facebook::torchcodec {
std::ofstream* debug = nullptr; // remove
namespace {

double ptsToSeconds(int64_t pts, int den) {
return static_cast<double>(pts) / den;
}
Expand Down Expand Up @@ -165,6 +166,7 @@ VideoDecoder::BatchDecodedOutput::BatchDecodedOutput(
VideoDecoder::VideoDecoder() {}

void VideoDecoder::initializeDecoder() {
debug = new std::ofstream("debug.txt");
// Some formats don't store enough info in the header so we read/decode a few
// frames to grab that. This is needed for the filter graph. Note: If this
// takes a long time, consider initializing the filter graph after the first
Expand Down Expand Up @@ -654,6 +656,7 @@ VideoDecoder::DecodedOutput VideoDecoder::getDecodedOutputWithFilter(
if (activeStreamIndices_.size() == 0) {
throw std::runtime_error("No active streams configured.");
}
(*debug) << "getDecodedOutputWithFilter start" << std::endl;
VLOG(9) << "Starting getNextDecodedOutputNoDemux()";
resetDecodeStats();
if (maybeDesiredPts_.has_value()) {
Expand Down Expand Up @@ -749,9 +752,11 @@ VideoDecoder::DecodedOutput VideoDecoder::getDecodedOutputWithFilter(
}
if (ffmpegStatus < AVSUCCESS) {
if (reachedEOF || ffmpegStatus == AVERROR_EOF) {
(*debug) << "throwing EOF" << std::endl;
throw VideoDecoder::EndOfFileException(
"Requested next frame while there are no more frames left to decode.");
}
(*debug) << "throwing runtime" << std::endl;
throw std::runtime_error(
"Could not receive frame from decoder: " +
getFFMPEGErrorStringFromErrorCode(ffmpegStatus));
Expand Down
4 changes: 3 additions & 1 deletion src/torchcodec/decoders/_core/VideoDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
#include <torch/types.h>
#include <cstdint>
#include <memory>
#include <iostream> // remove
#include <ostream>
#include <fstream> // remove
#include <string_view>

#include "src/torchcodec/decoders/_core/FFMPEGCommon.h"

namespace facebook::torchcodec {

extern std::ofstream* debug;
/*
The VideoDecoder class can be used to decode video frames to Tensors.
Expand Down
3 changes: 3 additions & 0 deletions src/torchcodec/decoders/_core/VideoDecoderOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "src/torchcodec/decoders/_core/VideoDecoderOps.h"
#include <pybind11/pybind11.h>
#include <cstdint>
#include <iostream>
#include <sstream>
#include <string>
#include "c10/core/SymIntArrayRef.h"
Expand Down Expand Up @@ -139,11 +140,13 @@ void seek_to_pts(at::Tensor& decoder, double seconds) {
}

OpsDecodedOutput get_next_frame(at::Tensor& decoder) {
(*debug) << "get_next_frame start" << std::endl;
auto videoDecoder = unwrapTensorToGetDecoder(decoder);
VideoDecoder::DecodedOutput result;
try {
result = videoDecoder->getNextDecodedOutputNoDemux();
} catch (const VideoDecoder::EndOfFileException& e) {
(*debug) << "catch" << std::endl;
throw pybind11::stop_iteration(e.what());
}
if (result.frame.sizes().size() != 3) {
Expand Down
Loading

0 comments on commit da6df5c

Please sign in to comment.