Question

I am using the ffmpeg C library. I need to intercept RTCP packets from the camera in order to get the timestamp from the Sender Report. Is there any method or structure in the ffmpeg that gives me this information? I am completely stuck but I am not able to solve that problem.

Any help will be appreciated. Thanks in advance,

Was it helpful?

Solution

Finally I had to hack into the ffmpeg library like this:

// Patch for retrieving inner ffmpeg private data
RTSPState* rtsp_state = (RTSPState*) context->priv_data;
RTSPStream* rtsp_stream = rtsp_state->rtsp_streams[0];
RTPDemuxContext* rtp_demux_context = (RTPDemuxContext*) rtsp_stream->transport_priv;

// Decode the NTP time from the 64 bit structure
uint64_t ntp_time = rtp_demux_context->last_rtcp_reception_time;
uint32_t seconds = (uint32_t) ((ntp_time >> 32) & 0xffffffff);
uint32_t fraction  = (uint32_t) (ntp_time & 0xffffffff);
double useconds = ((double) fraction / 0xffffffff);

And I finally get timestamp information.

OTHER TIPS

I have done some experiments on the ffmpeg (version 3.4.6).

AVFormatContext* ifmt_ctx = avformat_alloc_context();
AVStream * st = xx; // select stream
double timebase = av_q2d(st->time_base);
streamStartTime  = ifmt_ctx->start_time_realtime; // this is ntp time , i.e. stream build time 

then, add relative time to ntp time ,you can get the absolute time of each frame

streamStartTime + (1000000 * pkt->pts * time_base) // AVPacket * pkt
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top