使用GStreamer读取FFmpeg推送的RTSP循环流时遇错误求助
问题:GStreamer读取FFmpeg推送的RTSP循环流失败
推流端(FFmpeg)命令
使用以下命令将静态MP4无限循环推为RTSP流:
ffmpeg -flush_packets 1 -re -stream_loop -1 -i sample.mp4 -f rtsp rtsp://ip:8554/mystream
拉流端(GStreamer)尝试的命令及错误
第一次尝试的命令
命令1:
gst-launch-1.0 rtspsrc location=rtsp://ip:8554/mystream
命令2:
gst-launch-1.0 rtspsrc location=rtsp://ip:8554/mystream ! avdec_h264 ! autovideoconvert ! queue ! rtph264depay ! h264parse ! autovideosink
错误日志:
Setting pipeline to PAUSED ... Pipeline is live and does not need PREROLL ... Progress: (open) Opening Stream Progress: (connect) Connecting to rtsp://10.0.0.19:8554/mystream Progress: (open) Retrieving server options Progress: (open) Retrieving media info Progress: (request) SETUP stream 0 Progress: (request) SETUP stream 1 Progress: (open) Opened Stream Setting pipeline to PLAYING ... New clock: GstSystemClock Progress: (request) Sending PLAY request Progress: (request) Sending PLAY request Progress: (request) Sent PLAY request WARNING: from element /GstPipeline:pipeline0/GstRTSPSrc:rtspsrc0: Delayed linking failed. Additional debug info: ./grammar.y(510): gst_parse_no_more_pads (): /GstPipeline:pipeline0/GstRTSPSrc:rtspsrc0: failed delayed linking some pad of GstRTSPSrc named rtspsrc0 to some pad of avdec_h264 named avdec_h264-0 ERROR: from element /GstPipeline:pipeline0/GstRTSPSrc:rtspsrc0: Internal data stream error. Additional debug info: gstrtspsrc.c(5653): gst_rtspsrc_loop (): /GstPipeline:pipeline0/GstRTSPSrc:rtspsrc0: streaming stopped, reason not-linked (-1) Execution ended after 0:00:01.552277296 Setting pipeline to PAUSED ... Setting pipeline to READY ... Setting pipeline to NULL ... Freeing pipeline ...
第二次尝试的命令
gst-launch-1.0 rtspsrc location=rtsp://ip:8554/mystream ! application/x-rtp,media=video,encoding-name=H264,clock-rate=90000 ! rtph264depay ! h264parse ! avdec_h264 ! videorate ! videoconvert ! queue! autovideosink
更新后的错误日志:
Setting pipeline to PAUSED ... Pipeline is live and does not need PREROLL ... Progress: (open) Opening Stream Progress: (connect) Connecting to rtsp://10.0.0.19:8554/mystream Progress: (open) Retrieving server options Progress: (open) Retrieving media info Progress: (request) SETUP stream 0 Progress: (request) SETUP stream 1 Progress: (open) Opened Stream Setting pipeline to PLAYING ... New clock: GstSystemClock Progress: (request) Sending PLAY request Progress: (request) Sending PLAY request Progress: (request) Sent PLAY request 0:00:02.180429398 3554 0x7f1cdc04e230 WARN basesrc gstbasesrc.c:3055:gst_base_src_loop:<udpsrc0> error: Internal data stream error. 0:00:02.180465192 3554 0x7f1cdc04e230 WARN basesrc gstbasesrc.c:3055:gst_base_src_loop:<udpsrc0> error: streaming stopped, reason not-linked (-1) 0:00:03.316770515 3554 0x7f1cdc032b20 WARN default grammar.y:510:gst_parse_no_more_pads:<rtspsrc0> warning: Delayed linking failed. 0:00:03.316823812 3554 0x7f1cdc032b20 WARN default grammar.y:510:gst_parse_no_more_pads:<rtspsrc0> warning: failed delayed linking some pad of GstRTSPSrc named rtspsrc0 to some pad of GstRtpH264Depay named rtph264depay0 WARNING: from element /GstPipeline:pipeline0/GstRTSPSrc:rtspsrc0: Delayed linking failed. Additional debug info: ./grammar.y(510): gst_parse_no_more_pads (): /GstPipeline:pipeline0/GstRTSPSrc:rtspsrc0: failed delayed linking some pad of GstRTSPSrc named rtspsrc0 to some pad of GstRtpH264Depay named rtph264depay0 0:00:04.018867523 3554 0x7f1cdc04e280 WARN basesrc gstbasesrc.c:3055:gst_base_src_loop:<udpsrc3> error: Internal data stream error. 0:00:04.018937057 3554 0x7f1cdc04e280 WARN basesrc gstbasesrc.c:3055:gst_base_src_loop:<udpsrc3> error: streaming stopped, reason not-linked (-1) ERROR: from element /GstPipeline:pipeline0/GstRTSPSrc:rtspsrc0/GstUDPSrc:udpsrc3: Internal data stream error. Additional debug info: gstbasesrc.c(3055): gst_base_src_loop (): /GstPipeline:pipeline0/GstRTSPSrc:rtspsrc0/GstUDPSrc:udpsrc3: streaming stopped, reason not-linked (-1) Execution ended after 0:00:01.908870388 Setting pipeline to PAUSED ... Setting pipeline to READY ... Setting pipeline to N
解决方案
问题根源
错误提示not-linked的核心原因:
- RTSP流同时包含视频和音频两路流,但原有命令仅处理视频流,音频流无对应处理分支,导致链路断裂
- 第一次尝试的命令中元素顺序错误(解码元件
avdec_h264需放在解封装rtph264depay和解析h264parse之后)
修正后的GStreamer命令
方式1:仅处理视频流,忽略音频流
通过命名rtspsrc并指定视频流分支,确保链路完整:
gst-launch-1.0 rtspsrc location=rtsp://ip:8554/mystream latency=0 name=src src. ! queue ! application/x-rtp,media=video,encoding-name=H264 ! rtph264depay ! h264parse ! avdec_h264 ! autovideoconvert ! autovideosink
方式2:同时处理视频和音频流
添加音频处理分支,两路流并行处理:
gst-launch-1.0 rtspsrc location=rtsp://ip:8554/mystream latency=0 name=src \ src. ! queue ! application/x-rtp,media=video,encoding-name=H264 ! rtph264depay ! h264parse ! avdec_h264 ! autovideoconvert ! autovideosink \ src. ! queue ! application/x-rtp,media=audio,encoding-name=MPA ! rtppcmadepay ! mpegaudioparse ! avdec_mp3 ! audioconvert ! autoaudiosink
FFmpeg推流命令优化(可选)
指定编码参数提升兼容性和稳定性:
ffmpeg -flush_packets 1 -re -stream_loop -1 -i sample.mp4 -c:v libx264 -preset ultrafast -tune zerolatency -c:a aac -f rtsp rtsp://ip:8554/mystream
内容的提问来源于stack exchange,提问作者khÜs h
相关产品推荐
相关产品推荐

