MinGW32 compiled ffmpeg + libsrt

Foreword

National data on SRT agreement is almost zero, with no one to srt protocol compiled ffmpeg, and this stuff under Windows compile various pit, I engage in a full ten days, almost all online information in English, some errors can not find out, it is despair, with the help of master Cheng, stumbled to compile this thing out. (If you do not want to compile, can be directly under my programmed srt Library , but delegate to fish than giving the fish)

Why not use cygwin compiler, cygwin compiled srt when there are options for use-cygwin-posix, which means using cygwin posix standard that provides a set of threads library, it can only lead to cygwin compiled out below, can not be run in the following powershell, put on someone else's computer can only be installed in others to run the cygwin case, very troublesome, my goal is to compile can be performed directly on someone else's computer .exefiles, cygwin can not achieve their goals, to switch to MinGW

MinGW installation

After this much go into details, the basic components can be, and instructions for installing the Internet very much, do not go into details, installed basic MinGW, open msys need to install several packages are as follows:

Specifically how you can install on their own Baidu search, but more description here, this is not Benpian focus.

SDL can compile your own can own the next, MinGW installer no SDL library, go to the official website to download, the need for other versions of SDL can be added to the URL releaseyou can, do not want the compiler can download the version in the following figure.
SDL does not need to compile your own
According to the official document describes, 1.0.2r openssl version can be used, if the update later, then follow the latest documentation download, although MinGW provide openssl, but after verification found that not all configuration information, convenience directly translated like, you can also go to github download: https://github.com/openssl/openssl.
pkg-config component of a package management, can .pcfind the location of the library and header file configuration file, put the MinGW bindirectory can.
pkg-config required libglib-2.0-0.dll, copy the file to the bindirectory, and can be put together pkg-config.

CMAKE installation

This nothing to say, posted a good link to download their own
https://cmake.org/download/

Visual Studio 2017 installed

This is also nothing to say, is installed on the bin. Why install VS, because we need vs the back cl.exeand to help us build cmake combination srt project, compile a library.
https://visualstudio.microsoft.com/zh-hans/downloads/
Community Edition is free, there is no need to install Pro Community Edition enough to use, remember to install the Windows SDK, I am here only the most basic equipment package
vs installation

Support windows Thread Library

If you do not want to hear my long-winded, my conclusion is that you need to compile win32the thread library, so the direct release of Win32 threads compiled it with VS, and the document can not be said of a compiled x64library, so can not be used in MinGW below.

According to SRT official documents say, need to use threads library compiled vs windwos can be used, so to find this pthread library from the document, download, according to the method given in the document compiled libraries into the specified path.
Thread Library Address: https://github.com/GerHobbelt/pthread-win32
then pit father's place again ......
explanation given in the official documentation:

  • a. Using Visual Studio 2013, please open this file:
    pthread_lib.2013.vcxproj

  • b. Make sure to select configuration: Release and x64.

  • (They are in the toplevel directory, there are actually no meaningful subdirs here) (NOTE: the win32 is part of the project name. It will become 32 or 64 depending on selection)

什么意思呢,就是这个默认位置的文件夹命名是pthread-win32,win32仅仅是名字,根据选择他会变成32位或者64位,然后按照官方文档前面写的说明,我应该选择的是releasex64编出来的线程库。

这个时候问题来了,MinGW使用./configure之后调用去cmake构建srt项目后,默认构建的项目是win32,使用的工具链也是vs的,然后用vs去打开项目编译srt发现很多pthread找不到标识符的错误。

一开始以为是MinGW的问题,没有找到这个库,遂用cygwin去编译,发现这个线程库在用cygwin确实能识别当前是32位还是64位,使用cygwin64编出来的东西就是x64的,使用cygwin编出来就是i386的,但是VS编译的时候居然找不到标识符,后来发现这个玩意在VS里面压根就不会自动选择是32位还是64位,要是64位的库,我去构建win32的库压根无法识别pthread_lib.lib里面的内容。

解释完了,意思就是这个线程库,MinGW去构建不能像文档说的编出x64的库去用,而是需要选择win32去编译这个线程库,才能在之后的srt编译中不出现问题,所以实际应该和我下图贴出来的一样去编译
pthread Library Compiler

SRT库的编译

SRT库下载地址:https://github.com/Haivision/srt

SRT文档中对SRT编译前置条件描述:

  • cmake (as build system)
  • Tcl 8.5 (optional for user-friendly build system)
  • OpenSSL
  • Pthreads (for POSIX systems it’s builtin, for Windows there’s a library)

其中tcl如果没有安装的话,直接去MinGW的安装文件里面去找一个叫tclsh的包,勾选安装即可,这个在configure的时候用得到

openssl的安装

这东西需要openssl支持,所以在编译之前需要先把openssl给弄好。

http://slproweb.com/products/Win32OpenSSL.html
从官方文档提供的网址下一个Windows可以直接安装的版本,不需要自己编译,一样,用的1.0.2r,之后如果版本更新了,请按照文档来,这里下载的还是32位的,为了防止出现各种幺蛾子,统一用32位。

这个为什么还要再装一个呢,目的是为了给vs编译srt用,等会ffmpeg编译的时候也会用到openssl,那个openssl用的是编译出来的,两个放的目录不一样,为了我们之后的方便,Windows装一个放到默认目录省事,不用自己去指定目录,默认目录是C:\OpenSSL-Win32

当然,如果你想用源码编译一份,完全可以,用vs编译openssl看这:https://blog.csdn.net/sky101010ws/article/details/51682725

SRT编译

然后正式进入srt编译,MinGW没有自己的cmake,因此只能使用cmake提供的gui,srt协议编译库需要使用configure文件。

