Tidy up and first python examples

This commit is contained in:
Matthew Clark 2018-03-20 08:18:38 +00:00
parent 48a3a3530a
commit 7fb9d02b72
9 changed files with 117 additions and 13 deletions

View file

@ -39,7 +39,12 @@ Good GStreamer Python resources include:
* [Getting started with GStreamer with Python](https://www.jonobacon.com/2006/08/28/getting-started-with-gstreamer-with-python/)
* [Python GStreamer Tutorial](http://brettviren.github.io/pygst-tutorial-org/pygst-tutorial.html)
* [Function reference](http://lazka.github.io/pgi-docs/#GstApp-1.0)
* [Function reference](http://lazka.github.io/pgi-docs/#Gst-1.0)
* [Nice example script](https://github.com/rabits/rstream/blob/master/rstream.py)
### C++ with GStreamer
My favourite reference is [Valadoc](https://valadoc.org/gstreamer-1.0/index.htm)
# Problems or suggestions with this guide?

View file

@ -109,3 +109,6 @@ gst-launch-1.0 filesrc location=$SRC ! \
autovideosink
```
### Play files back to back
See (https://coaxion.net/blog/2014/08/concatenate-multiple-streams-gaplessly-with-gstreamer/)[https://coaxion.net/blog/2014/08/concatenate-multiple-streams-gaplessly-with-gstreamer/]

View file

@ -70,5 +70,17 @@ gst-launch-1.0 \
mix.
```
### Compositor with just one sources
It is possible for a compositor to have just one source. This example has the test source of a bouncing ball. It also has the audio test source included (muxed).
```
gst-launch-1.0 \
videotestsrc pattern=ball ! \
decodebin ! \
compositor name=mix sink_0::alpha=1 ! \
x264enc ! muxer. \
audiotestsrc ! avenc_ac3 ! muxer. \
mpegtsmux name=muxer ! queue ! \
tcpserversink host=127.0.0.1 port=7001 recover-policy=keyframe sync-method=latest-keyframe sync=false
```

View file

@ -92,15 +92,18 @@ To send a test stream:
```
gst-launch-1.0 \
audiotestsrc ! \
avenc_ac3 ! mpegtsmux ! tcpserversink port=7001 host=0.0.0.0
avenc_ac3 ! mpegtsmux ! \
tcpserversink port=7001 host=0.0.0.0
```
To send a file:
```
# Make sure $SRC is set to an audio file (e.g. an MP3 file)
gst-launch-1.0 -v filesrc location=$AUDIO_SRC ! \
mpegaudioparse ! tcpserversink port=7001 host=0.0.0.0
gst-launch-1.0 \
filesrc location=$AUDIO_SRC ! \
mpegaudioparse ! \
tcpserversink port=7001 host=0.0.0.0
```
And to receive:

View file

@ -0,0 +1,30 @@
#!/usr/bin/env python
#
# Sends a test stream to a fake sink.
# This is utterly pointless, but allows easy testing of GStreamer
# Python on a remote box that doesn't have video.
#
# Equivalent to:
# gst-launch-1.0 videotestsrc ! fakesink
#
import gi
gi.require_version('Gst', '1.0')
from gi.repository import GObject, Gst
import os
Gst.init()
mainloop = GObject.MainLoop()
pipeline = Gst.Pipeline.new("pipe")
videotestsrc = Gst.ElementFactory.make("videotestsrc", "videotestsrc")
fakesink = Gst.ElementFactory.make("fakesink", "fakesink")
pipeline.add(videotestsrc)
pipeline.add(fakesink)
videotestsrc.link(fakesink)
pipeline.set_state(Gst.State.PLAYING)
mainloop.run()

View file

@ -1,5 +1,7 @@
#!/usr/bin/env python
#
# Plays a file to screen.
#
# Make sure the environment variable SRC is set to a playable file
# e.g.
# export SRC='/tmp/me.mp4'
@ -13,9 +15,8 @@ import os
Gst.init()
mainloop = GObject.MainLoop()
pl = Gst.ElementFactory.make("playbin", "player")
pl.set_property('uri','file://'+os.environ['SRC'])
pipeline = Gst.ElementFactory.make("playbin", "player")
pipeline.set_property('uri','file://'+os.environ['SRC'])
#running the playbin
pl.set_state(Gst.State.PLAYING)
pipeline.set_state(Gst.State.PLAYING)
mainloop.run()

View file

@ -0,0 +1,31 @@
#!/usr/bin/env python
#
# Plays a test screen to screen.
#
# Equivalent to:
# gst-launch-1.0 videotestsrc ! videoconvert ! autovideosink
#
import gi
gi.require_version('Gst', '1.0')
from gi.repository import GObject, Gst
import os
Gst.init()
mainloop = GObject.MainLoop()
pipeline = Gst.Pipeline.new("pipe")
videotestsrc = Gst.ElementFactory.make("videotestsrc", "videotestsrc")
videoconvert = Gst.ElementFactory.make("videoconvert", "videoconvert")
autovideosink = Gst.ElementFactory.make("autovideosink", "autovideosink")
pipeline.add(videotestsrc)
pipeline.add(videoconvert)
pipeline.add(autovideosink)
videotestsrc.link(videoconvert)
videoconvert.link(autovideosink)
pipeline.set_state(Gst.State.PLAYING)
mainloop.run()

16
rtmp.md
View file

@ -136,6 +136,8 @@ gst-launch-1.0 videotestsrc is-live=true ! \
### Send a file over RTMP
Audio & video:
```
gst-launch-1.0 filesrc location=$SRC ! \
qtdemux name=demux \
@ -148,6 +150,17 @@ gst-launch-1.0 filesrc location=$SRC ! \
voaacenc bitrate=96000 ! audio/mpeg ! aacparse ! audio/mpeg, mpegversion=4 ! mux.
```
Just video:
```
gst-launch-1.0 filesrc location=$SRC ! \
qtdemux name=demux \
demux.video_0 ! queue ! \
decodebin ! videoconvert ! x264enc bitrate=1000 tune=zerolatency ! video/x-h264 ! h264parse ! \
video/x-h264 ! queue ! flvmux name=mux ! \
rtmpsink location=$RTMP_DEST
```
---
Can we work out why a bad RTMP brings down the other mix?
@ -168,6 +181,3 @@ gst-launch-1.0 \
videoscale ! video/x-raw,width=320,height=180! \
mix.
```

View file

@ -6,12 +6,12 @@
gst-launch-1.0 videotestsrc ! videoconvert ! autovideosink
```
This should display the test pattern in a window, that looks a
This should display the test pattern in a window, that looks a
bit like this:
![Test pattern window](images/test-pattern.png "Test pattern window")
There are multiple test patterns available, such as
There are multiple test patterns available, such as:
| Pattern | Example |
| ------------- |:-------------:|
@ -23,6 +23,13 @@ There are multiple test patterns available, such as
For the full list of patterns, see https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-base-plugins/html/gst-plugins-base-plugins-videotestsrc.html
### Change the shape of a test pattern
To change the width and/or height, pass width and height immediately afterwards, e.g.
```
gst-launch-1.0 -v videotestsrc pattern=snow ! video/x-raw,width=1280,height=720 ! autovideosink
```
### Listen to a test audio (beep)
@ -30,6 +37,8 @@ For the full list of patterns, see https://gstreamer.freedesktop.org/data/doc/gs
gst-launch-1.0 audiotestsrc ! audioconvert ! autoaudiosink
```
### View test pattern and hear test audio
Combine both the test pattern and test audio:
```