Updates to memory transfer, RTMP, and images

This commit is contained in:
Matthew Clark 2018-03-05 20:22:50 +00:00
parent e913be46ef
commit d06c015d36
7 changed files with 226 additions and 5 deletions

View file

@ -1,6 +1,6 @@
# GStreamer command-line cheat sheet
This series of docs provides a cheat sheet for Gstreamer on the command-line.
This series of docs provides a cheat sheet for GStreamer on the command-line.
## Contents
@ -8,8 +8,10 @@ This series of docs provides a cheat sheet for Gstreamer on the command-line.
* [Basics](basics.md)
* [RTMP](rtmp.md)
* [Mixing video](mixing.md)
* [Images](images.md)
* [Capturing images](capturing_images.md)
* [Sending/receiving video from shared memory](memory_transfer.md)
* [Network transfer](network_transfer.md) (including how to send so that VLC can preview)
## Sources and references
@ -18,10 +20,11 @@ This series of docs provides a cheat sheet for Gstreamer on the command-line.
* [List of all Gstreamer plugins](https://gstreamer.freedesktop.org/documentation/plugins.html)
* [Handy elements](https://gstreamer.freedesktop.org/documentation/tutorials/basic/handy-elements.html#uridecodebin)
## Other cheat sheets
## Other cheat-sheets
* http://wiki.oz9aec.net/index.php/Gstreamer_cheat_sheet
* https://github.com/xmementoit/gstreamerCheatsheet/blob/master/README.md
* https://gist.github.com/nebgnahz/26a60cd28f671a8b7f522e80e75a9aa5
## Interaction
@ -34,10 +37,10 @@ If you want to interact with GStreamer after it's started (e.g. respond to an ev
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)
# Problems or suggestions with this guide?
If you spot anything incorrect or incomplete, reports are welcome, either using [issues](issues) or [pull requests](pulls)

31
images.md Normal file
View file

@ -0,0 +1,31 @@
# Images (GStreamer command-line cheat sheet)
Gstreamer can show images on video using the `imagefreeze` element.
### Create a video from an image
![Example imagefreeze single image](images/imagefreeze_single.png "Example imagefreeze single image")
```
export PIC="https://upload.wikimedia.org/wikipedia/en/thumb/8/80/Wikipedia-logo-v2.svg/263px-Wikipedia-logo-v2.svg.png"
gst-launch-1.0 \
uridecodebin uri=$PIC ! \
imagefreeze ! \
autovideosink
```
### Create a video from multiple images
Here's the same image four times, done with the help of `compsitor` (a mixer):
```
gst-launch-1.0 \
compositor name=m sink_1::xpos=263 sink_2::ypos=240 sink_3::xpos=263 sink_3::ypos=240 ! autovideosink \
uridecodebin uri=$PIC ! videoscale ! video/x-raw, width=263, height=240 ! imagefreeze ! m. \
uridecodebin uri=$PIC ! videoscale ! video/x-raw, width=263, height=240 ! imagefreeze ! m. \
uridecodebin uri=$PIC ! videoscale ! video/x-raw, width=263, height=240 ! imagefreeze ! m. \
uridecodebin uri=$PIC ! videoscale ! video/x-raw, width=263, height=240 ! imagefreeze ! m.
```

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

View file

@ -2,7 +2,7 @@
The [`shmsink`](https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-bad/html/gst-plugins-bad-plugins-shmsink.html) element allows you to write video into shared memory, from which another gstreamer application can read it with [`shmsrc`](https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-bad/html/gst-plugins-bad-plugins-shmsrc.html).
### Puttingn a stream into memory
### Putting a stream into memory
```
gst-launch-1.0 -v videotestsrc ! \

163
network_transfer.md Normal file
View file

@ -0,0 +1,163 @@
# Transfer of audio/video via a network socket (GStreamer command-line cheat sheet)
GStreamer can send and receive audio and video via a network socket, using either UDP or TCP.
*UDP* is faster but lossy - there is no attempt to resend lost network packets to it will fail if the network is not perfect. *TCP* acknowledges every network packet so is slower, but more reliable.
## UDP
### Audio via UDP
To send an audio test source:
```
gst-launch-1.0 audiotestsrc ! avenc_ac3 ! mpegtsmux ! rtpmp2tpay ! udpsink host=127.0.0.1 port=7001
```
To send an audio 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 ! udpsink port=7001
```
And to receive audio:
```
gst-launch-1.0 udpsrc port=7001 ! decodebin ! autoaudiosink
```
### Video via UDP, as h264
To send a test stream:
```
gst-launch-1.0 videotestsrc ! decodebin ! x264enc ! rtph264pay ! udpsink port=7001
```
Or to send a file (video or audio only, not both):
```
# Make sure $SRC is set to an video file (e.g. an MP4 file)
gst-launch-1.0 filesrc location=$SRC ! decodebin ! x264enc ! rtph264pay ! udpsink port=7001
```
To receive:
```
gst-launch-1.0 \
udpsrc port=7001 caps = "application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, payload=(int)96" ! \
rtph264depay ! decodebin ! videoconvert ! autovideosink
```
### Video via UDP, as MPEG-2
To send a video test source:
```
gst-launch-1.0 videotestsrc ! x264enc ! mpegtsmux ! rtpmp2tpay ! udpsink host=127.0.0.1 port=7001
```
To receive:
```
gst-launch-1.0 udpsrc port=7001 ! decodebin ! autovideosink
```
### Both video and audio
To send both a video and audio test source (mixed together):
```
gst-launch-1.0 \
videotestsrc ! x264enc ! muxer. audiotestsrc ! avenc_ac3 ! \
muxer. mpegtsmux name=muxer ! rtpmp2tpay ! udpsink host=127.0.0.1 port=7001
```
And to receive both video and audio together:
```
gst-launch-1.0 \
udpsrc port=7001 caps="application/x-rtp" ! \
rtpmp2tdepay ! decodebin name=decoder ! autoaudiosink decoder. ! autovideosink
```
## TCP
### Send and receive audio via TCP
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
```
And to receive:
```
gst-launch-1.0 tcpclientsrc port=7001 host=0.0.0.0 ! decodebin ! autoaudiosink
```
### Send and receive video via TCP
Test video stream:
```
gst-launch-1.0 videotestsrc ! \
decodebin ! x264enc ! mpegtsmux ! queue ! \
tcpserversink port=7001 host=127.0.0.1 recover-policy=keyframe sync-method=latest-keyframe sync=false
```
MP4 file (video only):
```
gst-launch-1.0 \
filesrc location=$SRC ! decodebin ! x264enc ! mpegtsmux ! queue ! \
tcpserversink host=127.0.0.1 port=7001 recover-policy=keyframe sync-method=latest-keyframe sync=false
```
To receive, either use VLC (`tcp://localhost:7001`) or this command:
```
gst-launch-1.0 \
tcpclientsrc host=127.0.0.1 port=7001 ! \
decodebin ! videoconvert ! autovideosink sync=false
```
### Stream and receive video via TCP, using Matroska
Should you wish to use the Matroska container rather than MPEG, here are some examples.
(The [Matroska FAQ](https://www.matroska.org/technical/guides/faq/index.html) nicely describes what it is, if you're interested.)
To send a test stream:
```
gst-launch-1.0 \
videotestsrc is-live=true ! \
queue ! videoconvert ! x264enc byte-stream=true ! \
h264parse config-interval=1 ! queue ! matroskamux ! queue leaky=2 ! \
tcpserversink port=7001 host=0.0.0.0 recover-policy=keyframe sync-method=latest-keyframe sync=false
```
To send a file (video only):
```
# Make sure $SRC is set to an video file (e.g. an MP4 file)
gst-launch-1.0 \
filesrc location=$SRC ! decodebin ! \
queue ! videoconvert ! x264enc byte-stream=true ! \
h264parse config-interval=1 ! queue ! matroskamux ! queue leaky=2 ! \
tcpserversink port=7001 host=0.0.0.0 recover-policy=keyframe sync-method=latest-keyframe sync=false
```
To receive:
```
gst-launch-1.0 \
tcpclientsrc host=0.0.0.0 port=7001 typefind=true do-timestamp=false ! \
matroskademux ! typefind ! avdec_h264 ! autovideosink
```
I struggle to get VLC to play this (through `tcp://localhost:7001`).

26
rtmp.md
View file

@ -96,6 +96,7 @@ gst-launch-1.0 \
This overlays an RTMP source as a picture-in-picture on top of a local filesource (set as `$SRC`)
```
export QUEUE="queue max-size-time=0 max-size-bytes=0 max-size-buffers=0"
gst-launch-1.0 \
filesrc location="$SRC" ! \
decodebin ! videoconvert ! \
@ -111,7 +112,6 @@ gst-launch-1.0 \
mix.
```
## Sending to an RTMP server
### Sending a test stream to an RTMP server
@ -147,3 +147,27 @@ gst-launch-1.0 filesrc location=$SRC ! \
audio/x-raw,rate=48000 ! \
voaacenc bitrate=96000 ! audio/mpeg ! aacparse ! audio/mpeg, mpegversion=4 ! mux.
```
---
Can we work out why a bad RTMP brings down the other mix?
```
export QUEUE="queue max-size-time=0 max-size-bytes=0 max-size-buffers=0"
gst-launch-1.0 \
filesrc location="$SRC2" ! \
decodebin ! videoconvert ! \
videoscale ! video/x-raw,width=640,height=360 ! \
compositor name=mix sink_0::alpha=1 sink_1::alpha=1 sink_1::xpos=50 sink_1::ypos=50 ! \
videoconvert ! autovideosink \
rtmpsrc location="$RTMP_DEST" ! \
flvdemux name=demux \
demux.audio ! $QUEUE ! decodebin ! fakesink \
demux.video ! $QUEUE ! decodebin ! \
videoconvert ! \
videoscale ! video/x-raw,width=320,height=180! \
mix.
```

0
writing_to_files.md Normal file
View file