ffmpeg开发教程(1) 准备C++开发环境

本文介绍下C++常用的开发环境和工具,C++项目参见github的ffmpeg-tutorial 。目前我常用的开发环境有 Windows 10, Mac 和 Ubuntu,C++的开发IDE有CLion, XCode,Visual Studio ,VSCode。编译基于CMake,生成Ninja 编译文件。使用vcpkg来管理C++的软件包。

IDE 其中CLion和VSCode是三个平台都可以使用的,具体如下图所示:

Windows Mac Ubuntu
Clion X X X
Vscode X X X
Xcode X
Visual Studio 2017 X

vcpkg安装可以参考github上的说明,clone vcpkg repo ,运行bootstrap-vcpkg.bat(Windows)或 bootstrap-vcpkg.sh (Mac 和 Linux) .

安装好vcpkg之后,可以配置下面几个环节变量:

Linux和Mac

export VCPKG_ROOT=~/Workspace/vcpkg
export VCPKG_DEFAULT_TRIPLET=x64-osx
export CMAKE_GENERATOR=Ninja

其中VCPKG_ROOT 为vcpkg的安装目录,VCPKG_DEFAULT_TRIPLET 为C++软件包的缺省配置,比如64位还是32位,编译成动态库还是静态库,CMAKE_GENERATOR 缺省生成的编译文件的格式,比如Makefile,或是Ninja,或是XCode,Visual Studio 的项目文件。

目前大部分计算机都是64位机器,我们的教程基本是使用动态链接库的形式,因此我们可以使用如下的vcpkg, triplet的配置,可以修改缺省的triplet 或者创建新的triplet文件。vcpkg安装后,triplets目录下定义了一些常用的triplet文件:

Mac下的x64-osx缺省使用静态库,我们可以修改x64-osx.cmake

set(VCPKG_TARGET_ARCHITECTURE x64)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE dynamic)

set(VCPKG_CMAKE_SYSTEM_NAME Darwin)

在Ubuntu下,同样,我们复制x64-linux.cmake ,创建一个新的x64-ubuntu.cmake

set(VCPKG_TARGET_ARCHITECTURE x64)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE dynamic)

set(VCPKG_CMAKE_SYSTEM_NAME Linux)

Windows下直接使用x64-windows.cmake

有了vcpkg之后,安装C++软件包就非常简单,比如安装我们教程中用到的几个软件包SDL2, ffmpeg,可以直接运行:

vcpkg install SDL2 ffmpeg

安装成功后,可以使用vcpkg list列出安装好的软件包的版本和简要说明,比如Mac下:

catch2:x64-osx                                     2.11.1           A modern, header-only test framework for unit te...
ffmpeg:x64-osx                                     4.2-5            a library to decode, encode, transcode, mux, dem...
ffmpeg[avresample]:x64-osx                                          Libav audio resampling library support in ffmpeg
libjpeg-turbo:x64-osx                              2.0.4            libjpeg-turbo is a JPEG image codec that uses SI...
liblzma:x64-osx                                    5.2.4-4          Compression library with an API similar to that ...
libpng:x64-osx                                     1.6.37-6         libpng is a library implementing an interface fo...
libwebp:x64-osx                                    1.1.0            WebP codec: library to encode and decode images ...
libwebp[nearlossless]:x64-osx                                       Enable near-lossless encoding
libwebp[simd]:x64-osx                                               Enable any SIMD optimization.
opencv4:x64-osx                                    4.1.1-3          computer vision library
opencv4[dnn]:x64-osx                                                Enable dnn module
opencv4[jpeg]:x64-osx                                               JPEG support for opencv
opencv4[opengl]:x64-osx                                             opengl support for opencv
opencv4[png]:x64-osx                                                PNG support for opencv
opencv4[tiff]:x64-osx                                               TIFF support for opencv
opencv4[webp]:x64-osx                                               WebP support for opencv
opengl:x64-osx                                     0.0-5            Open Graphics Library (OpenGL)[3][4][5] is a cro...
protobuf:x64-osx                                   3.11.3           Protocol Buffers - Google's data interchange format
tiff:x64-osx                                       4.0.10-8         A library that supports the manipulation of TIFF...
zlib:x64-osx                                       1.2.11-6         A compression library

Ubuntu下

