Difference between revisions of "Using gstreamer"

From ElphelWiki
Jump to: navigation, search
(Command line examples)
Line 20: Line 20:
  
 
<b>Note: replace width and height accordingly to your camera setup and your computer's horsepower :P)</b>
 
<b>Note: replace width and height accordingly to your camera setup and your computer's horsepower :P)</b>
 +
 +
== GStreamer 1.0==
 +
 +
===Display===
 +
 +
====Multipart JPEGs, 4 channels in 1 window====
 +
* Each source is resized to 640x480
 +
* Text overlay and borders added
 +
<font size='2'>
 +
gst-launch-1.0 -ve videomixer name=mix \
 +
    sink_0::alpha=1 sink_0::xpos=0  sink_0::ypos=0 \
 +
    sink_1::alpha=1 sink_1::xpos=646 sink_1::ypos=0 \
 +
    sink_2::alpha=1 sink_2::xpos=0  sink_2::ypos=486 \
 +
    sink_3::alpha=1 sink_3::xpos=646 sink_3::ypos=486 \
 +
    ! \
 +
    xvimagesink sync=false \
 +
    souphttpsrc is-live=true location=http://192.168.0.8:2323/noexif/mimg ! image/jpeg,width=1,height=1,framerate=1000/1,pixel-aspect-ratio=1/1 ! \
 +
    jpegdec ! videoscale ! video/x-raw,width=640,height=480 ! videobox fill=Black top=-4 bottom=-2 left=-4 right=-2 ! \
 +
    textoverlay text=cam1 halignment=left valignment=top text-width=20 text-height=20 shaded-background=true ! mix. \
 +
    souphttpsrc is-live=true location=http://192.168.0.8:2324/noexif/mimg ! image/jpeg,width=1,height=1,framerate=1000/1,pixel-aspect-ratio=1/1 ! \
 +
    jpegdec ! videoscale ! video/x-raw,width=640,height=480 ! videobox fill=Black top=-4 bottom=-2 left=-2 right=-4 ! \
 +
    textoverlay text=cam2 halignment=left valignment=top text-width=20 text-height=20 shaded-background=true ! mix. \
 +
    souphttpsrc is-live=true location=http://192.168.0.8:2325/noexif/mimg ! image/jpeg,width=1,height=1,framerate=1000/1,pixel-aspect-ratio=1/1 ! \
 +
    jpegdec ! videoscale ! video/x-raw,width=640,height=480 ! videobox fill=Black top=-2 bottom=-4 left=-4 right=-2 ! \
 +
    textoverlay text=cam3 halignment=left valignment=top text-width=20 text-height=20 shaded-background=true ! mix. \
 +
    souphttpsrc is-live=true location=http://192.168.0.8:2326/noexif/mimg ! image/jpeg,width=1,height=1,framerate=1000/1,pixel-aspect-ratio=1/1 ! \
 +
    jpegdec ! videoscale ! video/x-raw,width=640,height=480 ! videobox fill=Black top=-2 bottom=-4 left=-2 right=-4 ! \
 +
    textoverlay text=cam4 halignment=left valignment=top text-width=20 text-height=20 shaded-background=true ! mix.
 +
</font>
  
 
== GStreamer 0.10==
 
== GStreamer 0.10==
  
=== Displaying ===
+
=== Display ===
 
careful with streams at higher resolution than 1920x1088
 
careful with streams at higher resolution than 1920x1088
  

Revision as of 14:57, 9 June 2016

GStreamer is a modular node based player as well as encoder in a single application. It is possible to create chains of so called elements with a wide range of different plugins.

GStreamer

GStreamer is a library for constructing graphs of media-handling components. The applications it supports range from simple Ogg/Vorbis playback, audio/video streaming to complex audio (mixing) and video (non-linear editing) processing.

Applications can take advantage of advances in codec and filter technology transparently. Developers can add new codecs and filters by writing a simple plugin with a clean, generic interface.

Installing GStreamer

NicoLargo made a script to automatically install all the required packages for GStreamer on Ubuntu 10.04. Should work up to for (K)Ubuntu 16.04 as well.

Tips

How to get 25 FPS ?

Depends on the sensor and the exposure:

  • In the sensor's datasheet find resolutions that allow the required FPS.
  • You won't get 25 fps if autoexposure is on and local brightness not high enough: the camera will automatically lower framerate for keeping clear picture. Either lighten up, or play with image settings (notably, gain).


Command line examples

Note: replace width and height accordingly to your camera setup and your computer's horsepower :P)

GStreamer 1.0

Display

Multipart JPEGs, 4 channels in 1 window

  • Each source is resized to 640x480
  • Text overlay and borders added

gst-launch-1.0 -ve videomixer name=mix \
    sink_0::alpha=1 sink_0::xpos=0   sink_0::ypos=0 \
    sink_1::alpha=1 sink_1::xpos=646 sink_1::ypos=0 \
    sink_2::alpha=1 sink_2::xpos=0   sink_2::ypos=486 \
    sink_3::alpha=1 sink_3::xpos=646 sink_3::ypos=486 \
    ! \
    xvimagesink sync=false \
    souphttpsrc is-live=true location=http://192.168.0.8:2323/noexif/mimg ! image/jpeg,width=1,height=1,framerate=1000/1,pixel-aspect-ratio=1/1 ! \
    jpegdec ! videoscale ! video/x-raw,width=640,height=480 ! videobox fill=Black top=-4 bottom=-2 left=-4 right=-2 ! \
    textoverlay text=cam1 halignment=left valignment=top text-width=20 text-height=20 shaded-background=true ! mix. \
    souphttpsrc is-live=true location=http://192.168.0.8:2324/noexif/mimg ! image/jpeg,width=1,height=1,framerate=1000/1,pixel-aspect-ratio=1/1 ! \
    jpegdec ! videoscale ! video/x-raw,width=640,height=480 ! videobox fill=Black top=-4 bottom=-2 left=-2 right=-4 ! \
    textoverlay text=cam2 halignment=left valignment=top text-width=20 text-height=20 shaded-background=true ! mix. \
    souphttpsrc is-live=true location=http://192.168.0.8:2325/noexif/mimg ! image/jpeg,width=1,height=1,framerate=1000/1,pixel-aspect-ratio=1/1 ! \
    jpegdec ! videoscale ! video/x-raw,width=640,height=480 ! videobox fill=Black top=-2 bottom=-4 left=-4 right=-2 ! \
    textoverlay text=cam3 halignment=left valignment=top text-width=20 text-height=20 shaded-background=true ! mix. \
    souphttpsrc is-live=true location=http://192.168.0.8:2326/noexif/mimg ! image/jpeg,width=1,height=1,framerate=1000/1,pixel-aspect-ratio=1/1 ! \
    jpegdec ! videoscale ! video/x-raw,width=640,height=480 ! videobox fill=Black top=-2 bottom=-4 left=-2 right=-4 ! \
    textoverlay text=cam4 halignment=left valignment=top text-width=20 text-height=20 shaded-background=true ! mix.

GStreamer 0.10

Display

careful with streams at higher resolution than 1920x1088

Display the cameras live video stream at its native resolution:

gst-launch-0.10 rtspsrc location=rtsp://192.168.0.9:554 ! rtpjpegdepay ! jpegdec ! queue ! ffmpegcolorspace ! xvimagesink sync=false

Display the cameras live video stream, resize to fit window (the ! videoscale element takes care of that)

gst-launch-0.10 rtspsrc location=rtsp://192.168.0.9:554 ! rtpjpegdepay ! jpegdec ! queue ! ffmpegcolorspace ! videoscale ! xvimagesink sync=false

Dumping

mjpeg dumping

gst-launch -v rtspsrc location=rtsp://192.168.0.9:554 ! queue ! rtpjpegdepay ! videorate ! capsfilter caps = "image/jpeg, framerate=(fraction)25/1, width=1024, height=768" ! queue ! matroskamux ! filesink location=/tmp/test.mkv

YUV Dumping

gst-launch -v rtspsrc location=rtsp://192.168.0.9:554 ! queue ! rtpjpegdepay ! queue ! jpegdec ! queue ! videorate ! capsfilter caps="video/x-raw-yuv, format=(fourcc)I420, width=(int)1024, height=(int)768, framerate=(fraction)25/1" ! queue ! avimux ! filesink location=/tmp/test.avi

Dump transcoding example

gst-launch filesrc location=test.mkv ! matroskademux ! queue ! jpegdec ! queue ! theoraenc bitrate=4000 ! queue ! oggmux ! filesink location=test.ogg

Live encoding

gst-launch -v rtspsrc location=rtsp://192.168.0.9:554 ! queue ! rtpjpegdepay ! queue ! jpegdec ! queue ! videorate ! capsfilter caps="video/x-raw-yuv, format=(fourcc)I420, width=(int)1024, height=(int)768, framerate=(fraction)25/1" ! queue ! theoraenc bitrate=4000 ! queue ! oggmux ! filesink location=/tmp/test1024.ogg

I did some benchmarks; a Core 2 Quad Q6600 (2.4 Ghz) is not powerful enough for h264 encoding @fullHD resolution (using 4 treads).