pytorch / vision

Datasets, Transforms and Models specific to Computer Vision
https://pytorch.org/vision
BSD 3-Clause "New" or "Revised" License
15.99k stars 6.92k forks source link

Building FFmpeg binaries for Windows #2688

Open andfoy opened 3 years ago

andfoy commented 3 years ago

Discussion

Context

Right now, as part of PRs https://github.com/pytorch/vision/pull/2683 and https://github.com/pytorch/vision/pull/2596, we intend to include the FFmpeg binaries on or wheel distributions. Due to the software licensing nature of FFmpeg (GPL), we started to build our own LGPL FFmpeg binaries on the PyTorch builder repo, based off the conda-forge recipe

Problems

  1. Building and distributing FFmpeg While Linux and Mac builds can be done from source and they are working, Windows builds depend on a binary distribution repository for FFmpeg, namely, Zeranoe FFmpeg builds, which will be deprecated after the 18th of September of 2020 (The day of the opening of this discussion), that implies that we need to start compiling LGPL binaries for Windows.

  2. FFmpeg dependencies While compiling FFmpeg is feasible by using MinGW-w64 and MSYS2, some of the libraries required to compile it, such as OpenH264, iconv and others are not available for Windows in any Anaconda channel, both defaults nor conda-forge, therefore we need also to tackle those packages as well.

Solution options

  1. Cross compile FFmpeg and distribute the binaries (Zeranoe-like) We can setup a new binary distribution repository where we can distribute LGPL binaries for Windows to replace the Zeranoe one. In order to compile the binaries, we can "easily" cross-compile FFmpeg and all of the downstream libraries on Linux and package them. I've built FFmpeg locally on linux by using MXE, and we could set a Docker image to do so. I've done some tests using this repository: https://github.com/andfoy/ffmpeg-win-lgpl, for redistributing those packages. Note: This solution fixes also the problem with the FFmpeg downstream binaries

  2. Compile the downstream libraries and FFmpeg directly on conda-build While this is an adequate solution, we would need to update the recipes on conda-build for the dependencies that we need for compiling FFmpeg, such as OpenH264, libiconv and others, then ask the Anaconda team to update the corresponding packages on defaults and then update our FFmpeg build recipe for Windows in order to compile FFmpeg using MinGW-w64.

Additional context

We need to take into account potential patent licensing issues regarding OpenH264 specifically. According to the OpenH264 FAQ and the following conda-forge issues: https://github.com/conda-forge/openh264-feedstock/issues/5, https://github.com/conda-forge/ffmpeg-feedstock/issues/66. We should download Cisco OpenH264 binaries directly each time the library is installed, since the patent fee that Cisco pays can only apply when using their binaries instead of ours.

Regarding the conda recipe, we can use a post-install script to handle this case, however, for the wheels, we need a mechanism to download Cisco OpenH264 when installing it. In Windows this shouldn't be a problem, since DLLs do not require an rpath and just require dependencies to be on the PATH, whereas on Linux and Mac this requires updating of the rpath of the video_reader.so/dylib libraries.

Other resources

Here is the same issue regarding the Windows source compilation on conda-forge: https://github.com/conda-forge/ffmpeg-feedstock/issues/90

cc @peterjc123 @nbcsm @guyang3532 @maxluk @gunandrose4u @smartcat2010 @mszhanyi @fmassa @seemethere

peterjc123 commented 3 years ago

@andfoy What extra work is needed here?

andfoy commented 3 years ago

I've just opened a PR on builder, it is only missing some minor details regarding the conda recipe, however I've been progressing slow on that since I don't have SSH permission there

andfoy commented 3 years ago

@peterjc123 https://github.com/pytorch/builder/pull/544