Saturday, 25 January 2014

Building FFmpeg in Visual Studio

The default build chain for the FFmpeg project uses the standard (well standard for gnu open source projects) gnu autotools. The use of configure and make may be rather familiar to those who compile often on linux but for many Windows developers these can seem like somewhat alien tools. This is compounded by the fact that to use these tools on Windows requires setting up a MSYS/Cygwin environment which can often be easier said than done. Even after that most build chains using this environment require a gcc based compiler which on Windows is MinGW. Gcc is a good compiler but MinGW can have some issues (which in its defence is generally always around Windows specific things) which can make it less than ideal.

FFmpegs default build tools do currently support compiling natively in msvc (Microsoft's C compiler) and will even convert the C99 FFmpeg code to msvc compliant C89 code. But this still requires setting up a MSYS shell and any additional FFmpeg dependencies don't offer msvc support from within the same build tools.

So as powerful as the configure/make build chains can be and say what you like about the msvc compiler (I agree its standards compliance is abysmal) but for those wanting to develop natively on Windows having Visual Studio support is the simplest and most robust. Since FFmpeg wont maintain a native Visual Studio build chain (and I cant blame them for not wanting to), I got a little bored and decided to take it upon myself to provide an alternative.

The result of some holiday free time is that I wrote up a FFmpeg Visual Studio project generator. This is a simple piece of software that will scan in the existing FFmpeg configure/make files and then use those to dynamically generate a visual studio project file that can be used to natively compile FFmpeg. This program not only builds the project files but will also generate the config files dynamically based on a combination of rules found in the original configure script and any passed in arguments. In fact the generator excepts many of the same configuration arguments as the configure script allowing fine-tuned control of what gets enabled/disabled.
Example command line options:

ffmpeg_generator.exe --enable-gpl --enable-bzlib --enable-iconv 
   --enable-zlib --disable-encoders --enable-encoder=vorbis

The program doesn't support all the options of the configure script but it supports many of them and in some cases actually exposes more than the original. Any option that shows up in the config.h file can be manually enabled/disabled through the command line. And even if an invalid option is set the generator uses all the inbuilt configuration checks found in the original build script to automatically validate each setting. Options such as 32/64bit are some of the options that are not supported, mainly because they are not relevant as the generated config.h file can be used for both 32/64 bit and even detects and enables inline asm if the Intel compiler is made available.

#define ARCH_X86 1
#if defined( __x86_64 ) || defined( _M_X64 )
#   define ARCH_X86_32 0
#else
#   define ARCH_X86_32 1
#endif

All of this happens dynamically so for those building from git master, once any commits are and added to your repo you just have to rerun the generator program and it will automatically detect any changes (new/deleted files, configuration changes, new/deleted options etc.) and generate a new project accordingly.

Now I should point out that this generator was rather quickly (and half-assed) thrown together so its not exactly very brilliant code. But for something quick and dirty it gets the job done. It supports all current additional dependencies but not all have been checked and it takes certain liberties with respect to library naming. This is because many dependency libraries don't have consistent naming conventions so the link include the generated project uses may not be exactly the same as the actually file you are linking against. Should this happen then you'll just have to manually tweak the file-name in the include option as without any kind of naming consistency there's not much that can be done about it.

The generator also by default generates a project with default Intel compiler settings. Those without Intel compiler may have to change a few settings in the project properties if they want to set it back to the standard msvc. Intel is chosen as default as Visual Studio 2012 doesn't support enough C99 features to be able to compile FFmpeg so only the Intel compiler can be used with 2012 to build the project. For those with Visual Studio 2013 the default compiler adds enough C99 to be able to get it to work but for the moment the generator is built to default to 2012. The same project can be loaded in both 2012/2013 and all that needs to be changed is the compiler being used. If there is enough interest I may add an option to the generator to allow for people to specify whether they want Intel support or not at generation time but in the meantime you'll just have to change the build tool in the project properties.

Update: The current version of the generator allows for specifying the compiler that will be used as default in the output project file. Of course this can also be changed directly in the project after it is generated but for convenience the "toolchain" option is now processed by the generator. With newer patches to FFmpeg Visual Studio 2013 can compile it without problems. The toolchian parameter accepts either "msvc" for default Microsoft compiler or "icl" for the Intel compiler which also supports inline assembly.

ffmpeg_generator.exe --toolchain=msvc

The project generator can be found in my git repo below. Also in the repo is a pre-built project that is built using the following command options:

ffmpeg_generator.exe --enable-gpl --enable-version3 --enable-avisynth
   --enable-nonfree --enable-bzlib --enable-iconv --enable-zlib
   --enable-libmp3lame --enable-libvorbis --enable-libspeex
   --enable-libopus --enable-libfdk-aac --enable-libtheora
   --enable-libx264 --enable-libxvid --enable-libvpx --enable-libmodplug
   --enable-libsoxr --enable-libfreetype --enable-fontconfig 
   --enable-libass --enable-openssl --enable-librtmp --enable-libssh

Update: The default projects now include libcdio, libbluray, opengl, opencl and sdl enabled. More will be enabled as they are tested. All of these dependencies have working Visual Studio projects found in the SMP directories in each of their repos found at the parent ShiftMediaProject repository.

Your free to use this project directly as I keep it up to date and all the necessary dependency projects can also be found in my github.

git repository:
https://github.com/ShiftMediaProject/FFmpeg

82 comments:

  1. Great project! Was able to get everything to compile under VS2013 update 3, except for ffmpeg. There were a few small issues, but the biggest issue is that ffversion.h is not generated.

    ReplyDelete
    Replies
    1. This should now be fixed. ffversion.h was in my local copy but gitignore prevented it from being synced with the repo. It should be available now. Let me know if you still have any issues.

      Delete
  2. This is fantastic.
    I'm only having one issue with building ffmpeg.exe. For some reason I get lzma linker errors. I have lzma built from your code repository and everything looks good. But I get unresolved errors when ffmpeg links:
    9>libavcodec.lib(libavcodec_tiff.obj) : error LNK2019: unresolved external symbol __imp__lzma_code referenced in function _tiff_uncompress_lzma
    9>libavfilter.lib(xzlib.obj) : error LNK2001: unresolved external symbol __imp__lzma_code
    9>libavcodec.lib(libavcodec_tiff.obj) : error LNK2019: unresolved external symbol __imp__lzma_end referenced in function _tiff_uncompress_lzma
    9>libavfilter.lib(xzlib.obj) : error LNK2001: unresolved external symbol __imp__lzma_end
    9>libavcodec.lib(libavcodec_tiff.obj) : error LNK2019: unresolved external symbol __imp__lzma_stream_decoder referenced in function _tiff_uncompress_lzma
    9>libavfilter.lib(xzlib.obj) : error LNK2019: unresolved external symbol __imp__lzma_properties_decode referenced in function _is_format_lzma
    9>libavfilter.lib(xzlib.obj) : error LNK2019: unresolved external symbol __imp__lzma_auto_decoder referenced in function _xz_head

    ReplyDelete
    Replies
    1. Update: I decided to try and remove lzma, but disabling it did not seem to help. I was able to manually modify the config.h and define CONFIG_LZMA 0 which got rid of the unresolved refs in libavcodec. I still have them in avfilter though.

      Delete
    2. Hey, thanks for the feedback.
      Some of the dependency libs have now been updated in order to fix everything (xml2, gnutls, dvdread, dvdnav, gcrypt) so update from upstream and then rebuild those (make sure to also re-link the libs that depend on those mentioned - fontconfig, bluray, ssh, rtmp).
      With the above updates and CONFIG_LZMA 0 everything should now build fine using static linkage (of course the DLL versions already worked fine).
      Enabling the lzma config value requires a patch to upstream FFmpeg which hopefully I should get added in the next day or 2. At which point everything should be back to working as normal.
      If you still have any issues after that then let me know.

      Delete
    3. FFmpeg is now patched upstream with the changes represented in my local repo. Hopefully everything should work for you fine.

      Delete
    4. Worked great! Thank you.
      Just an FYI - when you changed the folder names to SMP there are some projects that have post-build commands with SMC still in the paths.
      I just changed them to the new SMP path and all was good. Again, thank you.

      Delete
    5. Thanks for the feedback, should all be fixed in the repos now.
      FYI. The projects that needed updating are all for generating required source code not included in the parent repo. The outputs of these projects are already built and included in my repo by default so you dont need to use those projects (they are just there in case someone else modifies some of the code and needs to regenerate the files).

      Delete
  3. I have Visual Studio Premium 2013. I downloaded the Github project and loaded the SMP\ffmpeg.sln file. The Solution Explorer states that the following projects failed to load: libavcodec, libavfilter, libavutil, libswresample, libswscale.
    Regards,
    -David

    ReplyDelete
    Replies
    1. I fixed the above issue by installing YASM and copying vsyasm.props, vsyasm.targets and vsyasm.xml to the following directory:
      C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\BuildCustomizations

      Delete
    2. Now I'm failing the yasm step on libavutil:

      C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\BuildCustomizations\vsyasm.targets(45,5): error MSB3721: The command ""C:\QVision\yasm\"vsyasm.exe -Xvc -f Win32 -i "..\\" -i ".\\" -i "..\libavcodec" -o "C:\QVision\FFmpeg\FFmpeg-master\SMP\\obj\Debug\Win32\libavutil\\" -P "config.asm" -rnasm -pnasm ..\libavutil\x86\cpuid.asm ..\libavutil\x86\emms.asm ..\libavutil\x86\float_dsp.asm ..\libavutil\x86\lls.asm ..\libavutil\x86\pixelutils.asm" exited with code 1.
      Any thoughts as to why? Thanks

      Delete
    3. There are a couple of things that need to be changed in order to get vsyasm to work. Have you followed the instructions in readme.txt found in the SMP directory?

      Delete
    4. Wow, I don't know why I didn't look for a readme file. I will take a look.
      Thanks

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

      Delete
    6. Excellent. I got past that issue. Now the build complains it can't find CL/cl.h.
      It looks like this is from opencl. Do you suggest a certain opencl implemenation?

      Delete
    7. Ive been meaning to write up a post detailing any additional items one might need but ive been waiting for the project to settle and give it some time to make sure everything is bug free. In the mean time the project_generator will detect any available OpenCL implementation. You can rerun the generator and exclude the --enable-opencl command or you can download either the ATI or Intel OpenCL SDKs (NVIDIAs doesnt support required CL version). The default projects use the Intel SDK as that isnt GPU dependent. So I recommend installing that. The default project also requires glext (can be disabled by removing --enable-opengl) and SDL (SDL 1 not 2, can be disabled by removing --enable-sdl). Also the latest version support NVIDIA GPU accelerated encoding which requires the cuda toolkit and nvenc header from nvidia video codec sdk (can be disabled by removing --enable-nvenc).

      Delete
  4. Is there a reason all the Optimization debug settings are set to Maximum Speed? I'm having a hard time running ffmpeg in debug. I changed the Optimization to Disabled for all the projects and all the libs build, but ffmpeg fails with a ton of unresolved externals. I noticed all the external libs have the optimization set to disabled for debug builds (hevc, x264, etc). Here are a few of the link errors:

    9>cmdutils.obj : error LNK2019: unresolved external symbol _avresample_version referenced in function _print_all_libs_info
    9>cmdutils.obj : error LNK2019: unresolved external symbol _avresample_configuration referenced in function _print_all_libs_info
    9>libavcodecd.lib(libavcodec_allcodecs.obj) : error LNK2001: unresolved external symbol _ff_h263_vaapi_hwaccel

    ReplyDelete
    Replies
    1. FFmpeg projects build with the settings used by upstreams configure based build which uses O2 on debug. The problem is that FFmpeg uses a lot of dead code elimination that msvc does not remove when optimisation is disabled. This dead code has many function calls to ffmpeg functions that dont exist and hence generate a pile of unresolved symbol references. So whether your using the exernal libs or not FFmpeg just does not compile with optimizations disabled due to the extensive use of dead code elimination. Ive discussed this with upstream FFmpeg but they consider dead code elimination to be perfectly acceptable and will not replace it. So hence why the projects currently have O2 enabled as that it the only way to get it to build (and matches stream FFmpeg build settings aswell). If I have time ill try and look at creating an extra dummy source file that has empty functions for all the missing symbols so that the linker wont error any more. However this requires finding all missing symbols and the configuration options that cause them to be disabled (i.e. avresample_version uses CONFIG_AVRESAMPLE etc.) which may take a while to find all possible config combinations.

      Delete
    2. OK I made some modifications to the project files so that they can build with standard debug settings (i.e. no more need for optimizations) which should make it so much easier for debugging.
      There are just to many uses of dead code elimination in FFmpeg to cover them all and then maintain it so instead I just forced the compiler to ignore unresolved symbols in debug. The unresolved symbols have no affect as they are in code that will never execute (hence why the symbols are not available in the first place) so allowing the linker to generate an output anyway does not cause any program instability or issues.
      The linker will still output errors for unresolved symbols but will just continue and output the binary anyway. So if Visual Studio says you have build errors just ignore it and continue as normal.
      Let me know if that solves your issues.

      Delete
    3. Worked perfectly - thank you!

      Delete
    4. Hi there. I've got a same problem as gingerbrut.
      I wish to know how you fix it more detailed.
      When I had excuted "project_generate_msvc.bat", I got a 'error.txt(log.txt)' file. there were about lzma, iconv, zlib, or something else. so I disabled. but Now i got errors more than 300 in msvc. Plz explain to me how did you fix it?

      Delete
    5. gingerbrut's problems are already fixed so whatever issues your having are different again.
      The error log.txt im guessing would be due to missing headers for lzma, iconv etc. Once you disabled those whatever errors your getting now I cant help fix unless you tell me what they are.
      So what are some of these msvc errors your getting (dont have to list all 300 obviously)

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

      Delete
    7. I deleted when i got log.txt. Finaly when i succeeded to execute batch file, My configure option is like that (below). "--enable-gpl --enable-version3 --enable-avisynth --enable-nonfree --disable-iconv --disable-libxvid --disable-zlib --disable-lzma --disable-sdl --disable-bzlib --toolchain=msvc"
      If it couldn't find header, i deleted enable option. or disable option.
      After that, I've got visual studio errors about Cannot open include file "cl.h, soxr.h, zlib.h, iconv.h, nvEncodeAPI.h, xvid.h, x265.h, x264.h, vpx_encoder.h, vpx_codec.h, vorbisenc.h, theoraenc.h, speex.h, opus.h, opus_defines.h, lame.h, ilbc.h, aacenc_lib.h, aacdecoder_lib.h". and, now i got 40 Errors. Should I have to disable them?

      Delete
    8. OK the default project files included in my repo contain projects that build with a large number of additional projects as dependencies. Building with any of these enabled will result in the errors you have mentioned above (although FYI all the additional projects are available in the ShiftMediaProject repo).

      However if you are generating a new project using the project_generator then you dont need these additional projects. By default ffmpeg has zlib, iconv, bzlib and lzma enabled, only these dependencies need to be explicitly disabled on the command line as all others are disabled by default.

      So if your using a command line to the project generator that doesnt enable them then you shouldnt get a project that uses them. Based on the errors you mentioned above these are the exact dependencies that the default projects are configured with. This would suggest that you are trying to build the default projects and not generating new ones with the new configuration. Try deleting the existing projects and ensure that new ones are created. If you are using the msvc.bat file to launch project generate make sure that all --enable-xxx options are removed from that file before running it.

      Delete
    9. Thank you! Finally I just compile it. Thank you. It worked!! Fantastic

      Delete
  5. 1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppBuild.targets(1361,5): warning MSB8012: TargetPath(H:\code\3\FFmpeg-master\SMP\..\..\..\msvc32\libavutild.lib) does not match the Library's OutputFile property value (H:\code\msvc32\lib\libavutild.lib). This may cause your project to build incorrectly. To correct this, please make sure that $(OutDir), $(TargetName) and $(TargetExt) property values match the value specified in %(Lib.OutputFile).
    1>LINK : fatal error LNK1181: cannot open input file 'H:\code\3\FFmpeg-master\SMP\\obj\Debug\Win32\libavutil\cpuid.obj'

    ReplyDelete
    Replies
    1. The first is just a warning that can be completely ignored. Its a result of the project using the output directories as used by default upstream FFmpeg which has separate directories for dlls and libs.
      Second is generally a result of the project not building correctly. Try right clicking on the project and selecting "Rebuild". If that doesnt work then make sure you have installed yasm correctly (read the readme for instructions).

      Delete
  6. This is a really nice project.But I have faced some problems when I try to Debug it using Step Into(F11). Some of the .asm Files are missing and I am unable to debug further.Can you please explain me about this inconvenience?

    ReplyDelete
    Replies
    1. The issue is that yasm needs to generate debug symbols for the asm files in order for Visual Studio to be able to debug them. I have updated the yasm options in the generated projects to create cv8 debug information. Unfortunately yasm cant generate very detailed debug information when using Microsoft compatible format so try the updated generator/projects and see how that goes.

      Delete
  7. Firstly, thank you for a very helpful project. I just wrote a longer post with more compliments, but the commenting system ate it when I tried to post, so I'll keep this very short for now.
    So: I can build the ffmpeg libraries and link them to my own program, and debug the Release version. However, though I can build the debug version by using FORCE:UNRESOLVED, and run it as stand-alone, VS won't let me start it in the debugger, complaining about the unresolved symbols.
    The same is true of ffmpeg and ffprobe in your own tree, I'm stuck, and any advice would be appreciated. I'm using VS 2013 update 4.

    ReplyDelete
    Replies
    1. Actually, I've found an answer. If you set Tools|Options|Projects and Solutions|Build and Run|On Run... errors to Launch Old Version, it runs. This is ugly because it also rebuilds every time, but it's better than nothing.

      Delete
    2. Unfortunately this is a issue with FFmpeg code as its not written to support being compiled in debug. This is due to extensive use of dead code elimination throughout FFmpeg which there is not much that can be done about. So its on my short-list to try and find a fix but given the issue is actually a result of upstream FFmpegs code there's very little that can be done unfortunately.

      Delete
  8. >cmdutils.obj : error LNK2019: unresolved external symbol _avresample_version referenced in function _print_all_libs_info
    1>cmdutils.obj : error LNK2019: unresolved external symbol _avresample_configuration referenced in function _print_all_libs_info
    1>libavcodecd.lib(allcodecs.obj) : error LNK2001: unresolved external symbol _ff_h263_vaapi_hwaccel
    1>libavcodecd.lib(allcodecs.obj) : error LNK2001: unresolved external symbol _ff_h263_vdpau_hwaccel
    1>libavcodecd.lib(allcodecs.obj) : error LNK2001: unresolved external symbol _ff_h264_qsv_hwaccel
    1>libavcodecd.lib(allcodecs.obj) : error LNK2001: unresolved external symbol _ff_h264_vaapi_hwaccel
    1>libavcodecd.lib(allcodecs.obj) : error LNK2001: unresolved external symbol _ff_h264_vda_hwaccel
    1>libavcodecd.lib(allcodecs.obj) : error LNK2001: unresolved external symbol _ff_h264_vda_old_hwaccel

    ReplyDelete
    Replies
    1. Firstly, thank you for your job. i compile with virtual 2013 ,and i meet with these difficulties when compile ffmpe.exe.

      Delete
    2. As previously stated in the above comments, this is an issue with FFmpegs code and debug builds. If you check your output log youll see there is a comment stating that these errors can be ignored and an executable is generated anyway.
      Debug builds should only be used if you really need to debug code. For just compiling libs that can be used in your own application you should always use Release builds which dont have these issues.

      Delete
  9. Does this process also work to build ffmpeg libs (libavcodec, libavformat, etc) to be able to use them in Visual C applications, or does it only work to generate the Visual Studio project needed to build the ffmpeg executable?
    Does it support all the configure parameters?
    Thanks!

    ReplyDelete
    Replies
    1. It builds all the libs (as static and/or dynamic) as well as all the programs (ffmpeg/ffplay/ffserver). Which libs/programs are built can be configured on the command line. Most command line arguments are supported, there are a few rarely used ones and some that are not relevant to VS builds that are not covered. For instance --enable-static is not supported as the output VS project covers this as it has different configurations to allow you to choose what type to build.

      Delete
  10. When I try to build I get several errors like this...

    Error 165 error RC1110: could not open ..\libavutil\avutilres.rc

    Is project_generate.exe suppose to create .rc files?

    I'm using it on my own custom version of ffmpeg, not the one included with the project.

    ReplyDelete
    Replies
    1. avutilres.rc is part of the standard FFmpeg source code and has been provided for over a year.
      It can be seen in the official FFmpeg repo here:
      https://github.com/FFmpeg/FFmpeg/blob/master/libavutil/avutilres.rc

      So if your missing it then you might want to check your sources or make sure you have updated to a recent version of FFmpeg.

      Delete
    2. I'm using an old version, based on FFmpeg v1.2. It has some custom changes in it so moving over to a new build isn't easy. I tried with a newer release and it worked fine.

      I'll have to look into migrating my changes over to a newer release

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

    ReplyDelete
  12. Hi,

    I was trying to use project_generate with the following options:
    project_generate.exe --enable-version3 --enable-nonfree --disable-runtime-cpudetect --enable-gray --disable-programs --disable-ffplay --disable-ffprobe --disable-ffserver --disable-doc --disable-htmlpages --disable-manpages --disable-podpages --disable-txtpages --disable-postproc --disable-network --disable-dct --disable-dwt --disable-lsp --disable-lzo --disable-mdct --disable-rdft --disable-fft --disable-encoders --enable-encoder=rawvideo --enable-encoder=bmp --enable-encoder=mjpeg --enable-encoder=ffv1 --enable-encoder=h264_qsv --disable-decoders --enable-decoder=bmp --enable-decoder=h264_qsv --enable-decoder=cyuv --enable-decoder=ffv1 --enable-decoder=mjpeg --enable-decoder=mjpegb --enable-decoder=ayuv --enable-decoder=rawvideo --enable-decoder=yuv4 --enable-hwaccel=h264_qsv --disable-muxers --enable-muxer=avi --disable-demuxers --enable-demuxer=avi --disable-parsers --enable-parser=bmp --enable-parser=h264 --enable-parser=mjpeg --disable-bsfs --disable-protocols --enable-protocol=file --disable-indevs --disable-outdevs --disable-devices --disable-filters --enable-libmfx --toolchain=msvc --disable-debug --enable-memalign-hack

    But I am getting the following warnings and errors:
    Warning: Unlisted config dependency found (av_foundation)
    Warning: Unlisted config dependency found (qtkit)
    Error: Failed finding config list (encoder_LIST)
    Error: Unknown config option (encoder)
    Error: Unknown config option (encoder=rawvideo_rawvideo) in command line option (--enable-encoder=rawvideo)

    Any help is appreciated. I am trying to get a demo of this project working within a week's timeframe.

    Thanks!

    ReplyDelete
    Replies
    1. Should be fixed in the repo now.
      I will point out that passing all the command line options to disable the documentation is unnecessary as none is generated anyway (only a VS project file).
      Also disable-debug is reserved as the output VS projects have multiple configurations that can be changed to toggle between debug and release.

      Delete
    2. Thanks so much for the fix. The errors mentioned above are fixed, but the process stops with the following error:
      Failed calling temp.bat. Ensure you have Visual Studio or the Microsoft compiler installed and that any required dependencies are available.
      I have VS 2013 installed and also installed yasm. What am I missing?
      Sorry again for bothering you and thanks for your help!

      Delete
    3. Note that I am calling the batch file from a VS command prompt run as administrator.

      Delete
    4. Only config.h, config.asm and the libavcodec project are generated.

      Delete
    5. That error message also tells you to check log.txt for additional information. Check that as it will have the specific error in it.

      Delete
  13. Even calling the provided project_generate_msvc.bat fails with a weird error:
    Failed calling temp.bat. Ensure MSVC is installed.
    I have MSVC 2013 installed and made sure to also install yasm.

    ReplyDelete
  14. I had the same problem, by deleting all prebuilt projects (*.vcxproj; *.def) in SMP folder, and run it again, it worked.

    ReplyDelete
  15. Hi,

    I was able to compile the MSVC project in release, but I am getting a whole bunch of unresolved externals when I try to compile the debug version.
    I had a couple for the release version that I was able to fix by adding a couple c files to the project that the tools missed. No big deal. But the unresolved external that pop up for the debug version refer to functions that are declared in non x86 platforms (libavcodec\alpha for example).
    Adding them to the project just does not work.
    I tried to compare the build options for release and debug and don't see any difference that would prompt these errors.
    Any help would be greatly appreciated. I have a problem with the release dll, and I was trying to build the debug to see what some of the functions calls I am making are returning errors.

    Thank you very much in advance for your help.

    Best regards

    ReplyDelete
    Replies
    1. This is an issue with FFmpeg and not with the projects. As stated in previous comments due to FFmpegs use of dead code elimination the only way to get it to compile without the errors is with optimisations turned on (which makes it rather hard to debug). To get around this the Debug build is set to ignore all these warning and generate a complete binary anyway. So although you are getting errors about unresolved externals these are as you discovered all for externals that will never get called (like all the alpha code etc.). So all these unresolved externals are all for code that is never used which is why release works fine. For Debug you just ignore the errors as VS still creates an output binary and that binary still works perfectly fine.

      Delete
    2. Thanks for your answer. I should have read more carefully the previous comments.
      I am using your generated project that generates the static libraries. The debug static libraries are generated fine. The problem is that I am trying to use the OpenCV wrapper to ffmpeg. It when trying to build that dll that includes those debug static libraries that I actually get all the unresolved external and in that case, my debug dll is actually not created.
      Am I out of luck?

      Delete
    3. The default already generated projects dont support OpenCV so OpenCV support hasnt been fully tested. Check your project properties and make sure that the correct OpenCL lib is being included with the project. If it is and your still getting unresolved then I dont have a solution at this point as its something that ive tested yet. If you do work out what needs to be changed in the project then let me know so I can update the generator.

      Delete
  16. Hello!
    It is my config options:
    --disable-ffmpeg --disable-ffplay --disable-ffprobe --disable-ffserver --disable-doc --disable-htmlpages --disable-manpages --disable-podpages --disable-txtpages --disable-avdevice --disable-swresample --disable-swscale --disable-postproc --disable-avfilter --disable-pthreads --disable-w32threads --disable-os2threads --disable-network --disable-lsp --disable-lzo --disable-mdct --disable-rdft --disable-faan --disable-iconv --disable-zlib --disable-lzma --disable-sdl --disable-bzlib --disable-encoders --disable-decoders --enable-encoder=h261 --enable-encoder=h263 --enable-encoder=h263p --enable-decoder=h261 --enable-decoder=h263 --enable-decoder=h263p --enable-decoder=h264 --enable-debug --toolchain=msvc

    I build libavcodecd.lib, libavutild.lib and libavformatd.lib, and when i ink it to other project, i recieve this:

    2>libavcodec.lib(allcodecs.obj) : error LNK2001: unresolved external symbol _ff_h263_vaapi_hwaccel
    2>libavcodec.lib(allcodecs.obj) : error LNK2001: unresolved external symbol _ff_h263_vdpau_hwaccel
    2>libavcodec.lib(allcodecs.obj) : error LNK2001: unresolved external symbol _ff_h264_mmal_hwaccel
    2>libavcodec.lib(allcodecs.obj) : error LNK2001: unresolved external symbol _ff_h264_qsv_hwaccel
    2>libavcodec.lib(allcodecs.obj) : error LNK2001: unresolved external symbol _ff_h264_vaapi_hwaccel
    2>libavcodec.lib(allcodecs.obj) : error LNK2001: unresolved external symbol _ff_h264_vda_hwaccel
    2>libavcodec.lib(allcodecs.obj) : error LNK2001: unresolved external symbol _ff_h264_vda_old_hwaccel
    2>libavcodec.lib(allcodecs.obj) : error LNK2001: unresolved external symbol _ff_h264_vdpau_hwaccel
    2>libavcodec.lib(allcodecs.obj) : error LNK2001: unresolved external symbol _ff_hevc_dxva2_hwaccel
    2>libavcodec.lib(allcodecs.obj) : error LNK2001: unresolved external symbol _ff_mpeg1_xvmc_hwaccel
    ....................
    2>libavcodec.lib(allcodecs.obj) : error LNK2001: unresolved external symbol _ff_h263_vaapi_hwaccel
    2>libavcodec.lib(allcodecs.obj) : error LNK2001: unresolved external symbol _ff_h263_vdpau_hwaccel
    2>libavcodec.lib(allcodecs.obj) : error LNK2001: unresolved external symbol _ff_h264_mmal_hwaccel
    2>libavcodec.lib(allcodecs.obj) : error LNK2001: unresolved external symbol _ff_h264_qsv_hwaccel
    2>libavcodec.lib(allcodecs.obj) : error LNK2001: unresolved external symbol _ff_h264_vaapi_hwaccel
    2>libavcodec.lib(allcodecs.obj) : error LNK2001: unresolved external symbol _ff_h264_vda_hwaccel
    2>libavcodec.lib(allcodecs.obj) : error LNK2001: unresolved external symbol _ff_h264_vda_old_hwaccel
    2>libavcodec.lib(allcodecs.obj) : error LNK2001: unresolved external symbol _ff_h264_vdpau_hwaccel
    2>libavcodec.lib(allcodecs.obj) : error LNK2001: unresolved external symbol _ff_hevc_dxva2_hwaccel
    2>libavcodec.lib(allcodecs.obj) : error LNK2001: unresolved external symbol _ff_mpeg1_xvmc_hwaccel
    .....................

    And many other unresolved external symbols. I really need to debug FFmpeg.

    ReplyDelete
  17. This is a result of the use of dead code elimination as used in FFmpeg source code (has been discussed numerous times in above comments). There is no issue with the above errors are it is complaining about code that will never be reached (e.g. the first error is about VAAPI hardware acceleration which is only available on linux and not enabled in windows builds).
    The generated programs will set this automatically but any other external programs will have to set a linker option in your project settings. This is found in "Linker->General->Force File Output" and set it to "Undefined Symbols Only". You will still get the errors but the binary will generate and run fine.

    ReplyDelete
  18. I used your excellent program some months ago, and now need it again for the newest ffmpeg: I'm finding some issues, some of which I can work around or fix, some not.
    I'm trying to make a build with no external dependencies.

    Firstly, there are some issues with disabled modules: in several places there are lines such as
    if (getConfigOption(*vitCheckItem)->m_sValue.compare("0") != 0) { ... }

    However, there may be no option for that item, in which case it's trying to derefence an end().

    I fixed this by adding a matchConfigOption function that checks for this, and using it in about six places. I'll send you the trivial code if you want.


    Secondly, there are a couple of issues with the directories.

    1) --rootdir command, at least if used as the first command, seems to attempt to modify an option that doesn't exist yet - I haven't tried to debug that in detail
    2) Because the directories are relative, there seems to be some disagreement between different parts of the program.
    For me, default program cwd is the one with the solution in, which means that it find the configure file but can't find the templates.
    If I set the cwd to bin, it finds the templates but no configure.
    This can be fixed by adding "../../" to the sPathList array.


    After I have done the above, I can make the project fine: however it doesn't build because of some missing dependencies that the program doesn't seem to know about.
    These are:
    libxcdd.lib
    libsoxrd.lib
    libbz2d.lib
    libfrei0rd.lib
    libcacad.lib

    With the exception of bz2, these are all set 0 in config.h - but it fails anyway.

    Any help appreciated.

    ReplyDelete
    Replies
    1. Can you post the command line options that you are using that are causing issues with the disabled modules.

      As for the issues with directories and rootdir those should now be fixed in the repo.

      Delete
  19. Thanks for fixing those. The command-line I am using is the one in your readme:
    -enable-gpl --enable-version3 --disable-bzlib --disable-iconv --disable-zlib
    --disable-lzma --disable-sdl --toolchain=msvc

    and the crash I was getting is associated with "stagefright", which is seen as disabled but has no associated entries.

    ReplyDelete
    Replies
    1. OK made some fixes which have been pushed to the repo which should correct all of the above issues.

      Let me know if you have any further problems (try creating a bug ticket on the github repo page as it helps keep track of things on my end)

      Delete
  20. Getting there. But still not quite... I'm hitting the same crash as before when getCongfigOption() is failing to find an option, and the end() iterator is being dereferenced.

    Getting there. But still not quite... I'm hitting the same crash as before when getCongfigOption() is failing to find an option, but the end() iterator is being dereferenced.

    Specific example in projectGenerator::buildDependencyDirs (line 194) on processing libaacplus.

    Sorry.

    I'll put this on github as well.

    ReplyDelete
  21. Success!
    After fixing the above, I just had to tell it not to try to look for an schannel library (the code is already in avformat)

    ReplyDelete
  22. And... I've found the bug I was after and can continue smoothly.
    Thank you.

    ReplyDelete
  23. Hi,
    Thanks for your wonderful project. I have downloaded the FFVS-project-generator from your site. I am testing it with latest ffmpeg version. For the following command line I am getting errors:

    D:\FFVS-Project-Generator_1.4.0_x64>project_generate.exe --rootdir="D:\Repos\ffmpeg1" --enable-gpl --enable-version3 --disable-bzlib --disable-iconv --disable-zlib --disable-lzma --disable-sdl --toolchain=msvc --disable-bsfs
    Project generator...
    Passing configure file...
    Warning: Unlisted config dependency found (qsvdec_mpeg2)
    Warning: Unlisted config dependency found (qsvdec_vc1)
    Warning: Unlisted config dependency found (avfoundation)
    Warning: Unlisted config dependency found (qtkit)
    Warning: Unlisted config dependency found (tls_protocol)
    Outputting config.h...
    Warning: Unknown option in ifa dependency (parisc64) for option (fast_64bit)
    Warning: Unknown option in dependency (VAEncPictureParameterBufferMPEG2) for option (mpeg2_vaapi_encoder)
    Warning: Unknown option in dependency (VAEncPictureParameterBufferVP8) for option (vp8_vaapi_encoder)
    Outputting avconfig.h...
    Outputting ffversion.h...
    Outputting enabled components file libavcodec/bsf_list.c...
    Outputting enabled components file libavformat/protocol_list.c...
    Generating from Makefile (D:\Repos\ffmpeg1/libavcodec/)...
    Warning: Unknown dynamic configuration option (CONFIG_MPEG4_OMX_ENCODER) used when passing object (omx)
    Generating from Makefile (D:\Repos\ffmpeg1/libavcodec/x86/)...
    Generating project exports file (libavcodec)...
    Generating missing DCE symbols (libavcodec)...
    Warning: Found unknown macro in DCE condition CANDIDATE_MB_TYPE_DIRECT
    Warning: Found unknown macro in DCE condition CANDIDATE_MB_TYPE_DIRECT0
    Warning: Found unknown macro in DCE condition MV_DIRECT
    Error: Failed opening file (../../../Repos/ffmpeg1/SMP/D:/Repos/ffmpeg1/SMP/libavcodec/bsf_list.c)
    Press any key to continue . . .

    I can find the bsf_list.c file in that directory. Any help would be appreciated! Thanks!

    ReplyDelete
    Replies
    1. Looks like an issue with using absolute directories for the rootdir value. Try setting rootdir="../Repos/ffmpeg1" instead.

      Delete
    2. I changed the path. Still getting the same error:

      D:\Repos\FFVS-Project-Generator_1.4.0_x64>project_generate.exe --rootdir=../ffmpeg1 --enable-gpl --enable-version3 --disable-bzlib --disable-iconv --disable-zlib --disable-lzma --disable-sdl --toolchain=msvc --disable-bsfs
      Error: Failed opening file (../ffmpeg1/ffmpeg1/SMP/libavcodec/bsf_list.c)

      my rootdir is ../ffmpeg1, but why it is looking for bsf_list.c at ../ffmpeg1/ffmpeg1/SMP/libavcodec/bsf_list.c

      Delete
    3. Looks like ill have to do a bit of debugging and work out whats going on. In the meantime, based on the directory structure of the last error you posted you should be just able to rename your ffmpeg directory to just 'ffmpeg' and then dont pass the rootdir variable and it should pick it up automatically.

      Delete
    4. As per your comment i removed rootdir from command line and renamed ffmpeg repo, still getting same error

      D:\Repos\FFVS-Project-Generator_1.4.0_x64>project_generate.exe --enable-gpl --enable-version3 --disable-bzlib --disable-iconv --disable-zlib --disable-lzma --disable-sdl --toolchain=msvc --disable-bsfs
      Project generator...
      Passing configure file...
      Generating from Makefile (../ffmpeg/libavcodec/)...
      Generating from Makefile (../ffmpeg/libavcodec/x86/)...
      Generating project exports file (libavcodec)...
      Generating missing DCE symbols (libavcodec)...
      Error: Failed opening file (../ffmpeg/ffmpeg/SMP/libavcodec/bsf_list.c)

      Delete
    5. OK i think i found the source of the issue. Ill put a bug fix version up soon. In the mean time it appears that if you just simply copy the existing contents of FVS-Project-Generator_1.4.0_x64 into a sub-directory (for instance create a sub-dir called bin i.e. FVS-Project-Generator_1.4.0_x64/bin) and then run it from there then it works.

      Delete
    6. Theres a 1.4.1 bug fix release that should be available on the site soon. If you have any further issues with it then create a ticket on the github site.

      Delete
    7. I created a sub-directory bin and placed the project_generate.exe inside. And now, some other issues pop-up. Here is the command line:
      project_generate.exe --enable-gpl --enable-version3 --disable-bzlib --disable-iconv --disable-zlib --disable-lzma --disable-sdl --toolchain=msvc --disable-bsfs

      I disabled sdl but its showing error:
      error C1083: Cannot open include file: 'SDL.h': No such file or directory

      Delete
    8. thats already fixed in the latest 1.4.1 build.

      Delete
    9. Thanks for your help! I am able to compile but getting some linker error while building ffmpeg in visual studio:
      1>libavcodec.lib(allcodecs.obj) : error LNK2001: unresolved external symbol ff_h264_cuvid_hwaccel
      1>libavcodec.lib(allcodecs.obj) : error LNK2001: unresolved external symbol ff_hevc_cuvid_hwaccel
      1>D:\Repos\ffmpeg\SMP\..\..\..\msvc\\bin\x64\ffmpeg.exe : warning LNK4088: image being generated due to /FORCE option; image may not run

      I modified the linker options like as you mentioned in your previous comments. This is done with release mode in visual studio 2013 and the generated ffmpeg.exe is broken.

      Delete
    10. Dont modify the linker options. That was for a separate issue that is not even required anymore.

      The error you have is based on your config options and the upstream ffmpeg code so its not directly related to the generated project. The error is valid as you have disabled bsfs which are required for h264/hevc cuvid to work. But cuvid by default is enabled in newer ffmpeg configs.

      So you need to either enable the bsf needed for it to operate (h264_mp4toannexb_bsf/hevc_mp4toannexb_bsf) or disable cuvid (or just the h264/hevc hwaccel)

      Delete
    11. It Worked! Thanks!

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

    ReplyDelete
  25. Hi, I am trying to build ffmpeg with --enable-libx265. I keep getting the following errors. I am not able to figure out the issue. Pls help.
    From the Logs:

    ibavcodec/x86/hpeldsp_init.c(209) : error C2065: 'put_pixels16_y2_mmxext' : undeclared identifier
    libavcodec/x86/hpeldsp_init.c(211) : error C2065: 'avg_pixels16_mmxext' : undeclared identifier
    libavcodec/x86/hpeldsp_init.c(212) : error C2065: 'avg_pixels16_x2_mmxext' : undeclared identifier
    libavcodec/x86/hpeldsp_init.c(213) : error C2065: 'avg_pixels16_y2_mmxext' : undeclared identifier
    libavcodec/x86/hpeldsp_init.c(214) : error C2065: 'avg_pixels16_xy2_mmxext' : undeclared identifier
    libavcodec/x86/hpeldsp_init.c(225) : error C2065: 'put_no_rnd_pixels16_x2_mmxext' : undeclared identifier
    libavcodec/x86/hpeldsp_init.c(226) : error C2065: 'put_no_rnd_pixels16_y2_mmxext' : undeclared identifier
    libavcodec/x86/hpeldsp_init.c(230) : error C2065: 'avg_approx_pixels16_xy2_mmxext' : undeclared identifier
    libavcodec/x86/hpeldsp_init.c(240) : error C2065: 'put_pixels16_y2_3dnow' : undeclared identifier
    libavcodec/x86/hpeldsp_init.c(242) : error C2065: 'avg_pixels16_3dnow' : undeclared identifier
    libavcodec/x86/hpeldsp_init.c(243) : error C2065: 'avg_pixels16_x2_3dnow' : undeclared identifier
    libavcodec/x86/hpeldsp_init.c(244) : error C2065: 'avg_pixels16_y2_3dnow' : undeclared identifier
    libavcodec/x86/hpeldsp_init.c(245) : error C2065: 'avg_pixels16_xy2_3dnow' : undeclared identifier
    libavcodec/x86/hpeldsp_init.c(256) : error C2065: 'put_no_rnd_pixels16_x2_3dnow' : undeclared identifier
    libavcodec/x86/hpeldsp_init.c(257) : error C2065: 'put_no_rnd_pixels16_y2_3dnow' : undeclared identifier
    libavcodec/x86/hpeldsp_init.c(261) : error C2065: 'avg_approx_pixels16_xy2_3dnow' : undeclared identifier

    ReplyDelete
    Replies
    1. There are some object files missing from the link. My guess is that you haven't installed yasm properly.

      If this is an issue related from using a project generated from the FFVS generator then make sure you read all the instructions that come with it and if you still have problems then create a new issue on the projects github.

      Delete
  26. Hi,
    I am using the latest version FFVS-Project-Generator-1.6.0 and trying to compile ffmpeg but getting the following error

    "Error: Errors detected during compilation :-
    error : An installed version of Visual Studio could not be detected.Based on the above error(s) Visual Studio is not installed correctly on the host system.Install a compatible version of Visual Studio before trying again."

    I am using Visual Studio 13 update 5. I am able to generate ffmpeg.sln with FFVS-project-generator-1.4.1 version. So what is the minimum version of visual studio required to use the latest project generator?

    ReplyDelete
    Replies
    1. FFVS should support 2013 onwards. However version 1.6.0 changed the detection of installed Visual Studio which may have caused some errors with older versions. If you open an issue on the FFVS github page ill look into it.

      Delete
    2. A new version 1.6.1 has been released which should fix 2013 detection. If not then let me know.

      Delete