Saturday 3 May 2014

Building FFmpeg on Windows with in-line asm and the Intel compiler (Part 3).

Previously I have posted about efforts to build FFmpeg natively under windows with inline assembly enabled and using the Intel compiler:

Building FFmpeg on Windows with in-line asm and the Intel compiler.
Building FFmpeg on Windows with in-line asm and the Intel compiler (Part 2).

After many months of patching, testing and review the current upstream FFmpeg master is now fully updated to support inline asm compilation with Intel compiler. This means that my patches do not need to be explicitly applied as now the default FFmpeg repository has been updated to include all my changes. So now those people who have access to the Intel compiler on Windows can build FFmpeg using the latest source and will automatically have all the hand-tuned assembly optimizations built in without any extra effort.

For those interested in testing it out they can grab the latest FFmpeg source from their git master. Normally FFmepg must be built through MSYS/Cygwin on Windows so if your not that way inclined you can also check out my repository which includes a copy of FFmpeg master with some additional visual studio project files added in. With these you can now compile FFmpeg natively directly through Visual Studio.

Building FFmpeg in Visual Studio.

These changes are all part of work designed to improve the state of FFmpeg on Windows. Also added to upstream FFmpeg are patches to enable OpenCL support with native win32 threads as well as several patches for dependency library linking errors (libvpx, libssh to name a few). It took a little while to get all these patches approved (asm patches to upstream libmpcodecs took a particularly long time) but as of this morning the libmpcodec changes were pulled into mainstream FFmpeg which was the last change required for full icl support. A big shout out to Michael Niedermayer for reviewing and providing useful feedback on all the patches. He was a big help in pointing me in the right direction and for spotting all my mistakes (a side affect of me writing and submitting many of the patches in the wee hours of the morning).

As always you can grab the code from my repository and feel free to post any bugs/errors you may encounter.
https://github.com/ShiftMediaProject/FFmpeg

7 comments:

  1. Do you have intentions to update to use Visual Studio 2013 now that C99 support has been incorporated?

    ReplyDelete
    Replies
    1. Visual Studio 2013 is already supported. FFmpeg already detects availability of used C99 features and has fall backs if not found. So ive been using 2013 as default for some time now.

      Delete
  2. I have been trying the ShiftMediaProject repositories to build a full-featured FFmpeg with VS2013 (x64 output). Using project_generate.exe built from source to setup. The projects work great for most 90% of the projejcts, but with the ffmpeg libraries (libavcodec, libavfilter, etc.) there are problems with inline __asm__ not working. Clearly the devs use Intel compilers primarily, which is great, but this is a bit challenging with VS2013. I've had to manually turn off HAVE_INLINE_ASM in FFmpegs's SMC/config.h to get it to build. Also, either hacking a bunch of libmpcodec source or turning off HAVE_MMX was necessary. And I'm still having trouble with linking for the ff*.exe projects. Any suggestions for how to do this right for VS2013? Use fewer third party libraries perhaps. Thanks for your great contributions! BTW, I've built all these targets with MSVC via MSYS, but with far fewer libraries linked in. I haven't had a chance to see how it deals with inline asm.

    ReplyDelete
    Replies
    1. Im the FFmpeg maintainer for intel compiler which is why the ffmpeg projects default to use the intel compiler. Previously the mpcodec source should not have been included with a msvc build as it didnt compile properly as msvc doesnt support inline asm (as you have found out) which suggest to me that your generating projects with the icl setting. The default projects are icl (Intel compiler) and the batch file for project_generate also defaults to icl. So to build for Visual Studio you need to change the toolchain parameter to: --toolchain=msvc. If your using the batch file then just change --toolchain=icl to msvc and it will generate a Visual Studio compiler compatible version automatically. That said I recently pushed a patch to upstream FFmepg that makes libmpcodecs work with msvc so that problem shouldnt exist anymore anyway. Also the SMC/config.h header should detect the intel compiler and disable inline asm if not detected so not sure why you were getting errors. I did a msvc build this morning using --toolchain=msvc and it worked fine so if your still having problems let me know.

      Delete
    2. Also the default projects in the repo are now msvc instead of icl (as of right now) and there are 2 project_generate batch files for creating either msvc or icl projects. So give that a shot. The only thing missing from ShiftMediaProject is OpenCL and SDL libs. You can grab OpenCL sdks from either Intel or AMD (the Nvidia ones dont support required OpenCL version) and SDL binaries can be directly grabbed from the SDL site (must be version 1). If you couldnt be bothered with either of these just delete the --enable-opencl and/or --enable-sdl from the batch file and then regenerate the projects (note: ffplay requires sdl so it will be removed if sdl is disabled). The project_generator is still kinda beta so once its been further tested I will be making a full post about its use and the project.

      Delete
  3. This comment has been removed by the author.

    ReplyDelete
  4. I think I checked out just before revision 67973:
    https://github.com/ShiftMediaProject/FFmpeg/commit/0b3c23054279fe49ed550735a34cfbed67ce68cd#diff-e2d5a00791bce9a01f99bc6fd613a39d
    "configure: Enable mpcodec compilation without inline asm."
    I'll give it a try now. Thanks again for this great project!

    ReplyDelete