简体   繁体   中英

ffmpeg RTSP over TCP, RTP timestamps are always zero

I'm trying to get timestamps from RTP packet. When I scan packets with Wireshark I get following output: rtp_packet I see that timestamps have incremented after several packets. Issue that I have as following: when I read timestamp value from RTPDemuxContext->timestamp (rtp_demux_context->timestamp) in C, the value is always zero for several cameras, but for the majority of cameras the code works well. Can you help to figure out is there are bug in cameras or bug in ffmpeg?

There is my code:

double ntp_timestamp(AVFormatContext* pFormatCtx, uint32_t* last_rtcp_ts, double* base_time) {
RTSPState* rtsp_state = (RTSPState*) pFormatCtx->priv_data;
RTSPStream* rtsp_stream = rtsp_state->rtsp_streams[0];
RTPDemuxContext* rtp_demux_context = (RTPDemuxContext*) rtsp_stream->transport_priv;

uint32_t new_rtcp_ts = rtp_demux_context->last_rtcp_timestamp;

uint64_t last_ntp_time = 0;

if (new_rtcp_ts != *last_rtcp_ts) {
    *last_rtcp_ts = new_rtcp_ts;
    last_ntp_time = rtp_demux_context->last_rtcp_ntp_time;
    uint32_t seconds = ((last_ntp_time >> 32) & 0xffffffff) - 2208988800;
    uint32_t fraction  = (last_ntp_time & 0xffffffff);
    double useconds = ((double) fraction / 0xffffffff);
    *base_time = seconds + useconds;
}
uint32_t d_ts = rtp_demux_context->timestamp - *last_rtcp_ts;
return *base_time + d_ts / 90000.0;

}

could it be because you subtracted 2208988800 from the RTP timestamp seconds ? I suspect this may be the cause. I was in a similar situation but found out that the timestamp starts incrementing after the camera is turned on.

May be the rtsp server don't send any rtcp sender report. you can check if server send rtcp sender report by wireshake.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM