FFmpeg + OpenCV example application that builds on macOS, Windows and Linux
Go to file
Matt McWilliams 934806fc67 Replace error statements with log.message 2026-08-09 08:30:49 -04:00
cmake Fixed build 2026-08-02 12:38:54 -04:00
include Replace error statements with log.message 2026-08-09 08:30:49 -04:00
src Remove excessive comments 2026-08-09 07:58:42 -04:00
.gitignore Ignore DS_Store files 2026-08-03 11:48:52 -04:00
.gitmodules Lock commit at one I have been using reliably elsewhere 2026-08-03 11:20:28 -04:00
CMakeLists.txt Add Logger class candidate for log messages 2026-08-03 11:01:55 -04:00
CMakePresets.json Example without Args.h, adding now 2026-08-02 08:20:55 -04:00
README.md Example without Args.h, adding now 2026-08-02 08:20:55 -04:00
vcpkg.json Example without Args.h, adding now 2026-08-02 08:20:55 -04:00

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
# 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