You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用GStreamer通过RTMP实现Azure Media Services稳定长期推流

解决Azure Media Services RTMP推流24/7稳定性问题

核心问题分析

你遇到的数小时后缓冲、404错误,大概率是推流未定期输出H.264元数据(SPS/PPS),加上RTMP连接超时、流分片丢失导致的。以下是针对性解决方案:

  • 修正关键帧与元数据输出
    把h264parse config-interval=-1改为config-interval=1,强制每1秒输出一次SPS/PPS。Azure Media Services需要定期获取这些元数据维持流解析,长时间缺失会导致客户端无法解码,触发缓冲和404错误。

  • 增强RTMP连接稳定性
    给rtmpsink添加两个参数:

    • timeout=0:禁用RTMP连接超时,避免长时间推流被自动断开
    • async=false:确保音视频流同步推流,防止累积延迟导致服务器丢弃分片
  • 应对6小时流周期问题

    1. 在Azure Media Services的Basic Pass-through直播事件配置中,启用连续直播模式,避免服务器自动断开流
    2. 写个简单监控脚本,一旦gst-launch进程退出,自动重启推流。示例:
      while true; do
          gst-launch-1.0 [你的完整推流命令]
          echo "推流中断,5秒后重启..."
          sleep 5
      done
      
  • 验证封装与编码兼容性
    确认flvmux streamable=true已开启(你的命令里已有),同时确保faac输出AAC LC profile(默认配置即可),避免服务器无法识别编码格式导致分片生成失败。

修改后的GStreamer推流命令

gst-launch-1.0 v4l2src device=/dev/video0 ! video/x-raw, width=640, height=480, format=BGR \                                                                                                 
    ! vspmfilter dmabuf-use=true ! video/x-raw, format=NV12 \                                                                                                                                
    ! omxh264enc control-rate=2 target-bitrate=10485760 ! video/x-h264,profile=high,level=4.2 \                                                                                              
    ! h264parse config-interval=1 \                                                                                                                                                         
    ! mux. audiotestsrc is-live=true wave=silence ! audio/x-raw,rate=48000 ! faac bitrate=96000 ! aacparse ! audio/mpeg,mpegversion=4 ! mux. flvmux streamable=true name=mux \               
    ! rtmpsink location="${dest} live=1 flashver=FMLE/3.0(compatibble;FMSc/1.0)" timeout=0 async=false

内容的提问来源于stack exchange,提问作者Matin Lotfaliee

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 08:03:18