mpv

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 6 Imported by: 8

README

go-mpv

Build Status Go Reference

Go bindings for libmpv.

Build tags

  • nocgo - use purego implementation (can also be used with CGO_ENABLED=0)
  • pkgconfig - use pkg-config
  • static - use static library (used with pkgconfig)

License

The bindings in this repository are licensed under the MIT license.

They depend on libmpv, which is licensed under LGPLv2.1+ (or GPLv2+ when built with GPL-only components). A copy of the LGPL is included as LICENSE.LGPL; when you distribute a binary that links libmpv (statically or via dlopen), its terms apply to that library.

Documentation

Overview

Package mpv provides cgo bindings for libmpv.

Index

Constants

View Source
const (
	LCAll     = C.LC_ALL
	LCNumeric = C.LC_NUMERIC
)

Locale categories for SetLocale.

View Source
const (
	RenderAPITypeOpenGL = "opengl"
	RenderAPITypeSW     = "sw"
)

Render API type strings for MPV_RENDER_PARAM_API_TYPE.

View Source
const RenderUpdateFrame uint64 = 1 << 0

RenderUpdateFrame is set in the result of RenderContext.Update when a new video frame should be rendered.

Variables

View Source
var ErrAoInitFailed = errors.New("audio output initialization failed")
View Source
var ErrCommand = errors.New("error running command")
View Source
var ErrEventQueueFull = errors.New("event queue full")
View Source
var ErrGeneric = errors.New("something happened")
View Source
var ErrInvalidParameter = errors.New("invalid parameter")
View Source
var ErrLoadingFailed = errors.New("loading failed")
View Source
var ErrNomem = errors.New("memory allocation failed")
View Source
var ErrNotImplemented = errors.New("operation not implemented")
View Source
var ErrNothingToPlay = errors.New("no audio or video data played")
View Source
var ErrOptionError = errors.New("error setting option")
View Source
var ErrOptionFormat = errors.New("unsupported format for accessing option")
View Source
var ErrOptionNotFound = errors.New("option not found")
View Source
var ErrPropertyError = errors.New("error accessing property")
View Source
var ErrPropertyFormat = errors.New("unsupported format for accessing property")
View Source
var ErrPropertyNotFound = errors.New("property not found")
View Source
var ErrPropertyUnavailable = errors.New("property unavailable")
View Source
var ErrUninitialized = errors.New("core not uninitialized")
View Source
var ErrUnknown = errors.New("unknown error")
View Source
var ErrUnknownFormat = errors.New("unrecognized file format")
View Source
var ErrUnsupported = errors.New("not supported")
View Source
var ErrVoInitFailed = errors.New("video output initialization failed")

Functions

func SetLocale added in v0.3.1

func SetLocale(category int, locale string) string

SetLocale wraps C setlocale. libmpv needs LC_NUMERIC "C"; after a GUI toolkit changes the locale, call mpv.SetLocale(mpv.LCNumeric, "C").

Types

type Event

type Event struct {
	EventID       EventID
	Error         error
	ReplyUserdata uint64
	Data          unsafe.Pointer
}

Event represents an mpv_event struct.

func (*Event) ClientMessage added in v0.3.0

func (e *Event) ClientMessage() []string

ClientMessage returns the arguments of a client message event.

func (*Event) CommandReply added in v0.3.0

func (e *Event) CommandReply() any

CommandReply returns the result of an asynchronous command.

func (*Event) EndFile

func (e *Event) EndFile() EventEndFile

EndFile returns EventEndFile.

func (*Event) Hook added in v0.3.0

func (e *Event) Hook() Hook

Hook returns the hook event. Its ID must be passed to HookContinue.

func (*Event) LogMessage

func (e *Event) LogMessage() EventLogMessage

LogMessage returns EventLogMessage.

func (*Event) Property

func (e *Event) Property() EventProperty

Property returns EventProperty.

func (*Event) StartFile

func (e *Event) StartFile() EventStartFile

StartFile returns EventStartFile.

type EventEndFile

type EventEndFile struct {
	Reason           Reason
	Error            error
	EntryID          int64
	InsertID         int64
	InsertNumEntries int32
}

EventEndFile type.

type EventID

type EventID uint32

EventID type.

const (
	EventNone             EventID = 0
	EventShutdown         EventID = 1
	EventLogMsg           EventID = 2
	EventGetPropertyReply EventID = 3
	EventSetPropertyReply EventID = 4
	EventCommandReply     EventID = 5
	EventStart            EventID = 6
	EventEnd              EventID = 7
	EventFileLoaded       EventID = 8
	EventClientMessage    EventID = 16
	EventVideoReconfig    EventID = 17
	EventAudioReconfig    EventID = 18
	EventSeek             EventID = 20
	EventPlaybackRestart  EventID = 21
	EventPropertyChange   EventID = 22
	EventQueueOverflow    EventID = 24
	EventHook             EventID = 25
)

