ccap

A high-performance, lightweight cross-platform camera capture library with hardware-accelerated pixel format conversion.

高性能、轻量级的跨平台相机捕获库,支持硬件加速的像素格式转换。

Features

特性

High Performance

高性能

Hardware-accelerated pixel format conversion with up to 10x speedup using AVX2, Apple Accelerate, and NEON.

硬件加速的像素格式转换,使用 AVX2、Apple Accelerate 和 NEON 可提升高达 10 倍性能。

🪶

Lightweight

轻量级

Zero external dependencies - uses only system frameworks for maximum portability.

零外部依赖,仅使用系统框架,实现最大可移植性。

🌍

Cross Platform

跨平台

Native support for Windows (DirectShow), macOS/iOS (AVFoundation), and Linux (V4L2).

原生支持 Windows (DirectShow)、macOS/iOS (AVFoundation) 和 Linux (V4L2)。

🎨

Multiple Formats

多种格式

Support for RGB, BGR, YUV (NV12/I420) with automatic format conversion.

支持 RGB、BGR、YUV(NV12/I420)及自动格式转换。

🔧

Dual Language APIs

双语言接口

Both modern C++ API and pure C99 interface for various project integration and language bindings.

同时提供现代 C++ API 和纯 C99 接口,支持各种项目集成和语言绑定。

Production Ready

生产就绪

Comprehensive test suite with 95%+ accuracy validation and 50+ test cases.

完整测试套件,95%+ 精度验证,50+ 测试用例。

Supported Platforms

支持的平台

🪟

Windows

DirectShow

MSVC 2019+

🍎

macOS

AVFoundation

Xcode 11+, macOS 10.13+

📱

iOS

AVFoundation

Xcode 11+, iOS 13.0+

🐧

Linux

V4L2

GCC 7+ / Clang 6+

Quick Start

快速开始

// C++ Example
#include <ccap.h>

int main() {
    ccap::Provider provider;
    
    // List available cameras
    auto devices = provider.findDeviceNames();
    for (size_t i = 0; i < devices.size(); ++i) {
        printf("[%zu] %s\n", i, devices[i].c_str());
    }
    
    // Open and start camera
    if (provider.open("", true)) {
        auto frame = provider.grab(3000);
        if (frame) {
            printf("Captured: %dx%d\n", 
                   frame->width, frame->height);
        }
    }
    return 0;
}
// Pure C Example
#include <ccap_c.h>
#include <ccap_utils_c.h>

int main() {
    CcapProvider* provider = ccap_provider_create();
    if (!provider) return -1;
    
    // Find available devices
    CcapDeviceNamesList deviceList;
    if (ccap_provider_find_device_names_list(provider, &deviceList)) {
        printf("Found %zu camera(s)\n", deviceList.deviceCount);
    }
    
    // Open and capture
    if (ccap_provider_open(provider, NULL, true)) {
        CcapVideoFrame* frame = ccap_provider_grab(provider, 3000);
        if (frame) {
            CcapVideoFrameInfo info;
            ccap_video_frame_get_info(frame, &info);
            printf("Captured: %dx%d\n", info.width, info.height);
            ccap_video_frame_release(frame);
        }
    }
    
    ccap_provider_destroy(provider);
    return 0;
}

Installation

安装

Build from Source

从源码构建

git clone https://github.com/wysaid/CameraCapture.git
cd CameraCapture
./scripts/build_and_install.sh

CMake FetchContent

include(FetchContent)
FetchContent_Declare(
    ccap
    GIT_REPOSITORY https://github.com/wysaid/CameraCapture.git
    GIT_TAG main
)
FetchContent_MakeAvailable(ccap)

target_link_libraries(your_app PRIVATE ccap::ccap)

Homebrew (macOS)

brew tap wysaid/ccap
brew install ccap

CMake Integration

CMake 集成

find_package(ccap REQUIRED)
target_link_libraries(your_app ccap::ccap)

System Requirements

系统要求

Platform平台 Compiler编译器 Requirements要求
Windows MSVC 2019+ DirectShow
macOS Xcode 11+ macOS 10.13+
iOS Xcode 11+ iOS 13.0+
Linux GCC 7+ / Clang 6+ V4L2 (Linux 2.6+)

Build Requirements: CMake 3.14+, C++17 (C++ interface), C99 (C interface) 构建要求:CMake 3.14+,C++17(C++ 接口),C99(C 接口)