Skip to content

Zig FFI bindings for FFmpeg/libav - Inspired by panoptes video analysis needs

License

Notifications You must be signed in to change notification settings

hyperpolymath/zig-ffmpeg-ffi

Repository files navigation

zig-ffmpeg-ffi

Zig FFI bindings for FFmpeg (libavformat, libavcodec, libavutil).

Overview

High-performance Zig interface for video/audio metadata extraction and format operations. Replaces subprocess calls to ffprobe/ffmpeg with direct library bindings.

Installation

System Requirements

Platform Command

Fedora

sudo dnf install ffmpeg-free-devel

Ubuntu/Debian

sudo apt install libavformat-dev libavcodec-dev libavutil-dev

macOS

brew install ffmpeg

Arch

sudo pacman -S ffmpeg

Building

zig build
zig build test
zig build run -- /path/to/video.mp4

Usage

Zig

const ffmpeg = @import("zig-ffmpeg-ffi");

var info = try ffmpeg.probe(allocator, "video.mp4");
defer info.deinit();

std.debug.print("Duration: {d:.2}s\n", .{info.duration_seconds});
std.debug.print("Format: {s}\n", .{info.format_name orelse "unknown"});

for (info.streams) |stream| {
    if (stream.stream_type == .video) {
        std.debug.print("Video: {}x{} @ {d:.2}fps\n", .{
            stream.width orelse 0,
            stream.height orelse 0,
            stream.frame_rate orelse 0,
        });
    }
}

C FFI (for Rust/Deno/ReScript)

#include "ffmpeg_ffi.h"

FFIMediaInfo* info = ffmpeg_probe("video.mp4");
if (info) {
    double duration = ffmpeg_get_duration(info);
    int64_t bitrate = ffmpeg_get_bitrate(info);

    uint32_t count = ffmpeg_get_stream_count(info);
    for (uint32_t i = 0; i < count; i++) {
        CStreamInfo stream;
        if (ffmpeg_get_stream(info, i, &stream)) {
            // Use stream.width, stream.height, etc.
        }
    }

    ffmpeg_free(info);
}

Provenance

This library was inspired by panoptes video analysis needs. See PROVENANCE.md for details.

License

PMPL-1.0-or-later

About

Zig FFI bindings for FFmpeg/libav - Inspired by panoptes video analysis needs

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •