Skip to content

Instantly share code, notes, and snippets.

@hissinger
Last active January 16, 2021 00:18
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hissinger/4560c444659d4771a44c46506df9ffff to your computer and use it in GitHub Desktop.
Save hissinger/4560c444659d4771a44c46506df9ffff to your computer and use it in GitHub Desktop.
package main
import (
"log"
"os"
gst "github.com/spreadspace/go-gstreamer"
"github.com/ziutek/glib"
)
func onMessage(bus *gst.Bus, message *gst.Message) {
if message.GetType() == gst.MESSAGE_EOS {
log.Println("End of stream")
os.Exit(0)
} else if message.GetType() == gst.MESSAGE_ERROR {
_, debug := message.ParseError()
log.Printf("ERROR: %s\n", debug)
} else if message.GetType() == gst.MESSAGE_WARNING {
_, debug := message.ParseWarning()
log.Printf("WARNING: %s\n", debug)
}
}
func main() {
gst.Init(nil)
pipeline, err := gst.PipelineNew("videotest-pipeline")
if err != nil {
log.Fatal(err)
}
source, err := gst.ElementFactoryMake("videotestsrc", "video-src")
if err != nil {
log.Fatal(err)
}
source.SetProperty("num-buffers", 50)
sink, err := gst.ElementFactoryMake("autovideosink", "video-sink")
if err != nil {
log.Fatal(err)
}
pipeline.Bin.Add(source)
pipeline.Bin.Add(sink)
source.Link(sink)
bus, err := pipeline.GetBus()
if err != nil {
log.Fatal(err)
}
bus.AddSignalWatch()
_, err = bus.Connect("message", onMessage, nil)
if err != nil {
log.Fatal(err)
}
var state = pipeline.SetState(gst.STATE_PLAYING)
log.Printf("StateChangeReturn: %d\n", state)
glib.NewMainLoop(nil).Run()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment