mirror of
https://github.com/go-gst/go-gst.git
synced 2025-10-17 21:41:13 +08:00
50e4c828554e8b31507e33f40d70f30476f7109b
go-gst
Go bindings for the GStreamer C libraries
See the godoc.org or pkg.go.dev references for documentation and examples. As the latter requires published tags, see godoc.org for the latest documentation of master at any point in time.
This library has not been thoroughly tested and as such is not recommended for mission critical applications yet. If you'd like to try it out and encounter any bugs, feel free to open an Issue or PR.
Requirements
For building applications with this library you need the following:
cgo
: You must setCGO_ENABLED=1
in your environment when building.gcc
andpkg-config
- GStreamer development files (the method for obtaining these will differ depending on your OS)
- The core
gst
package utilizes GStreamer core - Subpackages (e.g.
app
,video
) will require development files from their corresponding GStreamer packages- Look at
pkg_config.go
in the imported package to see which C libraries are needed.
- Look at
- The core
Quickstart
For more examples see the examples
folder here.
// This is the same as the `launch` example. See the godoc and other examples for more
// in-depth usage of the bindings.
package main
import (
"fmt"
"os"
"github.com/tinyzimmer/go-gst/gst"
)
func main() {
if len(os.Args) == 1 {
return errors.New("Pipeline string cannot be empty")
}
// Initialize GStreamer
gst.Init(nil)
// Create a main loop. This is only required when utilizing signals via the bindings.
// In this example, the AddWatch on the pipeline bus requires iterating on the main loop.
mainLoop := gst.NewMainLoop(gst.DefaultMainContext(), false)
defer mainLoop.Unref()
// Build a pipeline string from the cli arguments
pipelineString := strings.Join(os.Args[1:], " ")
/// Let GStreamer create a pipeline from the parsed launch syntax on the cli.
pipeline, err := gst.NewPipelineFromString(pipelineString)
if err != nil {
return err
}
// Add a message handler to the pipeline bus, printing interesting information to the console.
pipeline.GetPipelineBus().AddWatch(func(msg *gst.Message) bool {
switch msg.Type() {
case gst.MessageEOS: // When end-of-stream is received stop the main loop
mainLoop.Quit()
case gst.MessageError: // Error messages are always fatal
err := msg.ParseError()
fmt.Println("ERROR:", err.Error())
if debug := err.DebugString(); debug != "" {
fmt.Println("DEBUG:", debug)
}
mainLoop.Quit()
default:
// All messages implement a Stringer. However, this is
// typically an expensive thing to do and should be avoided.
fmt.Println(msg)
}
return true
})
// Start the pipeline
pipeline.SetState(gst.StatePlaying)
// Block and iterate on the main loop
mainLoop.Run()
// Destroy the pipeline
return pipeline.Destroy()
}
Languages
Go
98.2%
C
1.8%