Last edited 3 weeks ago

How to stream camera over network

Applicable for STM32MP13x lines, STM32MP15x lines


1. Overview[edit | edit source]

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

Capturing compressed JPEG pictures is an efficient way to send camera images to any local or remote player. JPEG pictures require a limited bandwidth while being fully interoperable.

Info white.png Information
This article focus on camera sensors that can directly output JPEG content, if it is not the case refer to How to stream RAW camera over network.

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

2. Local streaming[edit | 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.



For STM32MP135 line More info.png, set up 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 "'st-mipid02 1-0014':2[fmt:JPEG_1X8/640x480]"
media-ctl -d /dev/media0 --set-v4l2 "'dcmipp_input':1[fmt:JPEG_1X8/640x480]"
media-ctl -d /dev/media0 --set-v4l2 "'dcmipp_dump_postproc':1[fmt:JPEG_1X8/640x480]"

Capture the JPEG pictures then decode and display them:

v4l2-ctl --set-fmt-video=width=640,height=480,pixelformat=JPEG --set-parm=30 --stream-mmap --stream-count=-1 --stream-to=- 2>/dev/null | gst-play-1.0 "fd://0"

--stream-to=- tells V4l2-ctl to output binary captured content to standard output, which is then sent to pipe |.

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 | 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
Info white.png Information
On the STM32MP135x-DK board, the GC2145 camera sensor is not capable of streaming JPEG data, hence JPEG based network streaming is not possible with this sensor. The example below is given using a CSI based OV5640 sensor, capable of JPEG output.


For STM32MP135 line More info.png, set up 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 "'st-mipid02 1-0014':2[fmt:JPEG_1X8/640x480]"
media-ctl -d /dev/media0 --set-v4l2 "'dcmipp_input':1[fmt:JPEG_1X8/640x480]"
media-ctl -d /dev/media0 --set-v4l2 "'dcmipp_dump_postproc':1[fmt:JPEG_1X8/640x480]"

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

ifconfig | grep "inet"
   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-fmt-video=width=640,height=480,pixelformat=JPEG --set-parm=30 --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 the host PC:

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

A new window appears on the 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 the host side.