这里我犯了一个错误,由于我发现configure文件里面在一系列检测之后还是调用了cmake,所以我就直接使用cmake -G"Unix Makefiles" .去生成makefile文件,然后出现了一大堆错误,后来在hook的指导下,才知道这样越过configure文件是错误的编译方式,configure文件会帮我们配置一些环境,直接跳过configure去cmake显然不可取。

./configure --enable-static --disable-shared

可能会出现tclsh没有找到的问题,原因是configure文件第一行写的是#!/usr/bin/tclsh,然而我们的tclsh并没有装在/usr/bin,我的tclsh是在/MinGW/bin目录下,修改一下即可。

完成之后,使用VS去编译SRT库,注意,默认使用MinGW配合CMake生成的VS项目应该是32位的(Win32),确认后用VS生成项目即可,生成完毕后会得到一些.lib.exp.dll.exe文件。
Here Insert Picture Description
编译好的SRT按照下面给出的地方放置到/usr/local下,给出/usr/loacl我的参考路径——E:\MinGW32\msys\1.0\local\srt,在SRT的目录中将需要的文件移到/usr/local下面

srt/
├── bin
│   ├── srt.dll
│   ├── srt-file-transmit.exe
│   ├── srt-live-transmit.exe
│   └── srt-multiplex.exe
├── include
│   └── srt
│       ├── in6addr.h
│       ├── logging_api.h
│       ├── platform_sys.h
│       ├── srt.h
│       ├── srt4udt.h
│       ├── udt.h
│       ├── version.h
│       ├── win
│       │   ├── syslog_defs.h
│       │   └── unistd.h
│       ├── winapifamily.h
│       └── ws2ipdef.h
└── lib
    ├── pkgconfig
    │   ├── haisrt.pc
    │   └── srt.pc
    ├── srt.exp
    ├── srt.ilk
    ├── srt.lib
    ├── srt.pdb
    ├── srt_static.lib
    ├── srt_static.pdb
    ├── srt-file-transmit.exp
    ├── srt-file-transmit.ilk
    ├── srt-file-transmit.lib
    ├── srt-file-transmit.pdb
    ├── srt-live-transmit.exp
    ├── srt-live-transmit.ilk
    ├── srt-live-transmit.lib
    ├── srt-live-transmit.pdb
    ├── srt-multiplex.exp
    ├── srt-multiplex.ilk
    ├── srt-multiplex.lib
    └── srt-multiplex.pdb

6 directories, 35 files

MinGW下的SDL和openssl

为什么要自己编译openssl前面已经说过了,MinGW自带的openssl配置信息有误

openssl

openssl编译前置条件

  * make
  * Perl 5
  * an ANSI C compiler
  * a development environment in form of development libraries and C header files
  * a supported Unix operating system

装好make和perl 5后开始编译,请按照INSTALL文件提供的方法去编译

  $ ./config
  $ make
  $ make test
  $ make install

SDL

这里我就不编译库了,直接拿官方安装好的库去使用,执行以下命令即可,文件将会移到默认位置

  $ make native

ffmpeg编译

PKG-CONFIG配置

pkg-config是通过PKG_CONFIG_PATH这个环境变量进行查找包的,比如:SDL2库有SDL2.pc这个文件,.pc文件里面存放了库的配置信息,比如头文件放在哪,库文件放在哪等等。
由于我们的库都在不同的地方,因此需要我们自己去指定opensslSDLsrt的路径。
比如,我的库的位置是在/usr/local下面的三个文件,那么我的配置应该是

  $ export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/SDL/lib/pkgconfig:/usr/local/srt/lib/pkgconfig:/usr/local/openssl/lib/pkgcongig

务必要把所有需要用到的库包含进去,这个目录要根据自己的情况写,之后用以下命令查看pkg-config是否能找到这几个库

  $ pkg-config --list-all

Here Insert Picture Description

ffmpeg

准备工作结束,正式编译ffmpeg,可以看到有些文章编译ffmpeg之前装过nasm/yasm这个交叉编译的汇编器,但是我测试的时候发现如果使用yasm去编译,最后出来得ffmpeg根本无法使用,因此使用--disable-x86asm选项,--enable-sdl2是为了确保肯定会去检测SDL2,以便编译出ffplay,在configure的help说明中,sdl2是自动检测的,这里写出来只是为了确保一定会去尝试使用sdl2去编译ffplay。

./configure --enable-static --disable-shared --enable-libsrt --disable-x86asm --enable-sdl2

成功生成makefile之后的情况
Here Insert Picture Description
可以看到有SDL2出现,表示最后能够生成ffplay
Here Insert Picture Description
可以看到Enabled protocols里面,存在一个libsrt在其中,可以说成功了一半。
之后便是make的过程了,直接执行

  $ make -j8

make the process, there will be a few questions, the first is a redefinition of the problem, srt.h redefined in several types, we need to comment out of him.
Note
Then a MinGW own bug, a problem cited winsock2.h after winsock.h.
After a: libformat / os_support.c: error:. 'ERROR_NOT_ENOUGH_MEMORY' undeclared (first use in this function) case EAI_MEMORY
these two issues in a blog others have a solution, I'll just quoted, Here is the link:
HTTPS : //blog.csdn.net/kl794756707/article/details/82808514

Compilation is completed
Compilation is completed
after to get rid of these problems, successfully compile ffmpeg, ffprobe, ffplay, test ~ ~ ~ ~ In powershell
test

Published 89 original articles · won praise 96 · views 90000 +

Guess you like

Origin blog.csdn.net/Boring_Wednesday/article/details/88674854