Git Product home page Git Product logo

gst's Introduction

gst

a small go gstreamer binding

Install

Ubuntu or Dedian

apt-get install pkg-config
apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgstreamer-plugins-good1.0-dev libgstreamer-plugins-bad1.0-dev gstreamer1.0-plugins-ugly gstreamer1.0-libav


// set GST_PLUGIN_PATH on linux, may diff on your system
export GST_PLUGIN_PATH=/usr/local/lib:/usr/lib/x86_64-linux-gnu/gstreamer-1.0

Mac os

brew install gstreamer
brew install gst-plugins-base
brew install gst-plugins-good
brew install gst-plugins-bad
brew install gst-plugins-ugly


// set GST_PLUGIN_PATH on mac 
export GST_PLUGIN_PATH=/opt/homebrew/lib/gstreamer-1.0/

Then

go get github.com/notedit/gst

Examples

https://github.com/notedit/gst-go-demo

gst's People

Contributors

basheuft avatar castaneai avatar danjenkins avatar hoffie avatar jwmwalrus avatar nlowe avatar notedit avatar tzim avatar vahid-sohrabloo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

gst's Issues

undefined reference to `g_memdup2' and cannot use _Ctype_long(duration.Nanoseconds()) (type _Ctype_long) as type _Ctype_longlong in assignmen

path\pkg\mod\github.com\notedit\[email protected]/gst.c:248: undefined reference to `g_memdup2'
collect2.exe: error: ld returned 1 exit status
# github.com/notedit/gst
gst.c: In function 'X_gst_app_src_push_buffer':
gst.c:248:16: warning: implicit declaration of function 'g_memdup2'; did you mean 'g_memdup'? [-Wimplicit-function-declaration]
248 | gpointer p = g_memdup2(buffer, len);
| ^~~~~~~~~
| g_memdup
==========================================================================
github.com\notedit\gst\element_other.go:13:96: cannot use _Ctype_long(duration.Nanoseconds()) (type _Ctype_long) as type _Ctype_longlong in assignmen

怎么设置 appsrc 属性 format=time

您好,我是这样写的,但是不行,麻烦您帮忙看一下

appsrc, _ := gst.ElementFactoryMake("appsrc", "src")
appsrc.SetObject("format", gst.FormatTime)

appsrc plugin not found

After finally getting things compiling.... It won't find appsrc etc...

0:00:03.567196000 60583    0x15460be40 WARN     GST_ELEMENT_FACTORY gstelementfactory.c:701:gst_element_factory_make_with_properties: no such element factory "appsrc"!
0:00:03.567229000 60583    0x15460be40 ERROR           GST_PIPELINE gst/parse/grammar.y:851:priv_gst_parse_yyparse: no element "appsrc"
0:00:03.567245000 60583    0x15460be40 WARN     GST_ELEMENT_FACTORY gstelementfactory.c:701:gst_element_factory_make_with_properties: no such element factory "videoconvert"!
0:00:03.567248000 60583    0x15460be40 ERROR           GST_PIPELINE gst/parse/grammar.y:851:priv_gst_parse_yyparse: no element "videoconvert"
0:00:03.567253000 60583    0x15460be40 ERROR           GST_PIPELINE gst/parse/grammar.y:939:priv_gst_parse_yyparse: link has no source [sink=@0x0]
0:00:03.567256000 60583    0x15460be40 WARN     GST_ELEMENT_FACTORY gstelementfactory.c:701:gst_element_factory_make_with_properties: no such element factory "autovideosink"!
0:00:03.567317000 60583    0x15460be40 ERROR           GST_PIPELINE gst/parse/grammar.y:851:priv_gst_parse_yyparse: no element "autovideosink"
0:00:03.567322000 60583    0x15460be40 ERROR           GST_PIPELINE gst/parse/grammar.y:939:priv_gst_parse_yyparse: link has no source [sink=@0x0]
2022/05/24 18:56:44 error was: create pipeline error
panic: pipeline error

But gstreamer can see it normally....

❯ gst-inspect-1.0 --print-plugin-auto-install-info /opt/homebrew/lib/gstreamer-1.0/libgstapp.dylib
element-appsrc
urisource-appsrc
element-appsink
urisink-appsink

❯ pkg-config --cflags gstreamer-plugins-base-1.0
-I/opt/homebrew/Cellar/libffi/3.4.2/include -I/opt/homebrew/Cellar/gst-plugins-base/1.20.2/include/gstreamer-1.0 -I/opt/homebrew/Cellar/gstreamer/1.20.2/include/gstreamer-1.0 -I/opt/homebrew/Cellar/glib/2.72.1/include -I/opt/homebrew/Cellar/glib/2.72.1/include/glib-2.0 -I/opt/homebrew/Cellar/glib/2.72.1/lib/glib-2.0/include -I/opt/homebrew/opt/gettext/include -I/opt/homebrew/Cellar/pcre/8.45/include