EventID constants.

func (EventID) String

func (e EventID) String() string

String .

type EventLogMessage

type EventLogMessage struct {
	Prefix   string
	Level    string
	Text     string
	LogLevel uint32
}

EventLogMessage type.

type EventProperty

type EventProperty struct {
	Name   string
	Format Format
	Data   any
}

EventProperty type.

type EventStartFile

type EventStartFile struct {
	EntryID int64
}

EventStartFile type.

type Format

type Format uint32

Format is data format for options and properties.

const (
	FormatNone Format = iota
	FormatString
	FormatOsdString
	FormatFlag
	FormatInt64
	FormatDouble
	FormatNode
	FormatNodeArray
	FormatNodeMap
	FormatByteArray
)

Data formats.

type Hook added in v0.3.0

type Hook struct {
	Name string
	ID   uint64
}

Hook is the payload of a hook event.

type Mpv

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

Mpv represents an mpv client.

func New added in v0.2.0

func New() *Mpv

New creates a new mpv instance and an associated client API handle.

func (*Mpv) APIVersion added in v0.2.0

func (m *Mpv) APIVersion() uint64

APIVersion returns the client api version the mpv source has been compiled with.

func (*Mpv) AbortAsyncCommand added in v0.3.0

func (m *Mpv) AbortAsyncCommand(replyUserdata uint64)

AbortAsyncCommand aborts an outstanding asynchronous command with the given reply userdata.

func (*Mpv) Command

func (m *Mpv) Command(cmd []string) error

Command runs the specified command, returning an error if something goes wrong.

func (*Mpv) CommandAsync

func (m *Mpv) CommandAsync(replyUserdata uint64, cmd []string) error

CommandAsync runs the command asynchronously.

func (*Mpv) CommandNode added in v0.3.0

func (m *Mpv) CommandNode(args interface{}) (interface{}, error)

CommandNode runs a command given as a []any or map[string]any and returns its result.

func (*Mpv) CommandNodeAsync added in v0.3.0

func (m *Mpv) CommandNodeAsync(replyUserdata uint64, args interface{}) error

CommandNodeAsync runs a structured command asynchronously.

func (*Mpv) CommandRet added in v0.3.0

func (m *Mpv) CommandRet(cmd []string) (interface{}, error)

CommandRet runs the specified command and returns its result.

func (*Mpv) CommandString

func (m *Mpv) CommandString(cmd string) error

CommandString runs the given command string, this string is parsed internally by mpv.

func (*Mpv) DelProperty added in v0.3.0

func (m *Mpv) DelProperty(name string) error

DelProperty deletes the given property.

func (*Mpv) Destroy added in v0.3.0

func (m *Mpv) Destroy()

Destroy disconnects and destroys this client handle without terminating mpv.

func (*Mpv) GetProperty

func (m *Mpv) GetProperty(name string, format Format) (interface{}, error)

GetProperty returns the value of the property according to the given format.

func (*Mpv) GetPropertyAsync

func (m *Mpv) GetPropertyAsync(name string, replyUserdata uint64, format Format) error

GetPropertyAsync gets a property asynchronously.

func (*Mpv) GetPropertyOsdString

func (m *Mpv) GetPropertyOsdString(name string) string

GetPropertyOsdString returns the value of the property as a string formatted for on-screen display.

func (*Mpv) GetPropertyString

func (m *Mpv) GetPropertyString(name string) string

GetPropertyString returns the value of the property as a string. If the property is empty, an empty string is returned.

func (*Mpv) HookAdd added in v0.3.0

func (m *Mpv) HookAdd(replyUserdata uint64, name string, priority int) error

HookAdd registers a hook handler for the named hook. Higher priority runs first.

func (*Mpv) HookContinue added in v0.3.0

func (m *Mpv) HookContinue(id uint64) error

HookContinue continues the hook with the given ID from a hook event.

func (*Mpv) ID

func (m *Mpv) ID() int64

ID returns the ID of this client handle.

func (*Mpv) Initialize

func (m *Mpv) Initialize() error

Initialize initializes an uninitialized mpv instance.

func (*Mpv) LoadConfigFile

func (m *Mpv) LoadConfigFile(fileName string) error

LoadConfigFile loads the given config file.

func (*Mpv) Name

func (m *Mpv) Name() string

Name returns the name of this client handle.

func (*Mpv) NewRenderContextGL added in v0.4.0

func (m *Mpv) NewRenderContextGL(getProcAddress func(name string) unsafe.Pointer) (*RenderContext, error)

