How to install torchvision from source?

I’m trying to build torchvision from source in order to use its video functions.
Following the instructions in the README, I just need to do:

conda install -c conda-forge ffmpeg
python setup.py install

I have a virtual environment with ffmpeg installed through conda.
FFMPEG version:

ffmpeg version 9c33b2f Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 9.3.0 (crosstool-NG 1.24.0.133_b0863d8_dirty)
configuration: --prefix=/home/vedant/miniconda3/envs/video-rec --cc=/home/conda/feedstock_root/build_artifacts/ffmpeg_1627813612080/_build_env/bin/x86_64-conda-linux-gnu-cc --disable-doc --disable-openssl --enable-avresample --enable-gnutls --enable-gpl --enable-hardcoded-tables --enable-libfreetype --enable-libopenh264 --enable-libx264 --enable-pic --enable-pthreads --enable-shared --enable-static --enable-version3 --enable-zlib --enable-libmp3lame --pkg-config=/home/conda/feedstock_root/build_artifacts/ffmpeg_1627813612080/_build_env/bin/pkg-config
libavutil      56. 51.100 / 56. 51.100
libavcodec     58. 91.100 / 58. 91.100
libavformat    58. 45.100 / 58. 45.100
libavdevice    58. 10.100 / 58. 10.100
libavfilter     7. 85.100 /  7. 85.100
libavresample   4.  0.  0 /  4.  0.  0
libswscale      5.  7.100 /  5.  7.100
libswresample   3.  7.100 /  3.  7.100
libpostproc    55.  7.100 / 55.  7.100

After activating my environment with ffmpeg, I then build torchvision using python3 setup.py install.

However, this has 2 problems:

  1. The build output indicates that FFMPEG is not actually being used
Compiling extensions with following flags:
  WITH_CPP_MODELS_TEST: False
  FORCE_CUDA: False
  DEBUG: False
  TORCHVISION_USE_PNG: True
  TORCHVISION_USE_JPEG: True
  TORCHVISION_USE_NVJPEG: True
  TORCHVISION_USE_FFMPEG: True
  TORCHVISION_USE_VIDEO_CODEC: True
  NVCC_FLAGS: 
Found PNG library
Building torchvision with PNG image support
  libpng version: 1.6.37
  libpng include path: /home/vedant/miniconda3/envs/video-rec/include/libpng16
Running build on conda-build: False
Running build on conda: True
Building torchvision with JPEG image support
Building torchvision without NVJPEG image support
Building torchvision without ffmpeg support
Building torchvision without video codec support
running build
  1. Afterwards, I run pip show torchvision and the version is 0.13.1, even though the install output indicates I am building version: torchvision-0.14.0a0+c0ba3ec.

Anyone have thoughts on how to install torchvision from source?

I came up with this while trying to compile vision from sources, hope it works for somebody who finds the same problem, at least on any Ubuntu (and possibly Debian) installation:

For enabling jpeg, png, and ffmpeg support for vision, run:

apt install ffmpeg libavutil-dev libavcodec-dev libavformat-dev libavdevice-dev libavfilter-dev libswscale-dev libswresample-dev libswresample-dev libpostproc-dev libjpeg-dev libpng-dev