Avi Zimmerman 50e4c82855 readme fixes
2021-01-03 16:00:41 +02:00
2020-10-07 12:07:00 +03:00
2020-10-05 08:22:58 +03:00
2020-10-04 15:58:46 +03:00
2020-10-04 15:58:46 +03:00
2020-09-24 21:25:44 +03:00
2021-01-03 16:00:41 +02:00

go-gst

Go bindings for the GStreamer C libraries

go.dev reference godoc reference GoReportCard

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 set CGO_ENABLED=1 in your environment when building.
  • gcc and pkg-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.

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()
}
Description
Gstreamer bindings and utilities for golang
Readme LGPL-2.1 36 MiB
Languages
Go 98.2%
C 1.8%