Multimedia: GStreamer

GStreamer & automated testing in Lyon

Audio streaming

gstreamer pipeline to stream raw audio over network

gst-launch-1.0 -v filesrc location=/tmp/musicfile.mp3 ! mpegaudioparse ! mpg123audiodec ! audioconvert ! audioresample ! audio/x-raw, rate=16000, channels=1, format=S16LE ! audiomixer blocksize=320 ! udpsink host=192.168.1.10 port=10000
gst-launch-1.0 -v udpsrc port=10000 ! rawaudioparse use-sink-caps=false format=pcm pcm-format=s16le sample-rate=16000 num-channels=1 ! queue ! audioconvert ! audioresample ! autoaudiosink

v4l2loopback

Il software v4l2loopback consente di aprire “due volte” un dispositivo V4L2. Ciò può essere utile per consentire di effettuare snasphot (es. con v4l2grab) mentre è in corso la trasmissione del video da parte di un altro programma.

Installazione e creazione di un device virtuale con v4l2loopback

sudo apt-get install v4l2loopback-dkms
sudo modprobe v4l2loopback video_nr=10

Redirezione dell’output prodotto da un dispositivo reale (/dev/video0) in ingresso al dispositivo virtuale (/dev/video10)

  • Con ffmpeg
sudo apt-get install ffmpeg
ffmpeg -f video4linux2 -i /dev/video0 -vcodec copy -f v4l2 /dev/video10
  • Con gstreamer
sudo apt-get install gstreamer1.0-tools gstreamer1.0-plugins-good
gst-launch-1.0 v4l2src device=/dev/video0 ! v4l2sink device=/dev/video10

Script provati su Raspberry Pi 2 con Raspbian GNU/Linux 10 (buster)

uname -a
Linux raspberrypi 4.19.97-v7+ #1294 SMP Thu Jan 30 13:15:58 GMT 2020 armv7l GNU/Linux

Script video-test.sh

#!/bin/sh
gst-launch-1.0 videotestsrc ! autovideosink

Script video-test-ball.sh

#!/bin/sh
gst-launch-1.0 videotestsrc pattern=ball ! autovideosink

Script video-cam-test.sh

#!/bin/sh
gst-launch-1.0 -v v4l2src device=/dev/video0 ! video/x-raw,width=640,height=480,framerate=30/1 ! videoconvert ! tee ! queue ! autovideosink

Script video-test-src.sh

#!/bin/sh
gst-launch-1.0 videotestsrc ! video/x-raw,width=320,height=240 ! videoconvert ! tee ! v4l2sink device=/dev/video1

Script video-cam-src.sh

#!/bin/sh
gst-launch-1.0 v4l2src device=/dev/video0 ! video/x-raw,width=320,height=240 ! videoconvert ! tee ! v4l2sink device=/dev/video1

Streaming with GStreamer
gst-launch-1.0 \
v4l2src device=/dev/video0 \
! videorate ! videoscale \
! clockoverlay shaded-background=true font-desc="Sans 38" \
! video/x-raw,format=I420,width=640,height=360,framerate=25/1 \
! jpegenc ! rtpjpegpay \
! udpsink host=localhost port=5000
  • And here is the client:
gst-launch-1.0 -v \
udpsrc port=5000 \
! application/x-rtp, encoding-name=JPEG, framerate=25/1 \
! rtpjpegdepay ! jpegdec ! videoconvert ! ximagesink

Solution: I just needed to install gstreamer1.0-x as well.


#!/bin/bash
clear
raspivid -n -t 0 -rot 270 -w 960 -h 720 -fps 30 -b 6000000 -o - | gst-launch-1.0 -e -vvvv fdsrc ! h264parse ! rtph264pay pt=96 config-interval=5 ! udpsink host=***YOUR_PC_IP*** port=5000

Windows Command Prompt

gst-launch-1.0 -e -v udpsrc port=5000 ! application/x-rtp, payload=96 ! rtpjitterbuffer ! rtph264depay ! avdec_h264 ! fpsdisplaysink sync=false text-overlay=false

GStreamer and Python

Getting started with GStreamer 1.0 and Python 3.x

Python GStreamer Tutorial

Gstreamer webcam video feed in tkinter

Way to play video files in Tkinter?

python gstreamer play multiple video streams

convert gstreamer pipeline to python code

Python script


Python and VLC

d