NewRenderContextGL creates an OpenGL render context; getProcAddress resolves GL functions. Requires vo=libmpv and the GL context current on the calling thread.

func (*Mpv) NewRenderContextSW added in v0.4.0

func (m *Mpv) NewRenderContextSW() (*RenderContext, error)

NewRenderContextSW creates a software (CPU) render context. The mpv instance must have the "vo" option set to "libmpv".

func (*Mpv) ObserveProperty

func (m *Mpv) ObserveProperty(replyUserdata uint64, name string, format Format) error

ObserveProperty gets a notification whenever the given property changes.

func (*Mpv) RequestEvent

func (m *Mpv) RequestEvent(event EventID, enable bool) error

RequestEvent enables or disables the given event.

func (*Mpv) RequestLogMessages

func (m *Mpv) RequestLogMessages(level string) error

RequestLogMessages enables or disables receiving of log messages. Valid log levels: no fatal error warn info v debug trace.

func (*Mpv) SetOption

func (m *Mpv) SetOption(name string, format Format, data interface{}) error

SetOption sets the given option according to the given format.

func (*Mpv) SetOptionString

func (m *Mpv) SetOptionString(name, value string) error

SetOptionString sets the option to the given string.

func (*Mpv) SetProperty

func (m *Mpv) SetProperty(name string, format Format, data interface{}) error

SetProperty sets the client property according to the given format.

func (*Mpv) SetPropertyAsync

func (m *Mpv) SetPropertyAsync(name string, replyUserdata uint64, format Format, data interface{}) error

SetPropertyAsync sets a property asynchronously.

func (*Mpv) SetPropertyString

func (m *Mpv) SetPropertyString(name, value string) error

SetPropertyString sets the property to the given string.

func (*Mpv) TerminateDestroy

func (m *Mpv) TerminateDestroy()

TerminateDestroy terminates mpv and destroys the client.

func (*Mpv) TimeNS added in v0.3.0

func (m *Mpv) TimeNS() int64

TimeNS returns the internal time in nanoseconds.

func (*Mpv) TimeUS

func (m *Mpv) TimeUS() int64

TimeUS returns the internal time in microseconds.

func (*Mpv) UnobserveProperty

func (m *Mpv) UnobserveProperty(replyUserdata uint64) error

UnobserveProperty will remove all observed properties for passed replyUserdata.

func (*Mpv) WaitAsyncRequests

func (m *Mpv) WaitAsyncRequests()

WaitAsyncRequests blocks until all asynchronous requests are done.

func (*Mpv) WaitEvent

func (m *Mpv) WaitEvent(timeout float64) *Event

WaitEvent calls mpv_wait_event and returns the result as an Event struct.

func (*Mpv) Wakeup

func (m *Mpv) Wakeup()

Wakeup interrupts the current mpv_wait_event() call.

func (*Mpv) WakeupPipe added in v0.3.0

func (m *Mpv) WakeupPipe() int

WakeupPipe returns the read end of a pipe that signals new events, or -1 on error.

type Reason

type Reason uint32

Reason is end file reason.

const (
	EndFileEOF      Reason = 0
	EndFileStop     Reason = 2
	EndFileQuit     Reason = 3
	EndFileError    Reason = 4
	EndFileRedirect Reason = 5
)

End file reasons.

func (Reason) String

func (r Reason) String() string

String .

type RenderContext added in v0.4.0

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

RenderContext represents an mpv render context (the main video output).

func (*RenderContext) Free added in v0.4.0

func (rc *RenderContext) Free()

Free destroys the render context. Call it before the mpv core is destroyed.

func (*RenderContext) RenderGL added in v0.4.0

func (rc *RenderContext) RenderGL(fbo, width, height int, flipY bool) error

RenderGL renders the current frame into the given OpenGL framebuffer object (0 for the default framebuffer). Set flipY for bottom-up coordinate systems.

func (*RenderContext) RenderSW added in v0.4.0

func (rc *RenderContext) RenderSW(width, height, stride int, format string, buf []byte) error

RenderSW renders the current frame into buf, which must hold stride*height bytes. format is one of "rgb0", "bgr0", "0bgr", "0rgb".

func (*RenderContext) ReportSwap added in v0.4.0

func (rc *RenderContext) ReportSwap()

ReportSwap tells mpv that a frame swap (vsync) occurred.

func (*RenderContext) SetUpdateCallback added in v0.4.0

func (rc *RenderContext) SetUpdateCallback(fn func())

SetUpdateCallback sets fn to run when a new frame is ready. fn runs on an mpv thread and must only signal a redraw, not call mpv or render directly.

func (*RenderContext) Update added in v0.4.0

func (rc *RenderContext) Update() uint64

Update returns the render update flags; check the result against RenderUpdateFrame.

Jump to

Keyboard shortcuts

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