次の方法で共有


Building FFmpeg for Windows with HTTPS/TLS support

I’ve been working and contributing to a few open source projects for the last couple of years. When I started, we wanted to focus on pieces that we believed were some of the building blocks that developers would want to use to build Windows apps. The three that I’ve personally focused on were CMake, OpenSSL and FFmpeg. Recently I was asked to see how to play an https link through FFmpeg. Well, it just happens that in order to playback secure content, FFmpeg leverages OpenSSL. Great, I’ve worked on both projects and they can both be used from a UWP application. This should have been simple, unfortunately not, we had a fairly focused instructions and scripts to build each project, but they were fairly different, required a lot of tools setup and were not very easy to extend. At the same time, VS2017 had been released as well as the Windows 10 Creator’s Update and the work to get all these puzzle pieces aligned properly for our customers began to look like a daunting task. After a bunch of hacking, I was able to get things working; it felt like a house of cards though.

Then last week, I get another request, “Can you please update OpenSSL to the 1.0.2l release? We’re trying to update our drop.” This was coming from the VCPkg team. We had had meetings together a while ago, but had lost touch. I was in for quite a surprise when I synched up with them on what they were doing. They were enabling some of the core open-source projects to built and used in a much more seamless way than what I was used to. When I saw their demo, I was sold. Easy builds without having to manually setup an environment for each project (they take care of that for you), automatic reference of the built projects from your own projects (no need to change include/lib paths), easy dependency resolution and the option to create packages to distribute. As I walked back to my office, I couldn’t help but think about how this could make my life so much easier and from the transitive property of ease, other windows developers. My first project was clear: get FFmpeg with OpenSSL support building in VS2017. I had already spent quite some time trying to get all this working with some very complicated instructions that if I could simplify things, it could only been better for everyone.

I got myself setup and the first hurdle that I found was that VCPkg supported FFmpeg for Desktop but not as a UWP. Challenge accepted. There were instructions, I had done it many times, they were leveraging CMake as their scripting language as well to setup the proper build environment. Overall, these were all things that I was very comfortable with. It didn’t take long, and I had a first build of FFmpeg for UWP built through VCPkg. That was quite encouraging, I did run into some roadblocks but having done this before, I could at least compare the work that we had done before with the current work when running under VCPkg and try to isolate the differences. I spent a little time over the weekend and got my UWP build of FFmpeg completely automated and integrated with VCPkg. Now for the second challenge: Getting it built with OpenSSL support to handle HTTPS/TLS. Thanks to some quite detailed documentation, it was not hard to specify that I wanted FFmpeg to have a dependency on OpenSSL, make a small FFmpeg patch to detect OpenSSL on Windows in this new environment and voila! I’ve got a build of FFmpeg that includes support for secure contents. Now came time for the actual test: does this all work as expected?

I had enabled the VS integration for VCPkg, so I started by taking our FFmpegInterop project and removed all the customizations necessary to reference FFmpeg (no more extra include paths, no more adding dlls as content). Once everything was cleaned and the project looked like a simple project, I was able to build it, still referencing FFmpeg headers and linking against the libs without having to have the project know anything about FFmpeg (even less OpenSSL). The second modification was to remove the FFmpeg dlls from the actual application that was using FFmpegInterop. Final steps, build, run and open an https link. Everything worked as promised. Mission accomplished.

Trying it out:

The steps to run this are actually quite simple.

Clone my fork of the vcpkg project (until the code gets upstream)

git clone https://github.com/khouzam/vcpkg -b ffmpeg-opensslcd vcpkgbootstrap-vcpkg.bat (to build the VC package manager)

vcpkg integrate install (from an admin command prompt to have Visual Studio integration).

vcpkg install ffmpeg:x86-uwp ffmpeg:x64-uwp ffmpeg:arm-uwp ffmpeg:x86-windows ffmpeg:x64-windows (If you don't have CMake installed, you will be prompted to install it).

You can select which flavors of builds you are looking for by choosing the different architecture or platform combination (uwp for store apps and windows for desktop apps). Notice how OpenSSL is automatically built and referenced when you build FFmpeg. Once completed you will get all the built binaries in your vcpkg\installed with the different architectures.

As you can see, this can be much easier than following some of the manual steps needed to build either OpenSSL or FFmpeg for Windows.