How to stream RAW camera over network

Revision as of 12:37, 13 November 2023 by Registered User
Applicable for STM32MP25x lines

1. Overview[edit source]

This article will explain how to stream camera content over network thanks to GStreamer application on top of V4L2 Linux® kernel framework.

This article focus on camera sensor which doesn't output compressed image or video content but raw content such as YUV, RGB or Raw-bayer.

Remote sending of images with a decent framerate requires compression in order to respect a reasonable bandwidth on network. This could be achieved compressing to JPEG image format or video formats like VP8 or H264.

Find below some examples of command lines allowing to capture a continuous JPEG, VP8 and H264 stream while playing it using various multimedia players, either local or remote.

2. Local streaming[edit source]

Here is an example of a local preview involving V4l2-ctl for JPEG pictures capture and gst-play GStreamer player for JPEG decoding and display. JPEG pictures are sent over a standard Linux pipe.

Warning white.png Warning
If Weston is configured with a "weston" user instead of a "root" user, please use the following command:
 su -l "weston" -c "your_weston_command"


For STM32MP255 line More info.png, setup the camera subsystem first:
 /usr/local/demo/application/camera/bin/launch_camera_preview_mp25.sh
<wait few seconds that image is correct then hit "CTRL+C">
  media-ctl -d /dev/media1 --set-v4l2 "'dcmipp_main_postproc':0[compose:(0,0)/640x480]" 
  media-ctl -d /dev/media1 --set-v4l2 "'dcmipp_main_postproc':1[fmt:YUYV8_2X8/640x480]"


Capture YUV pictures then compress to JPEG then decode & display them:

 gst-launch-1.0 v4l2src device=/dev/video3 ! video/x-raw, format=YUY2, width=640, height=480, framerate=30/1 ! encodebin profile="image/jpeg" ! decodebin ! autovideosink


Special URI fd://0 tells gst-play GStreamer player to read data from the pipe.

Note the 2>/dev/null right after the V4l2-ctl command to remove the logs from console output.

3. UDP streaming[edit source]

An internet connection is required, for example by plugging an ethernet cable on the:

STM32MP135x-DK Discovery kit More info green.png CN4 Ethernet connector 1 or CN15 Ethernet connector 2
STM32MP157x-DKx Discovery kit More info green.png CN8 Ethernet connector
STM32MP157x-EV1 Evaluation board More info green.png CN3 Ethernet connector


For STM32MP135 line More info.png, setup the camera subsystem first:
 media-ctl -d /dev/media0 --set-v4l2 "'ov5640 1-003c':0[fmt:JPEG_1X8/640x480@1/30 field:none]"
media-ctl -d /dev/media0 --set-v4l2 "'dcmipp_parallel':0[fmt:JPEG_1X8/640x480]"
media-ctl -d /dev/media0 --set-v4l2 "'dcmipp_dump_postproc':0[fmt:JPEG_1X8/640x480]"
media-ctl -d /dev/media0 --set-v4l2 "'dcmipp_dump_postproc':1[fmt:JPEG_1X8/640x480]" 
media-ctl -d /dev/media0 --set-v4l2 "'dcmipp_dump_postproc':1[crop:(0,0)/640x480]"


Get the IP address aa.bb.cc.dd of the host PC using ifconfig command:

 ifconfig | grep "inet addr"
   inet addr:aa.bb.cc.dd  Bcast:10.201.23.255  Mask:255.255.252.0
   inet addr:127.0.0.1  Mask:255.0.0.0

Then fill the host= udpsink property with this IP address on the remote side:

 v4l2-ctl --set-parm=30;v4l2-ctl --set-fmt-video=width=640,height=480,pixelformat=JPEG --stream-mmap --stream-count=-1 --stream-to=- 2>/dev/null | gst-launch-1.0 fdsrc ! jpegparse ! rtpjpegpay ! udpsink host=aa.bb.cc.dd port=5000

Then play the UDP stream on host PC:

 gst-launch-1.0 udpsrc port=5000 ! application/x-rtp, encoding-name=JPEG ! rtpjpegdepay ! jpegparse ! decodebin ! videoconvert ! autovideosink

A new window will popup on host PC displaying the camera content.

Info white.png Information
Due to SDP protocol signaling, this solution is not fully interoperable because it needs a dedicated GStreamer command line to be played on host side