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

使用FFmpeg拉取Meldana网络摄像机流时出现cur_dts is invalid错误

Meldana摄像机FFmpeg拉流报错问题排查与解决建议

问题描述

我使用以下FFmpeg命令拉取网络摄像机流,输出给转换器以MP4格式实现无转码HLS推流:

const command = [
        '-loglevel',
        'debug',
        '-timeout',
        '10000000',
        '-rtsp_transport',
        'tcp',
        '-i',
        this.cameraInfo.url,
        '-c:v',
        'copy',
        '-c:a',
        'aac',
        '-f',
        'mp4',
        '-movflags',
        '+faststart+frag_every_frame+empty_moov+default_base_moof',
        "-min_frag_duration",
        this.livestreamSegmentDuration,
        'pipe:1',
    ];

该命令在其他品牌摄像机上运行正常,但拉取Meldana全系列摄像机流时,持续抛出以下错误且无法推流:

cur_dts is invalid st:0 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
cur_dts is invalid st:1 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
cur_dts is invalid st:0 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
cur_dts is invalid st:1 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
cur_dts is invalid st:0 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
cur_dts is invalid st:1 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
cur_dts is invalid st:0 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
cur_dts is invalid st:1 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
cur_dts is invalid st:0 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
cur_dts is invalid st:1 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
cur_dts is invalid st:0 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
cur_dts is invalid st:1 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
cur_dts is invalid st:0 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
cur_dts is invalid st:1 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)

VLC可正常观看该摄像机流,但FFmpeg无法推流,请问问题出在哪?能否通过调整FFmpeg命令解决?


问题原因与解决建议

原因分析

报错提示cur_dts is invalid说明Meldana摄像机输出的RTSP流存在DTS(解码时间戳)不规范问题:要么DTS序列不连续,要么初始DTS值不符合FFmpeg的处理要求。VLC对不规范流的容错性远高于FFmpeg,所以能正常播放;但FFmpeg在做MP4分段封装时,对时间戳的一致性要求严格,持续的DTS错误会导致封装流程中断。

调整FFmpeg命令的解决方案

以下几种调整无需转码,可保留原有的无转码HLS传输需求:

  1. 强制重新生成时间戳
    添加-fflags +genpts参数,让FFmpeg忽略流中原有错误的时间戳,重新生成标准的PTS/DTS序列。修改后的命令:
const command = [
        '-loglevel',
        'debug',
        '-timeout',
        '10000000',
        '-rtsp_transport',
        'tcp',
        '-fflags',
        '+genpts', // 新增参数
        '-i',
        this.cameraInfo.url,
        '-c:v',
        'copy',
        '-c:a',
        'aac',
        '-f',
        'mp4',
        '-movflags',
        '+faststart+frag_every_frame+empty_moov+default_base_moof',
        "-min_frag_duration",
        this.livestreamSegmentDuration,
        'pipe:1',
    ];
  1. 排查音频流问题
    报错中st:1代表音频流,若问题源于音频时间戳异常,可先禁用音频流测试,添加-an参数:
const command = [
        '-loglevel',
        'debug',
        '-timeout',
        '10000000',
        '-rtsp_transport',
        'tcp',
        '-i',
        this.cameraInfo.url,
        '-c:v',
        'copy',
        '-an', // 禁用音频
        '-f',
        'mp4',
        '-movflags',
        '+faststart+frag_every_frame+empty_moov+default_base_moof',
        "-min_frag_duration",
        this.livestreamSegmentDuration,
        'pipe:1',
    ];

若禁用音频后恢复正常,可单独对音频流做同步处理,添加-af "aresample=async=1"强制重新同步音频时间戳。

  1. 增大RTSP缓冲
    添加-rtsp_buffer_size 1024000参数增大RTSP接收缓冲,减少流的不连续性:
const command = [
        '-loglevel',
        'debug',
        '-timeout',
        '10000000',
        '-rtsp_buffer_size',
        '1024000', // 新增缓冲参数
        '-rtsp_transport',
        'tcp',
        '-fflags',
        '+genpts',
        '-i',
        this.cameraInfo.url,
        '-c:v',
        'copy',
        '-c:a',
        'aac',
        '-f',
        'mp4',
        '-movflags',
        '+faststart+frag_every_frame+empty_moov+default_base_moof',
        "-min_frag_duration",
        this.livestreamSegmentDuration,
        'pipe:1',
    ];

总结

优先尝试添加-fflags +genpts,这是解决时间戳不规范问题最常用的方案。若无效,再逐步排查音频流或调整RTSP缓冲参数。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.16 06:35:16