Gstreamer

Peter Maersk-Moller
Attachments
Snowmix-input.png (43194 bytes)

Input via GStreamer

This page has been obsoleted by the GStreamer Input Page on the new Snowmix website.

Updated for Snowmix-0.4.4 and GStreamer 1.x

Snowmix takes live video as input from video feeds primarily through shared memory interfacing with the GStreamer plugin module shmsink. The module shmsink is responsible for allocating a shared memory area, communicating the filename representing the shared memory area to Snowmix and feeding video into the shared memory. The video must be in the ARGB format or rather the BGRA format on little endian CPU systems such as the x86 CPU architecture. This means that each pixel is send to Snowmix in the order Blue, Green, Red and Alpha.

The image below shows 3 different types of input.

Snowmix-input

The GStreamer module needs a control channel to communicate with snowmix. This control channel is a named pipe (a fifo file) and both GStreamer and snowmix need to know the name of this pipe for this to work. This page will show and example of GStreamer feeding a video stream to snowmix.

GStreamer pipeline example: Input from File

Below is shown an example for inputting video to Snowmix using GStreamer version 1.0 tested with GStreamer version 1.0.0 through 1.4.1 and 1.5.0 as well as 0.10

    #!/bin/bash
    # These settings are the settings defined for video feed 1 in Snowmix
    CONTROL_PIPE=/tmp/feed1-control-pipe
    width=768
    height=576
    framerate='24/1'
    which gst-launch-1.0 2>/dev/null 1>&2
    if [ $? -eq 0 ] ; then
      gstlaunch=gst-launch-1.0
      DECODEBIN=decodebin
      SHMSIZE='shm-size='`echo "$width * $height * 4 * 14"|bc`
      MIXERFORMAT='video/x-raw, format=BGRA, pixel-aspect-ratio=1/1, interlace-mode=progressive'
      SCALE='videoconvert ! videorate ! videoscale ! videoconvert'
    else
      gstlaunch=gst-launch-0.10
      DECODEBIN=decodebin2
      SHMSIZE='shm-size='`echo "$width * $height * 4 * 8"|bc`
      MIXERFORMAT='video/x-raw-rgb, bpp=32, depth=32, endianness=4321, red_mask=65280, green_mask=16711680, blue_mask=-16777216, pixel-aspect-ratio=1/1, interlaced=false'
      SCALE='ffmpegcolorspace ! videorate ! videoscale ! ffmpegcolorspace'
    fi
    SRC="filesrc location=../test/LES_TDS_launch.mp4 ! $DECODEBIN "
    SHMOPTION="wait-for-connection=0 sync=true"
    SHMSINK1="shmsink socket-path=$CONTROL_PIPE $SHMSIZE $SHMOPTION"
    while true ; do
        # Remove the named pipe if it exist
        rm -f $CONTROL_PIPE
        $gstlaunch -v   \
            $SRC            !\
            $SCALENRATE     !\                
            $MIXERFORMAT"framerate=$framerate, width=$width, height=$height"    !\
            $SHMSINK1
        sleep 2
    done
    exit

In this example 'filesrc' reads from the file ../test/LES_TDS.mp4, decodes it, scale it to 704x576 and converts it to 32 bit RGBA (BGRA actually) before writing it to shared memory and signaling to Snowmix via the named pipe '/tmp/feed-control-pipe'. The example will stream the file over and over again with a 2 seconds pause until interrupted. The frame rate is set to 24fps. The videorate element is not strictly necessary as SNowmix will insert extra or drop frames automatically upon need.

Snowmix Configuration

For snowmix to receive the video feed from GStreamer configured as shown above, the following entries need to be added to snowmix either interactively or to the configuration file snowmix reads upon starting. The entries are

    feed add 1 Camera 1
    feed geometry 1 704 576
    feed live 1
    feed idle 1 100 ../frames/dead-704x576.rgba
    feed socket 1 /tmp/feed-control-pipe

