tinyzimmer / go-gst

Gstreamer bindings and utilities for golang
GNU Lesser General Public License v2.1
130 stars 37 forks source link

Try to control volume #54

Closed PuHsiu closed 1 year ago

PuHsiu commented 1 year ago

Hi all, I'm new on gst, and I wanna to control the volume of voice stream when playing, I know there's some function like gst_stream_volume_set_volume in C Library, but have no idea how to work with go-gst, can any one give me some help?

I start the pipeline by following code to transfer mp3 to g.711, send result over udp/rtp:

cmd := []string{
  "filesrc location=" + mediaPath,
  "decodebin",
  "audioconvert",
  "volume volume=0.1",
  "audioresample",
  "clocksync",
  "mulawenc",
  "rtppcmupay",
  "udpsink host=" + ip,
}

pipeline, err := gst.NewPipelineFromString(strings.Join(cmd, " ! "))
if err != nil {
  log.Errorf("failed to generate pipeline, err: %s", err)
  return err
}

if err := pipeline.SetState(gst.StatePlaying); err != nil {
  return err
}

// Do something to control the volume of pipeline
brucekim commented 1 year ago

Try to set a property of the volume element. In your code, first you need to get a reference of the volume element in the pipeline. Then, you can adjust the value of the property, volume.

Following would help you regarding how to use SetProperty in go-gst. https://github.com/tinyzimmer/go-gst/blob/d24532796427d84ab76dcdd45f6ff1d2fe402683/examples/requestpad/main.go#L97

gst volume

volume 
“volume” [gdouble](https://developer.gnome.org/glib/unstable/glib-Basic-Types.html#gdouble)
volume factor, 1.0=100%%

Flags : Read / Write

Default value : 1