Documentation
¶
Overview ¶
Package kinrec records the macOS screen (and optionally system audio) into an H.264/HEVC .mp4 or .mov file.
Built on top of ScreenCaptureKit + AVAssetWriter via a small embedded ObjC dylib. Pure Go on the calling side (no cgo needed downstream).
Quick start:
ctx := context.Background()
r, _ := kinrec.NewRecorder(ctx,
kinrec.WithOutput("/tmp/demo.mp4"),
kinrec.WithAudio(true),
kinrec.WithFrameRate(60),
)
r.Start(ctx)
time.Sleep(10 * time.Second)
r.Stop(ctx)
For duration-bounded recordings use the blocking helper:
kinrec.Record(ctx, 10*time.Second,
kinrec.WithOutput("/tmp/demo.mp4"),
kinrec.WithAudio(true),
)
Requirements ¶
macOS 14 (Sonoma) or newer. First run triggers the "Screen Recording" TCC prompt (and "Microphone" if --mic is set in a future release).
Index ¶
- Constants
- Variables
- func Load() error
- func Record(ctx context.Context, duration time.Duration, opts ...Option) error
- func ResolvedDylibPath() string
- type Codec
- type Container
- type Display
- type Mic
- type Option
- func WithAudio(enabled bool) Option
- func WithCodec(codec Codec) Option
- func WithContainer(container Container) Option
- func WithCursorHighlight(enabled bool) Option
- func WithDisplay(id uint32) Option
- func WithFrameRate(fps int) Option
- func WithMic(enabled bool) Option
- func WithMicDevice(uniqueID string) Option
- func WithOutput(path string) Option
- func WithResolution(w, h int) Option
- type Recorder
- type Stats
Constants ¶
const Version = "0.1.0"
Version is the semver tag for this build. Updated per release.
Variables ¶
var DylibPath = ""
DylibPath optionally overrides the embedded dylib. Leave empty (default) to use the bundled copy auto-extracted to the user cache.
var ErrAlreadyStarted = errors.New("kinrec: recorder already started")
ErrAlreadyStarted is returned when Start is called twice.
var ErrNotStarted = errors.New("kinrec: recorder not started")
ErrNotStarted is returned when Stop is called before Start.
var ErrPermissionDenied = errors.New("kinrec: screen recording permission denied")
ErrPermissionDenied is returned when macOS Screen Recording (and, for future mic capture, Microphone) permission has not been granted.
Functions ¶
func Load ¶
func Load() error
Load explicitly loads the companion dylib. Idempotent; the first public call triggers it implicitly.
func Record ¶
Record captures for the given duration and finalizes the output file. Equivalent to NewRecorder + Start + time.Sleep + Stop; returns only when the file is fully on disk.
func ResolvedDylibPath ¶
func ResolvedDylibPath() string
ResolvedDylibPath returns the filesystem path Dlopen'd by the current process. Empty until the first Load call.
Types ¶
type Mic ¶
type Mic struct {
UniqueID string // pass to WithMicDevice to force selection
Name string // user-visible name, e.g. "MacBook Pro Microphone"
IsDefault bool
}
Mic describes an available audio input device.
type Option ¶
type Option func(*config)
Option configures a recorder. Options follow the functional-options pattern and compose in left-to-right order (later overrides earlier).
func WithAudio ¶
WithAudio toggles capture of system audio (application audio via SCStreamConfiguration.capturesAudio). Excludes the recording process's own output to prevent feedback loops.
Default: false.
In v0.1, WithAudio(true) and WithMic(true) are mutually exclusive. v0.2 will mix both into a single track.
func WithCodec ¶
WithCodec selects the video codec. Default: CodecH264.
HEVC files are roughly 30% smaller at equivalent quality but require modern decoders (macOS 10.13+, Windows with the HEVC extension, modern browsers). For distribution to unknown audiences, stick with H.264.
func WithContainer ¶
WithContainer selects the output file format. Default: ContainerMP4.
func WithCursorHighlight ¶
WithCursorHighlight overlays a subtle ring around the cursor and a yellow expanding "ripple" on every left-button click, making mouse activity unmistakable in screen recordings. Useful for tutorials and UI demos.
Currently supports Display-target capture at the display's native resolution. Window / App / Region targets and --resolution scaling will misalign the overlay until coordinate mapping is generalized in a future release.
Does NOT require Accessibility permission: uses NSEvent.mouseLocation and CGEventSourceButtonState.
Default: false.
func WithDisplay ¶
WithDisplay selects a specific display by CGDirectDisplayID. Zero (default) auto-picks the first attached display.
func WithFrameRate ¶
WithFrameRate caps the output frame rate. Default: 60.
func WithMic ¶
WithMic toggles capture of the default microphone (or the device selected by WithMicDevice). Triggers a macOS Microphone permission prompt on first use.
Default: false.
func WithMicDevice ¶
WithMicDevice selects a specific microphone by its AVCaptureDevice uniqueID. Use ListMics to enumerate. When unset, the system's default input device is used.
func WithOutput ¶
WithOutput sets the destination path. Required — recorders without WithOutput fail to construct.
The file extension determines nothing by itself; use WithContainer to choose .mp4 vs .mov. WithOutput simply sets the filename.
func WithResolution ¶
WithResolution forces the output frame size in pixels. Zero values keep the target's native resolution. Typical use: downsample a 4K display to 1080p to save bitrate.
type Recorder ¶
type Recorder struct {
// contains filtered or unexported fields
}
Recorder is a live macOS screen + audio capture session that writes to a file. Create via NewRecorder; call Start then Stop.
func NewRecorder ¶
NewRecorder creates a configured recorder. Capture starts only when Start is called. The output file is created (or truncated) at this point, not at Start.
func (*Recorder) Start ¶
Start begins capture. Blocks until the SCStream is delivering (typically ~150ms).
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
kinrec
command
kinrec — record your Mac screen (video + audio) to mp4 / mov, from the command line.
|
kinrec — record your Mac screen (video + audio) to mp4 / mov, from the command line. |
|
internal
|
|
|
dylib
Package dylib embeds the ObjC companion library so downstream users can `go install github.com/LocalKinAI/kinrec/cmd/kinrec` without building C code locally.
|
Package dylib embeds the ObjC companion library so downstream users can `go install github.com/LocalKinAI/kinrec/cmd/kinrec` without building C code locally. |