gstreamer-cheat-sheet/basics.md

100 lines
2.8 KiB
Markdown
Raw Normal View History

2018-02-20 12:23:23 +00:00
# Basics (GStreamer command-line cheat sheet)
## Playing content
2018-02-20 12:32:33 +00:00
For these,set `SRC` to be e.g. an mp4 file., e.g.
```
export SRC=/home/me/videos/test.mp4
```
2018-02-20 12:23:23 +00:00
### Play a video (with audio)
2018-02-23 08:07:52 +00:00
`playbin` is a magical element that can play anything:
2018-02-23 08:07:52 +00:00
```
gst-launch-1.0 playbin uri=file://$SRC
```
This works with video, audio, RTMP streams, and so much more.
The 'bin' in 'playbin' means that under-the-hood, it's a collection of elements. For example, we can achieve the same thing by going to the next level of elements, which separate the decoding part from the playing part:
2018-02-20 12:23:23 +00:00
```
2018-02-23 08:07:52 +00:00
gst-launch-1.0 filesrc location=$SRC ! decodebin ! playsink
2018-02-20 12:23:23 +00:00
```
2018-02-23 08:07:52 +00:00
Or, we can split down even further:
2018-02-20 12:23:23 +00:00
```
2018-02-20 12:32:33 +00:00
gst-launch-1.0 filesrc location=$SRC ! \
2018-02-23 08:07:52 +00:00
qtdemux name=demux demux.audio_0 ! queue ! decodebin ! audioconvert ! audioresample ! \
2018-02-20 12:32:33 +00:00
autoaudiosink \
demux.video_0 ! queue ! \
decodebin ! videoconvert ! videoscale ! autovideosink
2018-02-20 12:23:23 +00:00
```
2018-02-20 12:26:20 +00:00
### Play a video (no audio)
2018-02-20 12:23:23 +00:00
```
2018-02-20 12:32:33 +00:00
gst-launch-1.0 -v uridecodebin uri="file://$SRC" ! autovideosink
2018-02-20 12:23:23 +00:00
```
which could also have been done as:
```
2018-02-20 12:32:33 +00:00
gst-launch-1.0 -v filesrc location="$SRC" ! decodebin ! autovideosink
2018-02-20 12:23:23 +00:00
```
2018-02-20 12:32:33 +00:00
### Play just the audio from a video
2018-02-20 12:23:23 +00:00
```
2018-02-20 12:32:33 +00:00
gst-launch-1.0 -v uridecodebin uri="file://$SRC" ! autoaudiosink
2018-02-20 12:23:23 +00:00
```
2018-02-20 12:32:33 +00:00
### Visualise the audio:
2018-02-20 12:23:23 +00:00
```
2018-02-20 12:32:33 +00:00
gst-launch-1.0 filesrc location=$SRC ! qtdemux name=demux demux.audio_0 ! queue ! decodebin ! audioconvert ! wavescope ! autovideosink
2018-02-20 12:23:23 +00:00
```
2018-02-20 12:32:33 +00:00
(or replace `wavescope` with `spectrascope` or `synaescope` or `spacescope`)
2018-02-20 12:23:23 +00:00
Or even better visualisation:
```
2018-02-20 12:32:33 +00:00
gst-launch-1.0 filesrc location=$SRC ! decodebin ! tee name=t ! queue ! audioconvert ! wavescope style=color-lines shade-amount=0x00080402 ! alpha alpha=0.5 ! videomixer name=m background=black ! videoconvert ! vertigotv ! autovideosink t. ! queue ! audioconvert ! spacescope style=color-lines shade-amount=0x00080402 ! alpha alpha=0.5 ! m. t. ! queue ! autoaudiosink
2018-02-20 12:23:23 +00:00
```
2018-02-20 12:32:33 +00:00
### Add filters
2018-02-20 12:23:23 +00:00
2018-02-20 12:32:33 +00:00
Go slightly mad:
2018-02-20 12:23:23 +00:00
```
2018-02-20 12:32:33 +00:00
gst-launch-1.0 -v filesrc location="$SRC" ! decodebin ! videoconvert ! vertigotv ! autovideosink
2018-02-20 12:23:23 +00:00
```
Try also rippletv, streaktv, radioactv, optv, quarktv, revtv, shagadelictv, warptv (I like), dicetv, agingtv (great), edgetv (could be great on real stuff)
2018-02-20 12:26:20 +00:00
### Resize video
2018-02-20 12:23:23 +00:00
```
2018-02-20 12:32:33 +00:00
gst-launch-1.0 -v filesrc location="$SRC" ! decodebin ! videoconvert ! videoscale ! video/x-raw,width=100 ! autovideosink
2018-02-20 12:23:23 +00:00
```
2018-02-20 12:26:20 +00:00
### Change framerate
2018-02-20 12:23:23 +00:00
```
2018-02-20 12:32:33 +00:00
gst-launch-1.0 -v filesrc location="$SRC" ! decodebin ! videoconvert ! videorate ! video/x-raw,framerate=5/1 ! autovideosink
2018-02-20 12:23:23 +00:00
```
And of course you can resize the video and change the framerate:
```
gst-launch-1.0 -v \
2018-02-20 12:32:33 +00:00
filesrc location="$SRC” ! \
2018-02-20 12:23:23 +00:00
decodebin ! videoconvert ! videoscale ! video/x-raw,width=100 ! videorate ! video/x-raw,framerate=5/1 ! \
autovideosink
```
2018-02-23 08:07:52 +00:00