catch2:x64-ubuntu                                  2.11.1           A modern, header-only test framework for unit te...
ffmpeg:x64-ubuntu                                  4.2-5            a library to decode, encode, transcode, mux, dem...
ffmpeg[avresample]:x64-ubuntu                                       Libav audio resampling library support in ffmpeg
libjpeg-turbo:x64-ubuntu                           2.0.4            libjpeg-turbo is a JPEG image codec that uses SI...
liblzma:x64-ubuntu                                 5.2.4-4          Compression library with an API similar to that ...
libpng:x64-ubuntu                                  1.6.37-6         libpng is a library implementing an interface fo...
libwebp:x64-ubuntu                                 1.1.0            WebP codec: library to encode and decode images ...
libwebp[nearlossless]:x64-ubuntu                                    Enable near-lossless encoding
libwebp[simd]:x64-ubuntu                                            Enable any SIMD optimization.
opencv4:x64-ubuntu                                 4.1.1-3          computer vision library
opencv4[dnn]:x64-ubuntu                                             Enable dnn module
opencv4[jpeg]:x64-ubuntu                                            JPEG support for opencv
opencv4[opengl]:x64-ubuntu                                          opengl support for opencv
opencv4[png]:x64-ubuntu                                             PNG support for opencv
opencv4[tiff]:x64-ubuntu                                            TIFF support for opencv
opencv4[webp]:x64-ubuntu                                            WebP support for opencv
opengl:x64-ubuntu                                  0.0-5            Open Graphics Library (OpenGL)[3][4][5] is a cro...
protobuf:x64-ubuntu                                3.11.3           Protocol Buffers - Google's data interchange format
sdl2:x64-ubuntu                                    2.0.10-3         Simple DirectMedia Layer is a cross-platform dev...
tiff:x64-ubuntu                                    4.0.10-8         A library that supports the manipulation of TIFF...
zlib:x64-ubuntu                                    1.2.11-6         A compression library

Windows下:

catch2:x64-windows                                 2.11.1           A modern, header-only test framework for unit te...
ffmpeg:x64-windows                                 4.2-5            a library to decode, encode, transcode, mux, dem...
ffmpeg[avresample]:x64-windows                                      Libav audio resampling library support in ffmpeg
libjpeg-turbo:x64-windows                          2.0.4            libjpeg-turbo is a JPEG image codec that uses SI...
liblzma:x64-windows                                5.2.4-4          Compression library with an API similar to that ...
libpng:x64-windows                                 1.6.37-6         libpng is a library implementing an interface fo...
libwebp:x64-windows                                1.1.0            WebP codec: library to encode and decode images ...
libwebp[nearlossless]:x64-windows                                   Enable near-lossless encoding
libwebp[simd]:x64-windows                                           Enable any SIMD optimization.
libwebp[unicode]:x64-windows                                        Build Unicode executables. (Adds definition UNIC...
opencv4:x64-windows                                4.1.1-3          computer vision library
opencv4[dnn]:x64-windows                                            Enable dnn module
opencv4[jpeg]:x64-windows                                           JPEG support for opencv
opencv4[opengl]:x64-windows                                         opengl support for opencv
opencv4[png]:x64-windows                                            PNG support for opencv
opencv4[tiff]:x64-windows                                           TIFF support for opencv
opencv4[webp]:x64-windows                                           WebP support for opencv
opencv:x64-windows                                 4.1.1-1          Computer vision library
opencv[dnn]:x64-windows                                             Enable dnn module
opencv[jpeg]:x64-windows                                            JPEG support for opencv
opencv[opengl]:x64-windows                                          opengl support for opencv
opencv[png]:x64-windows                                             PNG support for opencv
opencv[tiff]:x64-windows                                            TIFF support for opencv
opencv[webp]:x64-windows                                            WebP support for opencv
opengl:x64-windows                                 0.0-5            Open Graphics Library (OpenGL)[3][4][5] is a cro...
protobuf:x64-windows                               3.11.3           Protocol Buffers - Google's data interchange format
sdl2:x64-windows                                   2.0.10-2         Simple DirectMedia Layer is a cross-platform dev...
tiff:x64-windows                                   4.0.10-8         A library that supports the manipulation of TIFF...
zlib:x64-windows                                   1.2.11-6         A compression library
zlib:x86-windows                                   1.2.11-6         A compression library