百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
C

CameraCapture

> 开发工具
开源

ccap(C(C)amera(CAP)ture)是一款简单易用的 C/C++ 摄像头采集库,旨在为您提供简单高效的摄像头数据访问。它支持多种摄像头接口,包括 USB、FireWire、GigE、VGA、HDMI、DVI、V4L2、V4L2+、V4L2++、V4L2++++、V4L2++++++、V4L2++++++++、V4L2++++++++++、V4L2++++++++++++、V4L2++++++++++++++、V4L2++++++++++++++++、V4L2++++++++++++++++++、V4L2++++++++++++++++++++、V4L2++++++++++++++++++++++、V4L2++++++++++++++++++++++++、V4L2++++++++++++++++++++++++++、V4L2++++++

186 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

ccap(C(C)amera(CAP)ture)是一款简单易用的 C/C++ 摄像头采集库,旨在为您提供简单高效的摄像头数据访问。它支持多种摄像头接口,包括 USB、FireWire、GigE、VGA、HDMI、DVI、V4L2、V4L2+、V4L2++、V4L2++++、V4L2++++++、V4L2++++++++、V4L2++++++++++、V4L2++++++++++++、V4L2++++++++++++++、V4L2++++++++++++++++、V4L2++++++++++++++++++、V4L2++++++++++++++++++++、V4L2++++++++++++++++++++++、V4L2++++++++++++++++++++++++、V4L2++++++++++++++++++++++++++、V4L2++++++

ccap (CameraCapture)

English | 中文

A high-performance, lightweight cross-platform camera capture library with hardware-accelerated pixel format conversion, supporting both camera capture and video file playback (Windows/macOS). On Windows, ccap now fully supports both DirectShow and Media Foundation, with DirectShow remaining the default for strong virtual-camera compatibility. Provides complete C++ and pure C interfaces, plus Rust bindings.

Official Website: ccap.work

Table of Contents

  • Features
  • Quick Start
  • System Requirements
  • Examples
  • API Reference
  • Testing
  • Build and Install
  • Contributors
  • License

Features

  • High Performance: Hardware-accelerated pixel format conversion with up to 10x speedup (AVX2, Apple Accelerate, NEON)
  • Lightweight: No third-party dependencies - uses only system frameworks
  • Cross Platform: Windows (dual backends: DirectShow by default, Media Foundation fully supported), macOS/iOS (AVFoundation), Linux (V4L2)
  • Windows Dual Backends: DirectShow stays the default on Windows for compatibility with OBS Virtual Camera and other virtual devices, while Media Foundation is also fully supported through auto, environment overrides, and explicit backend selection
  • Multiple Formats: RGB, BGR, YUV (NV12/I420) with automatic conversion
  • Dual Language APIs: ✨ Complete Pure C Interface - Both modern C++ API and traditional C99 interface for various project integration and language bindings
  • Video File Playback: Play video files (MP4, AVI, MOV, etc.) using the same API as camera capture - supports Windows and macOS
  • Video Writing / Recording: Write MP4/MOV files from camera frames via ccap::VideoWriter, ccap_video_writer_*, or CLI --record (Windows/macOS, CCAP_ENABLE_VIDEO_WRITER=ON)
  • CLI Tool: Ready-to-use command-line tool for quick camera operations and video processing - list devices, capture images, real-time preview, video playback (Documentation)
  • Production Ready: Comprehensive test suite with 95%+ accuracy validation
  • Virtual Camera Support: Compatible with OBS Virtual Camera and similar tools through the default DirectShow path on Windows

Quick Start

Agent Skill

This repository also includes a standalone agent skill for ccap, which can be used as a standard skill entry for installation, device inspection, capture, and video inspection workflows.

  • Skill folder: skills/ccap
  • Skill definition: skills/ccap/SKILL.md

Use this skill when you want an agent to work through the practical ccap flows instead of reading the source tree first, for example:

  • install ccap on the current machine
  • list available camera devices
  • inspect device capabilities
  • capture frames or preview video with the CLI
  • inspect video metadata with structured output when available

The skill guides agents to choose among an existing installation, Homebrew on macOS, source builds, and release-binary fallback, then prefer the ccap CLI with --json where supported.

