Improve RTMP examples, amongst other things

This commit is contained in:
Matthew Clark 2018-02-21 22:46:55 +00:00
parent 7eab17fd69
commit d12138e065
4 changed files with 63 additions and 19 deletions

View file

@ -17,3 +17,8 @@ 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) * [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) * [Handy elements](https://gstreamer.freedesktop.org/documentation/tutorials/basic/handy-elements.html#uridecodebin)
## Other cheat sheets
* http://wiki.oz9aec.net/index.php/Gstreamer_cheat_sheet
* https://github.com/xmementoit/gstreamerCheatsheet/blob/master/README.md

View file

@ -10,6 +10,8 @@ export SRC=/home/me/videos/test.mp4
### Play a video (with audio) ### Play a video (with audio)
``` ```
gst-launch-1.0 -v playbin uri=file://$SRC gst-launch-1.0 -v playbin uri=file://$SRC
``` ```

68
rtmp.md
View file

@ -6,30 +6,66 @@ If you need your own RTMP server, [the Nginx RTMP extension](https://github.com/
### Play an RTMP stream ### Play an RTMP stream
To play from RTMP server, at the path `/live/x`, with the server name in the environment variable `RTMP_SERVER`: To play from RTMP server, playbin can be used (as with files and HLS streams):
``` ```
gst-launch-1.0 uridecodebin uri='rtmp://$RTMP_SERVER/live/x' ! \ gst-launch-1.0 playbin uri=$RTMP_SRC
videoconvert ! videorate ! videoscale ! videoconvert ! \
video/x-raw, format=BGRA, pixel-aspect-ratio=1/1, interlace-mode=progressive,framerate=24/1, width=640, height=360 ! \
autovideosink
``` ```
Russia Today is available over RTMP at `https://rtmp.api.rt.com/hls/rtdru360.m3u8`. So you can watch it with: A test RTMP stream is available at `rtmp://184.72.239.149/vod/BigBuckBunny_115k.mov` which serves as a useful example:
``` ```
gst-launch-1.0 uridecodebin uri='https://rtmp.api.rt.com/hls/rtdru360.m3u8' ! \ gst-launch-1.0 playbin uri='rtmp://184.72.239.149/vod/BigBuckBunny_115k.mov'
videoconvert ! videorate ! videoscale ! videoconvert ! \
video/x-raw, format=BGRA, pixel-aspect-ratio=1/1, interlace-mode=progressive,framerate=24/1, width=640, height=360 ! \
autovideosink
``` ```
### Stream TO an RTMP server Instead of using `playbin`, it's possible to get video only with `uridecodebin` then shown with `autovideosink`:
At the path '/live/x', with the server name in the environment variable `RTMP_SERVER`:
``` ```
gst-launch-1.0 videotestsrc \ gst-launch-1.0 uridecodebin uri=$RTMP_SRC ! autovideosink
is-live=true ! queue ! x264enc ! flvmux name=muxer ! \ ```
rtmpsink location='rtmp://$RTMP_SERVER/live/x'
Or as a step further we can split out into the source and decode too. This does video:
```
gst-launch-1.0 rtmpsrc location=$RTMP_SRC ! decodebin ! autovideosink
```
and this does the audio:
```
gst-launch-1.0 rtmpsrc name=rtmpsrc location=$RTMP_SRC ! decodebin ! \
queue ! audioconvert ! autoaudiosink
```
We can vget flvdemux to pull out the audio:
```
gst-launch-1.0 rtmpsrc location=$RTMP_SRC ! \
flvdemux name=t t.audio ! decodebin ! autoaudiosink
```
Incidentally, all of these work with a direct flv file:
```
gst-launch-1.0 filesrc location="/Users/clarkm22/workspace/silver/assets/test.flv" ! \
flvdemux name=t t.audio ! decodebin ! autoaudiosink
```
If you want to use `flvdemux` to do the video, you need to capture the audio too or else it will fail. This example puts it in `fakesink` which is basically discarding it:
```
gst-launch-1.0 rtmpsrc location="$RTMP_SRC" ! \
flvdemux name=demux \
demux.audio ! queue ! decodebin ! fakesink \
demux.video ! queue ! decodebin ! autovideosink
```
You could then use this to capture the RTMP as an MP4, e.g.
```
gst-launch-1.0 -e rtmpsrc location="$RTMP_SRC" ! \
flvdemux name=demux \
demux.audio ! queue ! decodebin ! audioconvert ! faac bitrate=32000 ! mux. \
demux.video ! queue ! decodebin ! videoconvert ! video/x-raw,format=I420 ! x264enc speed-preset=superfast tune=zerolatency psy-tune=grain sync-lookahead=5 bitrate=480 key-int-max=50 ref=2 ! mux. \
mp4mux name=mux ! filesink location="out.mp4"
``` ```

View file

@ -16,14 +16,15 @@ There are multiple test patterns available, such as
| Pattern | Example | | Pattern | Example |
| ------------- |:-------------:| | ------------- |:-------------:|
| `videotestsrc pattern=snow` | ![](images/test_snow.png) | | `videotestsrc pattern=snow` | ![](images/test_snow.png) |
| `videotestsrc pattern=red` (and blue and green) | ![](images/test_red.png) | | `videotestsrc pattern=red` (and blue, green, white and black) | ![](images/test_red.png) |
| `videotestsrc pattern=pinwheel` | ![](images/test_pinwheel.png) | | `videotestsrc pattern=pinwheel` | ![](images/test_pinwheel.png) |
| `videotestsrc pattern=smpte100` (color test bars) | ![](images/test_smpte100.png) | | `videotestsrc pattern=smpte100` (color test bars) | ![](images/test_smpte100.png) |
| `videotestsrc pattern=colors` | ![](images/test_colors.png) | | `videotestsrc pattern=colors` | ![](images/test_colors.png) |
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 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
### Listen to a test audio (beep)
### Listen to a test audio (beep)
``` ```
gst-launch-1.0 audiotestsrc ! audioconvert ! autoaudiosink gst-launch-1.0 audiotestsrc ! audioconvert ! autoaudiosink