These entries first add feed number 1 and name it 'Camera 1'. Then the geometry of the feed is defined. Then the feed is defined as live. Last but not least, snowmix is informed that the name of the named pipe used as control channel is /tmp/feed-control-pipe. The 'feed idle' command optionally tells snowmix to use and image (found in the RGBA dead-704x576.rgba as replacement for the live feed, should the feed be missing for 100 frames.

Other GStreamer examples:
GStreamer pipeline example: Input from a camera using V4L2 (Video for Linux)

The example below uses live video from web camera connected to the computer:

    #!/bin/bash
    CONTROL_PIPE=/tmp/feed-control-pipe
    width=704
    height=576
    framerate='25/1'
    which gst-launch-1.0 2>/dev/null 1>&2
    if [ $? -eq 0 ] ; then
      gstlaunch=gst-launch-1.0
      SHMSIZE='shm-size='`echo "$width * $height * 4 * 14"|bc`
      MIXERFORMAT='video/x-raw, format=BGRA, pixel-aspect-ratio=1/1, interlace-mode=progressive'
      SCALE='videoconvert ! videoscale ! videoconvert'
    else
      gstlaunch=gst-launch-0.10
      SHMSIZE='shm-size='`echo "$width * $height * 4 * 8"|bc`
      MIXERFORMAT='video/x-raw-rgb, bpp=32, depth=32, endianness=4321, red_mask=65280, green_mask=16711680, blue_mask=-16777216, pixel-aspect-ratio=1/1, interlaced=false'
      SCALE='ffmpegcolorspace ! videoscale ! ffmpegcolorspace'
    fi
    SRC='v4l2src device=/dev/video1 '
    SHMOPTION="wait-for-connection=0 sync=true"
    SHMSINK1="shmsink socket-path=$CONTROL_PIPE $SHMSIZE $SHMOPTION"
    while true ; do
        # Remove the named pipe if it exist
        rm -f $CONTROL_PIPE
        $gstlaunch -v          \
            $SRC              !\
            $SCALE            !\
            $MIXERFORMAT"width=$width, height=$height, framerate=$framerate" !\
            $SHMSINK1
        sleep 2
    done
    exit
GStreamer pipeline example: Input from a MPEG-4 UDP stream

The example below uses a MPEG-4 stream sent to a UDP port on the computer from an external IP based web camera.

    #!/bin/bash
    # These settings are from the Snowmix ini file for the feed.
    CONTROL_PIPE=/tmp/feed-control-pipe
    width=704
    height=576
    framerate='25/1'
    which gst-launch-1.0 2>/dev/null 1>&2
    if [ $? -eq 0 ] ; then
      gstlaunch=gst-launch-1.0
      SHMSIZE='shm-size='`echo "$width * $height * 4 * 14"|bc`
      MIXERFORMAT='video/x-raw, format=BGRA, pixel-aspect-ratio=1/1, interlace-mode=progressive'
      SCALENRATE='videoconvert ! videorate ! videoscale ! videoconvert'
    else
      gstlaunch=gst-launch-0.10
      SHMSIZE='shm-size='`echo "$width * $height * 4 * 8"|bc`
      MIXERFORMAT='video/x-raw-rgb, bpp=32, depth=32, endianness=4321, red_mask=65280, green_mask=16711680, blue_mask=-16777216, pixel-aspect-ratio=1/1, interlaced=false'
      SCALENRATE='ffmpegcolorspace ! videorate ! videoscale ! ffmpegcolorspace'
    fi
    SRC=" udpsrc port=4444 caps="application/x-rtp, media=(string)video, payload=(int)96, clock-rate=(int)90000, encoding-name=(string)MP4V-ES, profile-level-id=(string)245, config=(string)000001B0F5000001B50900000100000001200088401928B02240A21F, a-framerate=(string)30.0, a-mpeg4-esid=(string)201, clock-base=(uint)1918588220, seqnum-base=(uint)40098, npt-start=(guint64)0, play-speed=(double)1, play-scale=(double)1" ! rtpmp4vdepay ! mpeg4videoparse ! ffdec_mpeg4"
    SHMOPTION="wait-for-connection=0 sync=true "
    SHMSINK1="shmsink socket-path=$CONTROL_PIPE $SHMSIZE $SHMOPTION"
    while true ; do
        # Remove the named pipe if it exist
        rm -f $CONTROL_PIPE
        $gstlaunch -v           \
            $SRC               !\
            $SCALENRATE        !\
            $MIXERFORMAT", framerate=$framerate, width=$width, height=$height !\
            $SHMSINK1
        sleep 2
    done
    exit

Related

Wiki: Gstreamer Output
Wiki: Home

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks