diff --git a/README.md b/README.md index 1c754d4..d103078 100644 --- a/README.md +++ b/README.md @@ -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? diff --git a/basics.md b/basics.md index 3a45e3f..e2ba51c 100644 --- a/basics.md +++ b/basics.md @@ -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/] diff --git a/mixing.md b/mixing.md index 57649b9..c14f11c 100644 --- a/mixing.md +++ b/mixing.md @@ -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 +``` diff --git a/network_transfer.md b/network_transfer.md index e119eda..fca6ab8 100644 --- a/network_transfer.md +++ b/network_transfer.md @@ -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: diff --git a/python_examples/headless.py b/python_examples/headless.py new file mode 100644 index 0000000..2cf8e33 --- /dev/null +++ b/python_examples/headless.py @@ -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() diff --git a/python_examples/playbin.py b/python_examples/playbin.py index bfeae66..de57c01 100644 --- a/python_examples/playbin.py +++ b/python_examples/playbin.py @@ -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() diff --git a/python_examples/show_test_stream.py b/python_examples/show_test_stream.py new file mode 100644 index 0000000..07b79c6 --- /dev/null +++ b/python_examples/show_test_stream.py @@ -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() diff --git a/rtmp.md b/rtmp.md index ef078ac..eca79ad 100644 --- a/rtmp.md +++ b/rtmp.md @@ -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. ``` - - - diff --git a/test_streams.md b/test_streams.md index 8857d72..d43d7a1 100644 --- a/test_streams.md +++ b/test_streams.md @@ -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: ```