screencap

package
v1.0.31-alpha.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 14 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package screencap captures the screen, for sharing it in a call or recording it: a stream of frames from a display.

srcs, _ := screencap.Sources(ctx)
c, err := screencap.Start(ctx, app, screencap.Options{Source: srcs[0].ID, FPS: 15},
	func(f screencap.Frame) { encoder.Encode(f.Image) })
...
c.Stop()

Where it runs: Windows (GDI), macOS (ScreenCaptureKit, macOS 12.3 and later; the user allows screen recording in System Settings), Linux on X11 (on Wayland, through Xwayland, only X11 windows show), Android (MediaProjection: the user confirms each time) and iOS (ReplayKit: the app's own screen). Elsewhere Start returns giode.ErrNotSupported.

Index

Constants

This section is empty.

Variables

View Source
var ErrPermissionDenied = errors.New("screencap: permission denied")

ErrPermissionDenied is returned when the user didn't allow screen capture.

Functions

This section is empty.

Types

type Capture

type Capture struct {
	// contains filtered or unexported fields
}

Capture is a running capture.

func Start

func Start(ctx context.Context, a *giode.App, opts Options, onFrame func(Frame)) (*Capture, error)

Start captures a display, calling onFrame with each frame on its own goroutine. Frames arriving while onFrame still runs are dropped, so a slow consumer never builds a backlog. On Android and macOS it asks the user first.

func (*Capture) Stop

func (c *Capture) Stop()

Stop ends the capture.

type Frame

type Frame struct {
	// Image is the frame. It's onFrame's to keep.
	Image *image.RGBA
	Time  time.Time
}

Frame is a captured frame.

type Options

type Options struct {
	// Source is the ID of the display to capture; the primary one when
	// empty.
	Source string
	// FPS is how many frames a second to capture: 10 by default.
	FPS int
	// MaxSize caps the frames' long side, scaling them down: 1920 by
	// default; -1 for full size.
	MaxSize int
}

Options configure Start.

type Source

type Source struct {
	ID   string
	Name string
	// Bounds are the display's place on the desktop, in pixels.
	Bounds image.Rectangle
	// Primary is the main display.
	Primary bool
}

Source is something to capture: a display.

func Sources

func Sources(ctx context.Context) ([]Source, error)

Sources lists the displays.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL