preface

There are many ways to compile FFmpeg on the web, but most of them are compiled directly with MINGw. In my case, FFmpeg compiled with mingW causes 0xC000007b problems. I didn’t know why, and I didn’t look into it. Here is how to compile the FFmpeg+ FDK-AAC library for use in QT(MSVC 2017 64-bit compilation tool chain).

Compiled libraries

I compiled FFmpeg+ fdK-acc. I compiled FFmpeg separately before, but the avcodec-58.dll file is much bigger, so fdKAAC has been integrated

Compile the FDK – aac

Fdkaac already supports MSVC compilation, not many people on the web are talking about it.

  • Open x64 Native Tools Command Prompt for VS 2017
  • Go to the source directory of fdkaac, I have CD C:\Users\Yu\Documents\ fdK-aac-2.0.1
  • Run nmake -f makefile.vc all
  • After compiling, fdk-aac.lib is output, which is exactly what we need

There is a flaw here, I will mention the premise, compile only lib, do not output include folder, but the include after the use. I was first in msys2 + mingw compilation of the FDK – aac, compiled is include in the output directory, then I put the FDK made up above – aac. Lib copied to the output directory in the lib folder, will be used later. Include files can also be copied from the source directory, which is a few header files, as shown below

  • ./autogen.sh
  • /configure –prefix= your output directory (fdk-aac output directory requires absolute path)
  • make
  • make install

Compile FFmpeg

CMD to change rem set MSYS2_PATH_TYPE=inherit to set MSYS2_PATH_TYPE=inherit

- rem set MSYS2_PATH_TYPE=inherit
+ set MSYS2_PATH_TYPE=inherit
Copy the code

X86_x64 Cross Tools Command Prompt for VS 2017, C:\msys64\msys2_shell. CMD, msys2, MSVC You can view it by executing which CL in the MSYS2 window

Yu@DESKTOP-RONCTS2 MSYS ~/ffmpeg $ which cl /c/Program Files (x86)/Microsoft Visual Studio / 2017 / Community/VC/Tools/MSVC / 14.16.27023 / bin/HostX86 / x64 / clCopy the code

. / configure

. / configure -- toolchain = MSVC - extra - cflags = - I/home/Yu/FDK - aac - 2.0.1 / build_out/include - extra - ldflags = - LIBPATH: / home/Yu/FDK - aac - 2.0.1 / build_out/lib - disable - doc - disable - lzma - disable - designed --enable-shared --enable-libfdk-aac --enable-nonfree --enable-gpl --disable-static --disable-bzlib --disable-libopenjpeg  --disable-iconv --disable-zlib --prefix=build_outCopy the code

/configure –help:

–toolchain= MSVC to use the MSVC toolchain, must be added

–extra-cflags= -i /home/yu/fdk-aac-2.0.1 /build_out/include points to the directory of the header file of fdk-aac

–extra-ldflags= -libpath :/home/Yu/fdk-aac-2.0.1/build_out/lib –extra-ldflags= -libpath :/home/Yu/fdk-aac-2.0.1/build_out/lib It has to be complete. This hole is what I saw in ffbuild/config.log, which I can also see if there are other problems with./configure

–disable-doc does not output documents

–disable-lzma –disable-bzlib –disable-libopenjpeg –disable-iconv –disable-zlib Using these DLLS in QT will prompt you that they are missing

Disable-programs do not compile and generate FFMPEG, FFplay, and FFprobe

–enable-shared –disable-static Generates dynamic libraries, but does not generate static libraries

— enable-libfdK-aac –enable-nonfree –enable-gpl compiles fdK-aac to FFmpeg library

–prefix=build_out make install Output location, I specify output to the build_out directory

The project may take a few minutes to configure. If there are no errors, you can make make-j8 (8 threads compiling at the same time to speed up the process). When you are finished, you can make install and view the compiled output in the build_out directory

You probably don’t need FDK-AAC

I compiled the FFmpeg library with the FDK-AAC version because I ran into this problem while trying to code PCM to AAC:

[ffmpeg] Specified sample format s16 is invalid or not supported
Copy the code

This problem is because the encoder obtained by avCOdec_find_encoder (AV_CODEC_ID_AAC) of the new version of FFmpeg does not support the AV_SAMPLE_FMT_S16 format. Only the AV_SAMPLE_FMT_FLTP format is supported. There are two solutions:

  1. Use libfDK-AAC encoder like I did, this encoder supports AV_SAMPLE_FMT_S16 sampling format, can be directly encoded to AAC. The way you get the encoder needs to look like this:
    AVCodec * audio_codec = avcodec_find_encoder_by_name("libfdk_aac");
    Copy the code
  2. AV_SAMPLE_FMT_S16 = AV_SAMPLE_FMT_FLTP = AV_SAMPLE_FMT_FLTP = AV_SAMPLE_FMT_FLTP = AV_SAMPLE_FMT_FLTP = AV_SAMPLE_FMT_FLTP
    swr_context = swr_alloc();
    av_opt_set_int(swr_context, "in_channel_layout",  AV_CH_LAYOUT_STEREO, 0);
    av_opt_set_int(swr_context, "out_channel_layout", AV_CH_LAYOUT_STEREO, 0);
    av_opt_set_int(swr_context, "in_sample_rate",     48000, 0);
    av_opt_set_int(swr_context, "out_sample_rate",    48000, 0);
    av_opt_set_sample_fmt(swr_context, "in_sample_fmt",  AV_SAMPLE_FMT_S16, 0);
    av_opt_set_sample_fmt(swr_context, "out_sample_fmt", AV_SAMPLE_FMT_FLTP, 0);
    swr_init(swr_context);
    
    int len2 = swr_convert(swr_context, out_frame_buffer_, 4096 * 4, (const uint8_t **)&data , 4096 / 4);
    Copy the code

To approach 2 code I cannot fully explain it, is also a beginner, I put a here for sampling data links: blog.csdn.net/bixinwei22/…