Skip to content

Build and use GPU-enabled FFmpeg in doc CI #3045

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 47 additions & 3 deletions .github/workflows/build_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ jobs:
export PYTHON_VERSION="${{ matrix.python_version }}"
export CU_VERSION="${{ matrix.cuda_arch_version }}"
export CUDATOOLKIT="pytorch-cuda=${CU_VERSION}"
export CODEC_HEADER_VERSION=n11.1.5.2
export COMPUTE_CAPABILITY=86

# Set CHANNEL
if [[(${GITHUB_EVENT_NAME} = 'pull_request' && (${GITHUB_BASE_REF} = 'release'*)) || (${GITHUB_REF} = 'refs/heads/release'*) ]]; then
Expand All @@ -49,6 +51,50 @@ jobs:
conda create --quiet -y --prefix ci_env python="${PYTHON_VERSION}"
conda activate ./ci_env

# Install FFmpeg-dependencies
conda install --quiet -y -c conda-forge yasm x264 gnutls pkg-config lame libopus libvpx openh264 openssl x264

# Build FFmpeg with NVIDIA Video Codec SDK
# TODO cache this
(
git clone --quiet https://git.videolan.org/git/ffmpeg/nv-codec-headers.git
cd nv-codec-headers
git checkout ${CODEC_HEADER_VERSION}
make PREFIX=${CONDA_PREFIX} install
)

(
wget -q https://github.com/FFmpeg/FFmpeg/archive/refs/tags/n5.1.3.tar.gz
tar -xf n5.1.3.tar.gz
cd ./FFmpeg-n5.1.3
export revision=5.1.3
./configure \
--prefix=${CONDA_PREFIX} \
--extra-cflags="-I${CONDA_PREFIX}/include" \
--extra-ldflags="-L${CONDA_PREFIX}/lib" \
--nvccflags="-gencode arch=compute_${COMPUTE_CAPABILITY},code=sm_${COMPUTE_CAPABILITY} -O2" \
--disable-doc \
--enable-rpath \
--disable-static \
--enable-protocol=https \
--enable-gnutls \
--enable-shared \
--enable-gpl \
--enable-nonfree \
--enable-libmp3lame \
--enable-libx264 \
--enable-cuda-nvcc \
--enable-nvenc \
--enable-cuvid \
--enable-nvdec
make clean
make -j > /dev/null 2>&1
make install
# test
src="https://download.pytorch.org/torchaudio/tutorial-assets/stream-api/NASAs_Most_Scientifically_Complex_Space_Observatory_Requires_Precision-MP4_small.mp4"
ffmpeg -y -vsync 0 -hwaccel cuvid -hwaccel_output_format cuda -c:v h264_cuvid -resize 360x240 -i "${src}" -c:a copy -c:v h264_nvenc -b:v 5M test.mp4
)

# Install PyTorch
set -ex
set +u # don't know why
Expand All @@ -60,14 +106,12 @@ jobs:
"${CUDATOOLKIT}"

# Install torchaudio
# TODO: Enable NVDec/NVEnc
conda install --quiet -y -c conda-forge 'ffmpeg>=5.0,<6' pkg-config
pip --quiet install cmake>=3.18.0 ninja
cd packaging
. ./pkg_helpers.bash
setup_build_version
cd ../
USE_FFMPEG=1 pip install --progress-bar off -v -e . --no-use-pep517
FFMPEG_ROOT=${CONDA_PREFIX} USE_FFMPEG=1 USE_CUDA=1 pip install --progress-bar off -v -e . --no-use-pep517

# Install runtime dependencies
pip --quiet install git+https://github.com/kpu/kenlm/ flashlight-text
Expand Down