GStreamer* Video Pipeline with libv4l2#

Run a GStreamer* video pipeline using libv4l2 in a Docker* container.

Run the Sample Pipeline#

  1. Connect a video camera compatible with libv4l2, such as a webcam (an Intel® RealSense™ camera is not compatible).

  2. Check if your installation has the amr-gstreamer Docker* image.

    docker images |grep amr-gstreamer
    #if you have it installed, the result is:
    amr-gstreamer
    

    Note

    If the image is not installed, continuing with these steps triggers a build that takes longer than an hour (sometimes, a lot longer depending on the system resources and internet connection).

  3. If the image is not installed, Intel® recommends installing the Robot Base Kit or Robot Complete Kit with the Get Started Guide for Robots.

  4. Check that EI for AMR environment is set:

    echo $AMR_TUTORIALS
    # should output the path to EI for AMR tutorials
    /home/user/edge_insights_for_amr/Edge_Insights_for_Autonomous_Mobile_Robots_2023.1/AMR_containers/01_docker_sdk_env/docker_compose/05_tutorials
    

    If nothing is output, refer to Get Started Guide for Robots Step 5 for information on how to configure the environment.

  5. Get the stream from the webcam using GStreamer*:

    docker compose -f $AMR_TUTORIALS/gstreamer_libv4l2.tutorial.yml up
    

    Expected output: The stream from the webcam is displayed.

  6. To close this, do one of the following:

    • Type Ctrl-c in the terminal where you did the up command.

    • Run this command to remove the stopped containers:

    docker compose -f $AMR_TUTORIALS/gstreamer_libv4l2.tutorial.yml down
    
  7. For an explanation of what happened, open the yml file:

    • The first 37 lines are from the EI for AMR infrastructure.

    • Line 40 plays the stream from the webcam using GStreamer*.

Troubleshooting#

  • If the following error is encountered:

    eiforamr@edgesoftware:~/workspace$ gst-launch-1.0 v4l2src ! autovideosink
    Setting pipeline to PAUSED ...
    Pipeline is live and does not need PREROLL ...
    Setting pipeline to PLAYING ...
    ERROR: from element /GstPipeline:pipeline0/GstV4l2Src:v4l2src0: Internal data stream error.
    Additional debug info:
    gstbasesrc.c(3072): gst_base_src_loop (): /GstPipeline:pipeline0/GstV4l2Src:v4l2src0:
    streaming stopped, reason not-negotiated (-4)
    Execution ended after 0:00:00.000028689
    Setting pipeline to PAUSED ...
    Setting pipeline to READY ...
    Setting pipeline to NULL ...
    Freeing pipeline ...
    

    GStreamer* may want the type of decoding added. For example, for a Logitech* C922 webcam, the command is:

    $ gst-launch-1.0 v4l2src device=/dev/video0 ! jpegdec ! autovideosink
    
  • If the following error is encountered:

    amr-gstreamer | Setting pipeline to PAUSED ...
    amr-gstreamer | error: XDG_RUNTIME_DIR not set in the environment.
    

    try this:

    mkdir -pv ~/.cache/xdgr
    export XDG_RUNTIME_DIR=$PATH:~/.cache/xdgr
    
  • The following error might occur in a setup with multiple cameras:

    amr-gstreamer  | ERROR: from element /GstPipeline:pipeline0/GstV4l2Src:v4l2src0: Internal data stream error.
    amr-gstreamer  | Additional debug info:
    amr-gstreamer  | gstbasesrc.c(3072): gst_base_src_loop (): /GstPipeline:pipeline0/GstV4l2Src:v4l2src0:
    

    Identify the device number of the video camera that you want to use for this tutorial:

    for DEVICE in /sys/class/video4linux/*
      do echo $DEVICE; cat $DEVICE/name; echo ""
    done
    

    If your video camera is not listed as /sys/class/video4linux/video0, adapt the docker compose file 01_docker_sdk_env/docker_compose/05_tutorials/gstreamer_libv4l2.tutorial.yml such that the gst-launch-1.0 command specifies the correct video camera device

    gst-launch-1.0 v4l2src device=/dev/videoX ! videoconvert ! autovideosink
    

    where the X in /dev/videoX has to be replaced by the actual device number of your camera.

    As mentioned initially, the stream from an Intel® RealSense™ camera is not supported by libv4l2.

  • For general robot issues, go to: Troubleshooting for Robot Tutorials.