使用 gstreamer 通过 UDP 从网络摄像头流式传输
Using gstreamer to stream from webcam over UDP
我正在尝试通过以下方式使用 gstreamer 从网络摄像头进行流式传输
gst-launch-1.0 -e -v v4l2src device=/dev/video0 ! image/jpeg, width=1920, height=1080, framerate=30/1 ! rtpjpegpay ! udpsink host=127.0.0.1 port=1234
并通过 this
接收
gst-launch-1.0 -e -v udpsrc port=1234 caps="application/x-rtp,payload=26,media=video,clock-rate=90000, encoding-name=JPEG, a-framerate=30/1, ssrc=459305186, timestamp-offset=2045518475, seqnum-offset=13040, height=1920, width=1080" ! rtpjpegdepay ! jpegdec ! avimux ! filesink location=swag.avi
运行 GST_DEBUG=avimux:5 产量
Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
/GstPipeline:pipeline0/GstCapsFilter:capsfilter0.GstPad:src: caps = "application/x-rtp\,\ payload\=\(int\)96\,\ media\=\(string\)video\,\ clock-rate\=\(int\)90000\,\ encoding-name\=\(string\)JPEG"
/GstPipeline:pipeline0/GstRtpJPEGDepay:rtpjpegdepay0.GstPad:sink: caps = "application/x-rtp\,\ payload\=\(int\)96\,\ media\=\(string\)video\,\ clock-rate\=\(int\)90000\,\ encoding-name\=\(string\)JPEG"
/GstPipeline:pipeline0/GstRtpJPEGDepay:rtpjpegdepay0.GstPad:src: caps = "image/jpeg\,\ framerate\=\(fraction\)0/1\,\ width\=\(int\)1920\,\ height\=\(int\)1080"
0:00:00.049099661 18712 0x1d34230 DEBUG avimux gstavimux.c:415:gst_avi_mux_vidsink_set_caps:<avimux0> avimux0:video_0, caps=image/jpeg, framerate=(fraction)0/1, width=(int)1920, height=(int)1080
0:00:00.049145352 18712 0x1d34230 WARN avimux gstavimux.c:641:gst_avi_mux_vidsink_set_caps:<avimux0> refused caps image/jpeg, framerate=(fraction)0/1, width=(int)1920, height=(int)1080
0:00:00.059443752 18712 0x1d34230 DEBUG avimux gstavimux.c:415:gst_avi_mux_vidsink_set_caps:<avimux0> avimux0:video_0, caps=image/jpeg, framerate=(fraction)0/1, width=(int)1920, height=(int)1080
0:00:00.059564217 18712 0x1d34230 WARN avimux gstavimux.c:641:gst_avi_mux_vidsink_set_caps:<avimux0> refused caps image/jpeg, framerate=(fraction)0/1, width=(int)1920, height=(int)1080
0:00:00.059662942 18712 0x1d34230 DEBUG avimux gstavimux.c:415:gst_avi_mux_vidsink_set_caps:<avimux0> avimux0:video_0, caps=image/jpeg, framerate=(fraction)0/1, width=(int)1920, height=(int)1080
0:00:00.059727807 18712 0x1d34230 WARN avimux gstavimux.c:641:gst_avi_mux_vidsink_set_caps:<avimux0> refused caps image/jpeg, framerate=(fraction)0/1, width=(int)1920, height=(int)1080
0:00:00.059997284 18712 0x1d34230 DEBUG avimux gstavimux.c:415:gst_avi_mux_vidsink_set_caps:<avimux0> avimux0:video_0, caps=image/jpeg, framerate=(fraction)0/1, width=(int)1920, height=(int)1080
ERROR: from element /GstPipeline:pipeline0/GstUDPSrc:udpsrc0: Internal data flow error.
0:00:00.060125073 18712 0x1d34230 WARN avimux gstavimux.c:641:gst_avi_mux_vidsink_set_caps:<avimux0> refused caps image/jpeg, framerate=(fraction)0/1, width=(int)1920, height=(int)1080
Additional debug info:
gstbasesrc.c(2943): gst_base_src_loop (): /GstPipeline:pipeline0/GstUDPSrc:udpsrc0:
streaming task paused, reason not-negotiated (-4)
0:00:00.060335173 18712 0x1d34230 DEBUG avimux gstavimux.c:415:gst_avi_mux_vidsink_set_caps:<avimux0> avimux0:video_0, caps=image/jpeg, framerate=(fraction)0/1, width=(int)1920, height=(int)1080
EOS on shutdown enabled -- waiting for EOS after Error
Waiting for EOS...
0:00:00.060462445 18712 0x1d34230 WARN avimux gstavimux.c:641:gst_avi_mux_vidsink_set_caps:<avimux0> refused caps image/jpeg, framerate=(fraction)0/1, width=(int)1920, height=(int)1080
/GstPipeline:pipeline0/GstAviMux:avimux0.GstPad:src: caps = video/x-msvideo
/GstPipeline:pipeline0/GstFakeSink:fakesink0.GstPad:sink: caps = video/x-msvideo
0:00:00.061094793 18712 0x1d34230 DEBUG avimux gstavimux.c:1177:gst_avi_mux_riff_get_avi_header:<avimux0> creating avi header, data_size 4, idx_size 0
^Chandling interrupt.
Interrupt: Stopping pipeline ...
Interrupt while waiting for EOS - stopping pipeline...
Execution ended after 0:00:02.492331232
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...
如果我放弃 udp 并直接执行此操作,它会像我 expect/want 到
一样工作
gst-launch-1.0 v4l2src device=/dev/video0 ! image/jpeg, width=1920, height=1080, framerate=30/1 ! rtpjpegpay ! application/x-rtp, payload=96 ! rtpjpegdepay ! avimux ! filesink location=movie.avi
补充一下,用这个接收效果非常好。
gst-launch-1.0 -e -v udpsrc port=1234 caps="application/x-rtp,payload=26,media=video,clock-rate=90000, encoding-name=JPEG, a-framerate=30/1, ssrc=459305186, timestamp-offset=2045518475, seqnum-offset=13040, height=1920, width=1080" ! rtpjpegdepay ! jpegdec ! autovideosink
为什么它不能通过 udp 工作,我该如何解决?
虽然 Prasanth 的建议并不完全正确,但这是正确的想法。后来我了解到,在启动 source 命令时,它会吐出给定组件的整个大写字母,例如
/GstPipeline:pipeline0/GstRtpJPEGPay:rtpjpegpay0.GstPad:src: caps = "application/x-rtp\,\ media\=\(string\)video\,\ clock-rate\=\(int\)90000\,\ encoding-name\=\(string\)JPEG\,\ a-framerate\=\(string\)30.000000\,\ payload\=\(int\)26\,\ ssrc\=\(uint\)3985523101\,\ timestamp-offset\=\(uint\)2117749493\,\ seqnum-offset\=\(uint\)21358"
通过将正确的盖子复制粘贴到水槽中,一切正常。
我正在尝试通过以下方式使用 gstreamer 从网络摄像头进行流式传输
gst-launch-1.0 -e -v v4l2src device=/dev/video0 ! image/jpeg, width=1920, height=1080, framerate=30/1 ! rtpjpegpay ! udpsink host=127.0.0.1 port=1234
并通过 this
接收gst-launch-1.0 -e -v udpsrc port=1234 caps="application/x-rtp,payload=26,media=video,clock-rate=90000, encoding-name=JPEG, a-framerate=30/1, ssrc=459305186, timestamp-offset=2045518475, seqnum-offset=13040, height=1920, width=1080" ! rtpjpegdepay ! jpegdec ! avimux ! filesink location=swag.avi
运行 GST_DEBUG=avimux:5 产量
Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
/GstPipeline:pipeline0/GstCapsFilter:capsfilter0.GstPad:src: caps = "application/x-rtp\,\ payload\=\(int\)96\,\ media\=\(string\)video\,\ clock-rate\=\(int\)90000\,\ encoding-name\=\(string\)JPEG"
/GstPipeline:pipeline0/GstRtpJPEGDepay:rtpjpegdepay0.GstPad:sink: caps = "application/x-rtp\,\ payload\=\(int\)96\,\ media\=\(string\)video\,\ clock-rate\=\(int\)90000\,\ encoding-name\=\(string\)JPEG"
/GstPipeline:pipeline0/GstRtpJPEGDepay:rtpjpegdepay0.GstPad:src: caps = "image/jpeg\,\ framerate\=\(fraction\)0/1\,\ width\=\(int\)1920\,\ height\=\(int\)1080"
0:00:00.049099661 18712 0x1d34230 DEBUG avimux gstavimux.c:415:gst_avi_mux_vidsink_set_caps:<avimux0> avimux0:video_0, caps=image/jpeg, framerate=(fraction)0/1, width=(int)1920, height=(int)1080
0:00:00.049145352 18712 0x1d34230 WARN avimux gstavimux.c:641:gst_avi_mux_vidsink_set_caps:<avimux0> refused caps image/jpeg, framerate=(fraction)0/1, width=(int)1920, height=(int)1080
0:00:00.059443752 18712 0x1d34230 DEBUG avimux gstavimux.c:415:gst_avi_mux_vidsink_set_caps:<avimux0> avimux0:video_0, caps=image/jpeg, framerate=(fraction)0/1, width=(int)1920, height=(int)1080
0:00:00.059564217 18712 0x1d34230 WARN avimux gstavimux.c:641:gst_avi_mux_vidsink_set_caps:<avimux0> refused caps image/jpeg, framerate=(fraction)0/1, width=(int)1920, height=(int)1080
0:00:00.059662942 18712 0x1d34230 DEBUG avimux gstavimux.c:415:gst_avi_mux_vidsink_set_caps:<avimux0> avimux0:video_0, caps=image/jpeg, framerate=(fraction)0/1, width=(int)1920, height=(int)1080
0:00:00.059727807 18712 0x1d34230 WARN avimux gstavimux.c:641:gst_avi_mux_vidsink_set_caps:<avimux0> refused caps image/jpeg, framerate=(fraction)0/1, width=(int)1920, height=(int)1080
0:00:00.059997284 18712 0x1d34230 DEBUG avimux gstavimux.c:415:gst_avi_mux_vidsink_set_caps:<avimux0> avimux0:video_0, caps=image/jpeg, framerate=(fraction)0/1, width=(int)1920, height=(int)1080
ERROR: from element /GstPipeline:pipeline0/GstUDPSrc:udpsrc0: Internal data flow error.
0:00:00.060125073 18712 0x1d34230 WARN avimux gstavimux.c:641:gst_avi_mux_vidsink_set_caps:<avimux0> refused caps image/jpeg, framerate=(fraction)0/1, width=(int)1920, height=(int)1080
Additional debug info:
gstbasesrc.c(2943): gst_base_src_loop (): /GstPipeline:pipeline0/GstUDPSrc:udpsrc0:
streaming task paused, reason not-negotiated (-4)
0:00:00.060335173 18712 0x1d34230 DEBUG avimux gstavimux.c:415:gst_avi_mux_vidsink_set_caps:<avimux0> avimux0:video_0, caps=image/jpeg, framerate=(fraction)0/1, width=(int)1920, height=(int)1080
EOS on shutdown enabled -- waiting for EOS after Error
Waiting for EOS...
0:00:00.060462445 18712 0x1d34230 WARN avimux gstavimux.c:641:gst_avi_mux_vidsink_set_caps:<avimux0> refused caps image/jpeg, framerate=(fraction)0/1, width=(int)1920, height=(int)1080
/GstPipeline:pipeline0/GstAviMux:avimux0.GstPad:src: caps = video/x-msvideo
/GstPipeline:pipeline0/GstFakeSink:fakesink0.GstPad:sink: caps = video/x-msvideo
0:00:00.061094793 18712 0x1d34230 DEBUG avimux gstavimux.c:1177:gst_avi_mux_riff_get_avi_header:<avimux0> creating avi header, data_size 4, idx_size 0
^Chandling interrupt.
Interrupt: Stopping pipeline ...
Interrupt while waiting for EOS - stopping pipeline...
Execution ended after 0:00:02.492331232
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...
如果我放弃 udp 并直接执行此操作,它会像我 expect/want 到
一样工作gst-launch-1.0 v4l2src device=/dev/video0 ! image/jpeg, width=1920, height=1080, framerate=30/1 ! rtpjpegpay ! application/x-rtp, payload=96 ! rtpjpegdepay ! avimux ! filesink location=movie.avi
补充一下,用这个接收效果非常好。
gst-launch-1.0 -e -v udpsrc port=1234 caps="application/x-rtp,payload=26,media=video,clock-rate=90000, encoding-name=JPEG, a-framerate=30/1, ssrc=459305186, timestamp-offset=2045518475, seqnum-offset=13040, height=1920, width=1080" ! rtpjpegdepay ! jpegdec ! autovideosink
为什么它不能通过 udp 工作,我该如何解决?
虽然 Prasanth 的建议并不完全正确,但这是正确的想法。后来我了解到,在启动 source 命令时,它会吐出给定组件的整个大写字母,例如
/GstPipeline:pipeline0/GstRtpJPEGPay:rtpjpegpay0.GstPad:src: caps = "application/x-rtp\,\ media\=\(string\)video\,\ clock-rate\=\(int\)90000\,\ encoding-name\=\(string\)JPEG\,\ a-framerate\=\(string\)30.000000\,\ payload\=\(int\)26\,\ ssrc\=\(uint\)3985523101\,\ timestamp-offset\=\(uint\)2117749493\,\ seqnum-offset\=\(uint\)21358"
通过将正确的盖子复制粘贴到水槽中,一切正常。