|
| 1 | +# ffmpeg-statigo Copilot Instructions |
| 2 | + |
| 3 | +## Project Overview |
| 4 | + |
| 5 | +Go bindings for FFmpeg 8.0 static libraries. Ships ~100MB platform-specific `libffmpeg.a` files that link directly into Go binaries—no system FFmpeg required. |
| 6 | + |
| 7 | +## Critical Build Rules |
| 8 | + |
| 9 | +**Always use `just build`**—never run `go build` directly. The justfile orchestrates: |
| 10 | +1. Building FFmpeg static library from source (`internal/builder/`) |
| 11 | +2. Regenerating Go bindings from headers (`internal/generator/`) |
| 12 | +3. Compiling Go code with correct CGO flags |
| 13 | + |
| 14 | +## Code Generation |
| 15 | + |
| 16 | +Files matching `*.gen.go` are **auto-generated**—never edit directly: |
| 17 | +- `constants.gen.go`, `enums.gen.go`, `structs.gen.go`, `functions.gen.go`, `callbacks.gen.go` |
| 18 | + |
| 19 | +To regenerate after header changes: `just generate` |
| 20 | + |
| 21 | +The generator (`internal/generator/`) parses FFmpeg headers in `include/` using libclang and outputs Go bindings. |
| 22 | + |
| 23 | +## Architecture |
| 24 | + |
| 25 | +| Component | Purpose | |
| 26 | +|-----------|---------| |
| 27 | +| `ffmpeg.go` | CGO directives, platform-specific linker flags, helper types (`CStr`, `AVError`) | |
| 28 | +| `*.gen.go` | Generated FFmpeg API bindings | |
| 29 | +| `include/` | FFmpeg C headers (libavcodec, libavformat, libavutil, etc.) | |
| 30 | +| `lib/<os>_<arch>/` | Platform-specific static libraries (gitignored) | |
| 31 | +| `internal/builder/` | Builds FFmpeg + 20 dependencies from source | |
| 32 | +| `internal/generator/` | Generates Go bindings from headers | |
| 33 | +| `cmd/download-lib/` | Downloads pre-built libraries from GitHub Releases | |
| 34 | +| `examples/` | Working examples: transcode, metadata, asciiplayer, introspect | |
| 35 | + |
| 36 | +## Internal Builder |
| 37 | + |
| 38 | +The builder (`internal/builder/`) compiles FFmpeg and dependencies from source. Key files: |
| 39 | + |
| 40 | +- `libraries.go` — Library definitions (URLs, versions, build configs) |
| 41 | +- `buildsystems.go` — Autoconf, CMake, Meson, Cargo build implementations |
| 42 | +- `main.go` — CLI entry point with `--clean` and `--list` flags |
| 43 | + |
| 44 | +Build commands: |
| 45 | +- `just build-static` — Build all libraries |
| 46 | +- `just build-static ffmpeg --clean` — Rebuild FFmpeg only |
| 47 | +- `go run ./internal/builder --list` — Show library versions |
| 48 | + |
| 49 | +## Hardware Acceleration |
| 50 | + |
| 51 | +Supports NVENC/NVDEC (Linux), QuickSync (Linux), VideoToolbox (macOS), and Vulkan Video. See `README.md` and `docs/CODECS.md` for codec and hardware details. |
| 52 | + |
| 53 | +## Library Distribution |
| 54 | + |
| 55 | +Static libraries distributed via GitHub Releases (`lib-8.0.0.x` tags), not git. Download with: |
| 56 | +``` |
| 57 | +go run ./cmd/download-lib |
| 58 | +``` |
| 59 | + |
| 60 | +## Platform Support |
| 61 | + |
| 62 | +Linux (amd64, arm64) and macOS (amd64, arm64). CGO required (`CGO_ENABLED=1`). |
| 63 | + |
| 64 | +Platform-specific code uses build tags in CGO directives—see `ffmpeg.go` lines 11-17. |
| 65 | + |
| 66 | +## Testing |
| 67 | + |
| 68 | +``` |
| 69 | +just test |
| 70 | +``` |
| 71 | + |
| 72 | +Tests require downloaded libraries. See `ffmpeg_test.go` for version validation pattern. |
| 73 | + |
| 74 | +## Key Patterns |
| 75 | + |
| 76 | +- All FFmpeg types prefixed with `AV*` (e.g., `AVCodecContext`, `AVFrame`) |
| 77 | +- Use `CStr` type for C string interop—call `.Free()` when done |
| 78 | +- Wrap FFmpeg return codes with `WrapErr()` to convert to Go errors |
| 79 | +- Check `AVErrorEOF` and `EAgain` for stream processing loops |
| 80 | + |
| 81 | +## Environment |
| 82 | +- NixOS development shell via `flake.nix` |
| 83 | +- Fish shell for terminal commands |
| 84 | +- CGO required (`CGO_ENABLED=1` in build) |
| 85 | + |
| 86 | +## Further Reading |
| 87 | + |
| 88 | +- `docs/DEVELOPMENT.md` — Consumer integration, project layout, troubleshooting |
| 89 | +- `docs/CODECS.md` — Enabled codecs, muxers, parsers |
| 90 | + |
| 91 | +## Reference Projects |
| 92 | + |
| 93 | +See [jivedrop](https://github.com/linuxmatters/jivedrop) and [jivefire](https://github.com/linuxmatters/jivefire) for consumer integration patterns with justfiles and GitHub workflows. |
0 commit comments