I'm not really sure what's up.... any ideas?

How to build properly on Windows?

Hello,

What is the correct procedure to get one of the examples working on Windows?

I probably missed something silly, but I tried downloading and installing https://gstreamer.freedesktop.org/data/pkg/windows/1.18.2/mingw/gstreamer-1.0-devel-mingw-x86_64-1.18.2.msi then I tried to go build one of the examples:

package main

import (
	"fmt"
	"log"
	"time"

	"github.com/notedit/gst"
)

func main() {
	log.Printf("HELLO")

	pipeline, err := gst.ParseLaunch("appsrc name=mysource format=time is-live=true do-timestamp=true ! videoconvert ! autovideosink")

	if err != nil {
		panic("pipeline error")
	}
	log.Printf("pipe: %v", pipeline)
	videoCap := gst.CapsFromString("video/x-raw,format=RGB,width=320,height=240,bpp=24,depth=24")

	element := pipeline.GetByName("mysource")

	element.SetObject("caps", videoCap)

	pipeline.SetState(gst.StatePlaying)

	i := 0
	for {

		if i > 100 {
			break
		}

		data := make([]byte, 320*240*3)

		err := element.PushBuffer(data)

		if err != nil {
			fmt.Println("push buffer error")
			break
		}

		fmt.Println("push one")
		i++
		time.Sleep(50000000)
	}

	pipeline.SetState(gst.StateNull)

	pipeline = nil
	element = nil
	videoCap = nil
}

After an error about PKG_CONFIG_PATH not set properly, I notice there is a folder with a bunch of .pc files, including C:\gstreamer\1.0\mingw_x86_64\lib\pkgconfig\gstreamer-1.0.pc

So I set my PKG_CONFIG_PATH env var to C:/gstreamer/1.0/mingw_x86_64/lib/pkgconfig and finally go build silently builds an .exe, yet when I run it nothing happens. No error, no console output, it just quits immediately.

Any ideas?

My gstreamer-1.0.pc looks like this:

prefix=C:/gstreamer/1.0/mingw_x86_64
exec_prefix=${prefix}
libexecdir=${prefix}/libexec
libdir=${prefix}/lib
includedir=${prefix}/include/gstreamer-1.0
toolsdir=${exec_prefix}/bin
pluginsdir=${prefix}/lib/gstreamer-1.0
datarootdir=${prefix}/share
datadir=${datarootdir}
girdir=${datadir}/gir-1.0
typelibdir=${libdir}/girepository-1.0
pluginscannerdir=${libexecdir}/gstreamer-1.0

Name: GStreamer
Description: Streaming media framework
Version: 1.18.2
Requires: glib-2.0, gobject-2.0
Requires.private: gmodule-no-export-2.0  
Libs: -L${libdir} -lgstreamer-1.0
Cflags: -I${includedir}

appsrc loses data when sending EOS without waiting

First, thanks a lot for this project, highly appreciated!

I'm building a pipeline which uses an appsrc, is fed raw PCM data and encodes to webm/opus. The result is read back using an appsink.

gst.ParseLaunch("appsrc name=appsrc format=time is-live=true do-timestamp=true block=true max-bytes=128000 ! audio/x-raw,format=S16LE,channels=1,rate=48000,layout=interleaved ! audioconvert ! audioresample ! opusenc bitrate=128000 bitrate-type=vbr ! webmmux ! appsink name=appsink")

As per the GST docs, one should call gst_app_src_end_of_stream() once one is done feeding data:

https://gstreamer.freedesktop.org/documentation/application-development/advanced/pipeline-manipulation.html?gi-language=c

When the last byte is pushed into appsrc, you must call gst_app_src_end_of_stream () to make it send an EOS downstream.

When not sending EOS, the pipeline will hang as appsink.PullSample will block forever.

Something similar has been discussed in issue #11 and the related PR #12 added the required code to make it possible to send an EOS event from Go's gst. The issue cited the code which says that either the above mentioned function or a normal EOS signal could be used.

I tried using the newly possible code (appsrc.SendEvent(gst.NewEosEvent())) and the pipeline would no longer hang. However, it would randomly lose the last samples. As I am working with rather short fragments (~200ms chunks of raw PCM), I'm sometimes losing all the samples except for some 150 bytes of header information. This seems to depend on timing. When adding a short sleep (10ms were sufficient in my tests) between the .PushBuffer() call and the .SendEvent(gst.NewEosEvent()) call, the problem vanished. However, this feels wrong and as I am working on something timing-critical, I want to avoid that sleep call.