Installation

  1. Build and install from source (on Windows, use git-bash):

    bash
    git clone https://github.com/wysaid/CameraCapture.git
    cd CameraCapture
    ./scripts/build_and_install.sh
  2. Integrate directly using CMake FetchContent:

    Add the following to your CMakeLists.txt:

    cmake
    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)

    You can then use ccap headers and features directly in your project.

  3. Install and use via Homebrew on macOS:

    • First, install the binary with Homebrew:

      bash
      brew tap wysaid/ccap
      brew install ccap
    • Then, use it in CMake:

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

Basic Usage

ccap provides both complete C++ and pure C language interfaces to meet different project and development requirements:

  • C++ Interface: Modern C++ API with smart pointers, lambda callbacks, and other advanced features
  • Pure C Interface: Fully compatible with C99 standard, supporting language bindings and traditional C project integration

C++ Interface

cpp
#include 

int main() {
    ccap::Provider provider;
    
    // List available cameras
    auto devices = provider.findDeviceNames();
    for (size_t i = 0; i width, frame->height,
                   ccap::pixelFormatToString(frame->pixelFormat).data());
        }
    }
    return 0;
}
Error Handling in C++

Starting from v1.2.0, ccap uses a global error callback system for simplified error handling across all camera operations:

…

powershell

PowerShell: opt into Media Foundation for the current process

$env:CCAP_WINDOWS_BACKEND = "msmf" .\ccap --list-devices


