|
|
||
|---|---|---|
| cmake | ||
| include | ||
| src | ||
| .gitignore | ||
| .gitmodules | ||
| CMakeLists.txt | ||
| CMakePresets.json | ||
| README.md | ||
| vcpkg.json | ||
README.md
FFmpeg OpenCV Example
A boilerplate application that will build with ffmpeg libraries and OpenCV to perform image-editing operations if needed. Use this as the basis of a number of higher-performance rewrites of old node.js and Python scripts that call out to the shell to do these ops.
Prerequisites
- CMake ≥ 3.20
- A C++17 compiler (Clang on macOS, GCC on Linux, MSVC on Windows)
- vcpkg (recommended — see below), or system packages for OpenCV + FFmpeg + pkg-config
Option A: vcpkg (recommended, same steps on all platforms)
# one-time setup
git clone https://github.com/microsoft/vcpkg
./vcpkg/bootstrap-vcpkg.sh # macOS/Linux
# .\vcpkg\bootstrap-vcpkg.bat # Windows
export VCPKG_ROOT=$PWD/vcpkg # macOS/Linux
# $env:VCPKG_ROOT = "$PWD\vcpkg" # Windows (PowerShell)
Dependencies (ffmpeg, opencv4, pkgconf) are declared in vcpkg.json
and will be installed automatically the first time you configure.
Option B: system packages
macOS (Homebrew):
brew install cmake ffmpeg opencv pkg-config
Linux (Debian/Ubuntu):
sudo apt update
sudo apt install -y cmake build-essential pkg-config \
libavformat-dev libavcodec-dev libavutil-dev libswscale-dev libswresample-dev \
libopencv-dev
Windows: system-package installs of FFmpeg/OpenCV are inconsistent enough (no standard pkg-config, mismatched dev headers) that vcpkg is strongly recommended on Windows specifically.
Building
With vcpkg + CMake presets
cmake --preset linux # or: macos / windows
cmake --build --preset linux
The binary is written to build/<preset>/bin/.
With system packages (no presets)
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release
Running
./build/linux/bin/ffmpeg_opencv_cli input.mp4 first_frame.png
./build/linux/bin/ffmpeg_opencv_cli input.mp4 frame_10.png 10