After lots of research, I have found that others struggled with such problems as well when using a signal instead of the documented function call:
http://gstreamer-devel.966125.n4.nabble.com/How-to-handle-EOS-from-an-appsrc-to-ensure-all-frames-are-played-out-before-pipeline-closes-td4671225.html#a4671257

Therefore, I assume that the function call and the signal do not behave exactly the same. I suspect that the signal may either propagate through the pipeline immediately after being sent without the pipeline having actually finished all processing. I'm not familiar enough with C or GST to find the actual spot which would explain the difference.

However, a quick test shows that using the function call works. I am no longer losing any samples even when running without the sleep call.

I therefore propose exposing the required function gst_app_src_end_of_stream() to Go. I will submit a PR in a minute.

issue on mac m1 arm

❯ go run .
# github.com/notedit/gst
../../go/pkg/mod/github.com/notedit/[email protected]/bus.go:33:42: cannot use _Ciconst_GST_CLOCK_TIME_NONE (untyped int constant -1) as _Ctype_ulonglong value in variable declaration (overflows)
../../go/pkg/mod/github.com/notedit/[email protected]/element_other.go:13:96: cannot use _Ctype_long(duration.Nanoseconds()) (value of type _Ctype_long) as type _Ctype_longlong in variable declaration

Based on another comment in another ticket it looks like this is an arm issue....

How to send Events (e.g. End-Of-Stream) down the Pipeline?

In python it would be something like:

pipeline.send_event(Gst.Event.new_eos())

i am trying to use it from an appsrc and found this
https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/blob/1.16.2/gst-libs/gst/app/gstappsrc.c

 * When the application has finished pushing data into appsrc, it should call
 * gst_app_src_end_of_stream() or emit the end-of-stream action signal. After
 * this call, no more buffers can be pushed into appsrc until a flushing seek
 * occurs or the state of the appsrc has gone through READY.

@notedit any help is highly appreciated

Additional Callbacks

I was going to give this library a try and implement this in Go:
http://blog.nirbheek.in/2018/02/gstreamer-webrtc.html

But quickly ran into the limited callback functions and private callbackID on Element. I'm experimenting with adding things like SetOnNegotiationNeededCallback and SetOnICECandidateCallback, or something a little more general allowing arbitrary callbacks, but I thought I'd register this issue to see if adding something like this upstream would be possible.

How to add caps?

I couldnt find any examples of adding caps.

I wish to do something like this

gst-launch-1.0 appsrc name=src ! application/x-rtp, payload=96, encoding-name=OPUS ! rtpopusdepay ! decodebin ! appsink name=sink

How do I add application/x-rtp, payload=96, encoding-name=OPUS to dynamic pipelines?

GST Element linking failed

I have been trying to mix audio and vide using compositor and audio mixer. Here is the situation.
I have pointer for gst elements [appsrc, rtph264depay, avdec_h264, videoconvert]. I have added them to the pipeline. When i try to link them (in order) src.Link(dest) throws me the error gst_element_link_pads_full: assertion 'GST_IS_ELEMENT (dest)' failed. I checked the source type its gst.Element. The errors are follow:
(__debug_bin2560998154:2129271): GStreamer-CRITICAL **: 12:23:28.168: gst_element_set_state: assertion 'GST_IS_ELEMENT (element)' failed

(__debug_bin2560998154:2129271): GStreamer-CRITICAL **: 12:23:46.738: gst_element_link_pads_full: assertion 'GST_IS_ELEMENT (dest)' failed

2023/09/12 12:23:46 Linking: [rtph264depay] => [avdec_h264]

(__debug_bin2560998154:2129271): GStreamer-CRITICAL **: 12:23:46.738: gst_element_link_pads_full: assertion 'GST_IS_ELEMENT (src)' failed

(__debug_bin2560998154:2129271): GStreamer-CRITICAL **: 12:23:46.738: gst_element_link_pads_full: assertion 'GST_IS_ELEMENT (src)' failed

(__debug_bin2560998154:2129271): GStreamer-CRITICAL **: 12:23:46.738: gst_element_request_pad: assertion 'templ != NULL' failed'

(__debug_bin2560998154:2129271): GStreamer-CRITICAL **: 12:23:46.739: gst_pad_link_full: assertion 'GST_IS_PAD (sinkpad)' failed

Anything would help.

Gstreamer compatibility

Noticed today that a number of SeekFlags in element.go (introduced by: 06dccea) are not compatible with older versions of Gstreamer (<1.18).

We need to decide which versions we are going to support.

For example, i needed to comment lines 59:62 in element.go to get it working on Gstreamer 1.14.

What do you guys think?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.