```cpp
// Force Media Foundation explicitly on Windows
ccap::Provider msmfProvider("", "msmf");

// Force DirectShow explicitly on Windows
ccap::Provider dshowProvider("", "dshow");

Rust Bindings

Rust bindings are available as a crate on crates.io:

  • Crate: ccap-rs on crates.io
  • Docs: docs.rs/ccap-rs
  • Source: bindings/rust/

Quick install:

bash
cargo add ccap-rs

Or, if you want the crate name in code to be ccap:

toml
[dependencies]
ccap = { package = "ccap-rs", version = "" }

CLI Tool

ccap includes a powerful command-line tool for quick camera operations and video processing without writing code:

bash
# Build with CLI tool enabled
mkdir build && cd build
cmake .. -DCCAP_BUILD_CLI=ON
cmake --build .

# List available cameras
./ccap --list-devices

# Capture 5 images from default camera
./ccap -c 5 -o ./captures

# Real-time preview (requires GLFW)
./ccap --preview

# Play video file and extract frames
./ccap -i video.mp4 -c 30 -o ./frames

# Video preview with playback controls
./ccap -i video.mp4 --preview --speed 1.0

# Record camera stream to MP4 (Windows/macOS)
./ccap -d 0 --record ./camera_capture.mp4 --timeout 5

…

bash
bash
mkdir build && cd build
cmake .. -DCCAP_BUILD_EXAMPLES=ON
cmake --build .

# Run examples
./0-print_camera
./1-minimal_example

# Run the pure C variants (if you built C examples)
./0-print_camera_c
./1-minimal_example_c

Note: Each desktop example is available in both C++ (.cpp) and pure C (.c) variants. Use the filenames with a trailing _c (e.g. 1-minimal_example_c.c) for the C versions.

API Reference

ccap provides both complete C++ and pure C interfaces to meet different project requirements.

Core Classes

ccap::Provider

cpp
class Provider {
public:
    // Constructors
    Provider();
    Provider(std::string_view deviceName, std::string_view extraInfo = "");
    Provider(int deviceIndex, std::string_view extraInfo = "");
    
    // Device discovery
    std::vector findDeviceNames();
    
    // Camera lifecycle
    bool open(std::string_view deviceName = "", bool autoStart = true);
    bool open(int deviceIndex, bool autoStart = true);
    bool isOpened() const;
    void close();
    
    // Capture control
    bool start();
    void stop();
    bool isStarted() const;
    
    // Frame capture
    std::shared_ptr grab(uint32_t timeoutInMs = 0xffffffff);
    void setNewFrameCallback(std::function&)> callback);
    
    // Property configuration
    bool set(PropertyName prop, double value);
    template bool set(PropertyName prop, T value);
    double get(PropertyName prop);
    
    // Device info and advanced configuration
    std::optional getDeviceInfo() const;
    bool isFileMode() const;  // Check if playing video file vs camera
    void setFrameAllocator(std::function allocatorFactory);
    void setMaxAvailableFrameSize(uint32_t size);
    void setMaxCacheFrameSize(uint32_t size);
};

ccap::VideoFrame

cpp
struct VideoFrame {
    
    // Frame data
    uint8_t* data[3] = {};                  // Raw pixel data planes
    uint32_t stride[3] = {};                // Stride for each plane
    
    // Frame properties
    PixelFormat pixelFormat = PixelFormat::Unknown;  // Pixel format
    uint32_t width = 0;                     // Frame width in pixels
    uint32_t height = 0;                    // Frame height in pixels
    uint32_t sizeInBytes = 0;               // Total frame data size
    uint64_t timestamp = 0;                 // Frame timestamp in nanoseconds
    uint64_t frameIndex = 0;                // Unique incremental frame index
    FrameOrientation orientation = FrameOrientation::Default;  // Frame orientation
    
    // Memory management and platform features
    std::shared_ptr allocator;   // Memory allocator
    void* nativeHandle = nullptr;           // Platform-specific handle
};

Configuration

cpp
enum class PropertyName {
    Width, Height, FrameRate,
    PixelFormatInternal,        // Camera's internal format
    PixelFormatOutput,          // Output format (with conversion)
    FrameOrientation,
    
    // Video file playback properties (file mode only)
    Duration,                   // Video duration in seconds (read-only)
    CurrentTime,                // Current playback time in seconds
    FrameCount,                 // Total frame count (read-only)
    PlaybackSpeed               // Playback speed multiplier (1.0 = normal speed)
};

enum class PixelFormat : uint32_t {
    Unknown = 0,
    NV12, NV12f,               // YUV 4:2:0 semi-planar
    I420, I420f,               // YUV 4:2:0 planar  
    RGB24, BGR24,              // 24-bit RGB/BGR
    RGBA32, BGRA32             // 32-bit RGBA/BGRA
};

Video Writing (Windows/macOS)

Video writing is available on Windows and macOS when CCAP_ENABLE_VIDEO_WRITER=ON.

cpp
#include 
#include 

ccap::Provider provider;
ccap::VideoWriter writer;

if (provider.open("", true)) {
    ccap::WriterConfig cfg;
    cfg.width = 1280;
    cfg.height = 720;
    cfg.frameRate = 30.0;
    cfg.codec = ccap::VideoCodec::H264;
    cfg.container = ccap::VideoFormat::MP4;

    if (writer.open("camera_record.mp4", cfg)) {
        while (auto frame = provider.grab(3000)) {
            // timestampNs == 0 means auto timestamp generation from frameRate.
            writer.writeFrame(*frame, 0);
        }
        writer.close();
    }
}

Notes:

  • Writer input supports NV12, I420, BGR24, and BGRA32.
  • VideoFrame::orientation is honored by the writer path (including BottomToTop frames common on Windows RGB capture).
  • CCAP_ENABLE_VIDEO_WRITER is independent from CCAP_ENABLE_FILE_PLAYBACK.

Utility Functions

cpp
namespace ccap {
    // Hardware capabilities
    bool hasAVX2();
    bool hasAppleAccelerate();
    bool hasNEON();
    
    // Backend management
    ConvertBackend getConvertBackend();
    bool setConvertBackend(ConvertBackend backend);
    
    // Format utilities
    std::string_view pixelFormatToString(PixelFormat format);
    
    // File operations
    std::string dumpFrameToFile(VideoFrame* frame, std::string_view filename);
    
    // Logging
    enum class LogLevel { None, Error, Warning, Info, Verbose };
    void setLogLevel(LogLevel level);
}

Video File Playback

ccap supports playing video files using the same API as camera capture (Windows and macOS only):

cpp
#include 

ccap::Provider provider;

// Open video file - same API as camera
if (provider.open("/path/to/video.mp4", true)) {
    // Check if in file mode
    if (provider.isFileMode()) {
        // Get video proper

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C++avfoundationcameracaptureccap

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类开发工具
定价开源

> 相关工具

V
VS Code
流行的开源代码编辑器
G
Git
分布式版本控制系统
V
Vite
下一代前端构建工具