“How to stream camera over network”的版本间的差异
Zhouyuebiao(讨论 | 贡献) |
Zhouyuebiao(讨论 | 贡献) |
||
第1行: | 第1行: | ||
− | + | == Overview == | |
+ | This article will explain how to stream camera content over network thanks to [[GStreamer overview|GStreamer]] application on top of [[V4L2_camera_overview|V4L2 Linux<sup>®</sup> 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. |
− | + | ||
− | + | 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. | |
− | [[Category: | + | |
+ | == Local streaming == | ||
+ | Here is an example of a local preview involving [[V4l2-ctl]] for JPEG pictures capture and [[Gst-play|gst-play]] GStreamer player for JPEG decoding and display. JPEG pictures are sent over a standard Linux pipe. | ||
+ | {{Board$}} v4l2-ctl --set-parm=30;v4l2-ctl --set-fmt-video=width=640,height=480,pixelformat=JPEG --stream-mmap --stream-count=-1 {{highlight|'''--stream-to{{=}}-'''}} {{HighlightParam|2>/dev/null}} {{highlight|'''<nowiki>|</nowiki>'''}} gst-play-1.0 {{highlight|'''"fd://0"'''}} | ||
+ | {{highlight|'''--stream-to{{=}}-'''}} tells [[V4l2-ctl]] to output binary captured content to standard output, which is then sent to pipe {{highlight|'''<nowiki>|</nowiki>'''}}. | ||
+ | |||
+ | Special URI {{highlight|'''fd://0'''}} tells [[Gst-play|gst-play]] GStreamer player to read data from the pipe. | ||
+ | |||
+ | Note the {{HighlightParam|2>/dev/null}} right after the [[V4l2-ctl]] command to remove the logs from console output. | ||
+ | <br> | ||
+ | <br> | ||
+ | |||
+ | == UDP streaming == | ||
+ | {{Info|An internet connection is required, for example by plugging an ethernet cable on the [[STM32MP157C-EV1 - hardware description#MB1262-CN3|STM32MP157C-EV1 Evaluation board CN3 ethernet connector]]}}{{UpdateNeededForNewBoard|Point to the ethernet connector (if any) of the new board}} | ||
+ | Get first the IP address {{highlight|'''aa.bb.cc.dd'''}} of the host PC using [[Ifconfig|ifconfig]] command: | ||
+ | {{PC$}} ifconfig | grep "inet addr" | ||
+ | inet addr:{{highlight|'''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 {{HighlightParam|'''host{{=}}'''}} udpsink property with this IP address on the remote side: | ||
+ | {{Board$}} 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 {{HighlightParam|'''host{{=}}'''}}{{highlight|'''aa.bb.cc.dd'''}} port=5000 | ||
+ | |||
+ | Then play the UDP stream on host PC: | ||
+ | {{PC$}} gst-launch-1.0 udpsrc port=5000 ! application/x-rtp, encoding-name=JPEG ! rtpjpegdepay ! jpegparse ! decodebin ! autovideosink | ||
+ | A new window will popup on host PC displaying the camera content. | ||
+ | {{Info|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}} | ||
+ | |||
+ | |||
+ | <!-- | ||
+ | == RTSP streaming == | ||
+ | {{Warning| neet to explain gst-rtsp-server-launch-1.0 (derived from GStreamer example test_launch.c of rtsp libraries) and not yet documented}} | ||
+ | Prerequesite: | ||
+ | * Board connected to local network | ||
+ | * RTSP server [[GStreamer overview|GStreamer]] libraries (libgstrtspserver-1.0.so* to be put in /usr/lib/gstreamer-1.0/) | ||
+ | * gst-rtsp-server-launch-1.0 [[GStreamer overview|GStreamer]] utility | ||
+ | * Get the ip address of the board: | ||
+ | {{Board$}} ifconfig | ||
+ | |||
+ | eth0 Link encap:Ethernet HWaddr 00:80:E1:42:42:D8 | ||
+ | inet addr:{{blue|'''10.48.1.122'''}} Bcast:10.48.3.255 Mask:255.255.252.0 | ||
+ | |||
+ | |||
+ | Capture VGA jpeg pictures and stream them over network using RTSP streaming protocol: | ||
+ | {{Board$}} gst-rtsp-server-launch-1.0 {{blue|'''10.48.1.122'''}} 8081 "/test" "( v4l2src do-timestamp=true device=/dev/video0 ! image/jpeg, width=640, height=480, framerate=(fraction)15/1 ! queue ! jpegparse ! rtpjpegpay name=pay0 pt=96 )" | ||
+ | |||
+ | stream ready at {{green|'''rtsp://10.48.1.122:8081/test'''}} | ||
+ | |||
+ | |||
+ | Stream can then be played on host PC using any media player which support RTSP streaming such as [[GStreamer overview|GStreamer]] or VLC: | ||
+ | {{PC$}} gst-play-1.0 {{green|'''rtsp://10.48.1.122:8081/test'''}} | ||
+ | |||
+ | {{PC$}} cvlc {{green|'''rtsp://10.48.1.122:8081/test'''}} | ||
+ | |||
+ | Stream can also be played on another target with same [[Gst-play|gst-play]] [[GStreamer overview|GStreamer]] utility: | ||
+ | {{Board$}} gst-play-1.0 {{green|'''rtsp://10.48.1.122:8081/test'''}} | ||
+ | --> | ||
+ | |||
+ | <noinclude> | ||
+ | {{ArticleBasedOnModel | How to article model}} | ||
+ | {{PublicationRequestId | 7962 | 2018-07-05 | AlainF}} | ||
+ | [[Category:How to run use cases]] | ||
+ | [[Category:V4L2]] | ||
+ | [[Category:GStreamer]] | ||
+ | </noinclude> |
2020年5月8日 (五) 22:52的最新版本
Overview
This article will explain 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.
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.
Local streaming
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.
Board $> 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-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.
UDP streaming
An internet connection is required, for example by plugging an ethernet cable on the STM32MP157C-EV1 Evaluation board CN3 ethernet connector |
Get first the IP address aa.bb.cc.dd of the host PC using ifconfig command:
PC $> 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:
Board $> 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:
PC $> gst-launch-1.0 udpsrc port=5000 ! application/x-rtp, encoding-name=JPEG ! rtpjpegdepay ! jpegparse ! decodebin ! autovideosink
A new window will popup on host PC displaying the camera content.
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 |
<securetransclude src="ProtectedTemplate:ArticleBasedOnModel" params="How to article model"></securetransclude>
<securetransclude src="ProtectedTemplate:PublicationRequestId" params="7962 | 2018-07-05 | AlainF"></securetransclude>