port examples to new packages and add more postprocessors to reach a similar convenience feature set

This commit is contained in:
RSWilli
2025-09-16 22:36:07 +02:00
parent dc0ec1c3ee
commit 0eb8b28ee2
18 changed files with 528 additions and 1011 deletions

View File

@@ -4,46 +4,89 @@
package main
import (
"errors"
"fmt"
"os"
"strings"
"time"
"github.com/go-gst/go-glib/glib"
"github.com/go-gst/go-gst/examples"
"github.com/go-gst/go-gst/gst"
"github.com/diamondburned/gotk4/pkg/glib/v2"
"github.com/go-gst/go-gst/pkg/gst"
)
func runPipeline(mainLoop *glib.MainLoop) error {
if len(os.Args) == 1 {
return errors.New("pipeline string cannot be empty")
}
func main() {
gst.Init()
gst.Init(&os.Args)
mainLoop := glib.NewMainLoop(glib.MainContextDefault(), false)
// Let GStreamer create a pipeline from the parsed launch syntax on the cli.
pipeline, err := gst.NewPipelineFromString(strings.Join(os.Args[1:], " "))
res, err := gst.ParseLaunch(strings.Join(os.Args[1:], " "))
if err != nil {
return err
fmt.Printf("Parse error: %v", err)
return
}
pipeline := res.(*gst.Pipeline)
// Add a message handler to the pipeline bus, printing interesting information to the console.
pipeline.GetPipelineBus().AddWatch(func(msg *gst.Message) bool {
pipeline.Bus().AddWatch(0, func(_ *gst.Bus, msg *gst.Message) bool {
switch msg.Type() {
case gst.MessageEOS: // When end-of-stream is received stop the main loop
pipeline.BlockSetState(gst.StateNull)
case gst.MessageEos: // When end-of-stream is received stop the main loop
pipeline.BlockSetState(gst.StateNull, gst.ClockTime(time.Second))
mainLoop.Quit()
case gst.MessageError: // Error messages are always fatal
err := msg.ParseError()
err, debug := msg.ParseError()
fmt.Println("ERROR:", err.Error())
if debug := err.DebugString(); debug != "" {
if debug != "" {
fmt.Println("DEBUG:", debug)
}
mainLoop.Quit()
case gst.MessageAny:
case gst.MessageApplication:
case gst.MessageAsyncDone:
case gst.MessageAsyncStart:
case gst.MessageBuffering:
case gst.MessageClockLost:
case gst.MessageClockProvide:
case gst.MessageDeviceAdded:
case gst.MessageDeviceChanged:
case gst.MessageDeviceRemoved:
case gst.MessageDurationChanged:
case gst.MessageElement:
case gst.MessageExtended:
case gst.MessageHaveContext:
case gst.MessageInfo:
case gst.MessageInstantRateRequest:
case gst.MessageLatency:
case gst.MessageNeedContext:
case gst.MessageNewClock:
case gst.MessageProgress:
case gst.MessagePropertyNotify:
case gst.MessageQos:
case gst.MessageRedirect:
case gst.MessageRequestState:
case gst.MessageResetTime:
case gst.MessageSegmentDone:
case gst.MessageSegmentStart:
case gst.MessageStateChanged:
old, state, pending := msg.ParseStateChanged()
fmt.Printf("State changed: %s => %s (%s)\n", old, state, pending)
case gst.MessageStateDirty:
case gst.MessageStepDone:
case gst.MessageStepStart:
case gst.MessageStreamCollection:
case gst.MessageStreamStart:
case gst.MessageStreamStatus:
case gst.MessageStreamsSelected:
case gst.MessageStructureChange:
case gst.MessageTag:
case gst.MessageToc:
case gst.MessageUnknown:
case gst.MessageWarning:
default:
// All messages implement a Stringer. However, this is
// typically an expensive thing to do and should be avoided.
fmt.Println(msg)
panic("unexpected gst.MessageType")
}
return true
})
@@ -52,11 +95,8 @@ func runPipeline(mainLoop *glib.MainLoop) error {
pipeline.SetState(gst.StatePlaying)
// Block on the main loop
return mainLoop.RunError()
}
func main() {
examples.RunLoop(func(loop *glib.MainLoop) error {
return runPipeline(loop)
})
mainLoop.Run()
return
}