Reputation: 3834
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,
Upvotes: 5
Views: 5316
Reputation: 739
For anyone looking to extract this from FFmpeg=4.4.2, here is a nifty patch that I made: https://github.com/necla-ml/feedstocks/blob/main/recipes/ffmpeg/patches/rtp_ntp_timestamp_4.4.2.patch
This will add few new attributes to the AVPacket
uint32_t timestamp;
uint64_t last_rtcp_ntp_time;
uint32_t last_rtcp_timestamp;
uint16_t seq;
bool synced;
You can also just install fffmpeg from our conda channel: mamba install -c necla-ml ffmpeg=4.4.2=*ntp*
and use https://github.com/LukasBommes/mv-extractor which does the job of calculating the absolute ntp timestamp while maintaining opencv like interface.
Upvotes: 1
Reputation: 70
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
Upvotes: 0
Reputation: 3834
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.
Upvotes: 8