Compile FFmpeg 7 with OpenSSL
To process HTTPS, RTMPS, or TLS streams, FFmpeg must be linked against OpenSSL. Here is the definitive cross-platform guide to compiling them from source.
Required Tools & Source
Ensure you have the latest stable releases
Linux (Ubuntu/Debian) 编译步骤
sudo apt updatesudo apt install build-essential pkg-config nasm yasm curl# 解压并进入源码目录tar -zxf openssl-3.*.tar.gz && cd openssl-3.*/# 配置安装路径到 /usr/local/openssl./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl shared zlibmake -j$(nproc)sudo make installtar -xvf ffmpeg-7.*.tar.bz2 && cd ffmpeg-7.*/# 导出 PKG_CONFIG 环境变量,让 FFmpeg 找到刚才编译的 OpenSSLexport PKG_CONFIG_PATH=/usr/local/openssl/lib64/pkgconfig:$PKG_CONFIG_PATH./configure \--prefix=/usr/local/ffmpeg \--enable-shared \--enable-openssl \--enable-nonfree \--extra-cflags="-I/usr/local/openssl/include" \--extra-ldflags="-L/usr/local/openssl/lib64"make -j$(nproc)sudo make installmacOS (Apple Silicon / Intel) 编译步骤
# macOS 下自带的 OpenSSL 被替换成了 LibreSSL,所以推荐用 brew 装个标准的,或者从源码编译brew install pkg-config nasm openssl@3# 获取 Homebrew 安装的 OpenSSL 路径 (Apple Silicon 默认在 /opt/homebrew)export OPENSSL_DIR=$(brew --prefix openssl@3)export PKG_CONFIG_PATH=$OPENSSL_DIR/lib/pkgconfig./configure \--prefix=/usr/local/ffmpeg \--enable-shared \--enable-openssl \--enable-nonfree \--extra-cflags="-I$OPENSSL_DIR/include" \--extra-ldflags="-L$OPENSSL_DIR/lib"make -j8sudo make installWindows (MSYS2 + MinGW) 编译步骤
# 安装好 MSYS2 后,打开 "MSYS2 UCRT64" 终端执行:pacman -Syupacman -S mingw-w64-ucrt-x86_64-toolchain base-devel nasm pkg-config# 在 MSYS2 中解压 openssl 源码并进入./Configure mingw64 --prefix=/ucrt64 sharedmake -j16make install# 因为 OpenSSL 装在了 MSYS2 的系统路径下,所以 pkg-config 会自动找到它./configure \--arch=x86_64 \--target-os=mingw32 \--enable-shared \--enable-openssl \--enable-nonfreemake -j16# 编译完成后,会在当前目录生成 ffmpeg.exe,以及需要的 avcodec-61.dll 等动态库Verification & Usage
Testing your newly compiled FFmpeg build
./ffmpeg -protocols | grep https...
https
Output:
...
https
如果能查看到 `https` 协议,说明 OpenSSL 已经成功链接进入 FFmpeg。
extern"C"{#include<libavformat/avformat.h>#include<libavformat/avio.h>}intmain() { avformat_network_init();// 必须调用此函数初始化网络组件AVFormatContext *fmt_ctx = nullptr;const char*url ="https://example.com/stream.m3u8";// 如果没有编译 OpenSSL,这里将返回 Protocol not found 错误intret = avformat_open_input(&fmt_ctx, url, nullptr, nullptr);if(ret < 0) { printf("Failed to open HTTPS stream: %d\n", ret);return-1; } printf("HTTPS Stream opened successfully!\n"); avformat_close_input(&fmt_ctx); avformat_network_deinit();return0; }
Explore More#ffmpeg-dev
FFmpeg Building Guide
ArticleA detailed step-by-step guide on how to compile FFmpeg from source on different platforms.
FFmpeg and x264 Compilation Guide
ArticleA detailed step-by-step guide on how to compile FFmpeg from source and integrate x264 on different platforms.
Essential FFmpeg Commands
ArticleA quick reference guide for essential FFmpeg commands covering common operations like media processing, format conversion, and compression optimization.
FFmpeg C++ Video Player Development Guide
ArticleA detailed step-by-step guide on how to develop a simple C++ video player using the FFmpeg library.
FFmpeg 7 Compilation Guide
ArticleA detailed step-by-step guide on how to compile FFmpeg 7 from source on different platforms.
FFmpeg FFplay.c Source Code Analysis
ArticleA detailed analysis of the FFplay.c source code in FFmpeg, helping developers understand the implementation principles of video players.
FFmpeg + OpenSSL Compilation Guide
ArticleA detailed step-by-step guide on how to compile FFmpeg from source and integrate OpenSSL on different platforms for HTTPS streaming support.
FFmpeg + OpenCV Face Recognition and Video Processing
ArticleA detailed demonstration of how to use FFmpeg and OpenCV on mobile platforms to implement face recognition and video processing features.
FFmpeg + OpenCV Mask Processing and Video Analysis
ArticleA detailed demonstration of how to use FFmpeg and OpenCV on mobile platforms to implement mask processing and video analysis features.
