【发布时间】:2013-12-14 10:58:12
【问题描述】:
我正在使用 ffmpeg C 库。我需要拦截来自摄像头的 RTCP 数据包,以便从发件人报告中获取时间戳。 ffmpeg 中是否有任何方法或结构可以为我提供此信息?我完全被卡住了,但我无法解决这个问题。
任何帮助将不胜感激。提前致谢,
【问题讨论】:
我正在使用 ffmpeg C 库。我需要拦截来自摄像头的 RTCP 数据包,以便从发件人报告中获取时间戳。 ffmpeg 中是否有任何方法或结构可以为我提供此信息?我完全被卡住了,但我无法解决这个问题。
任何帮助将不胜感激。提前致谢,
【问题讨论】:
我在ffmpeg(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
然后,在ntp时间上加上相对时间,就可以得到每一帧的绝对时间
streamStartTime + (1000000 * pkt->pts * time_base) // AVPacket * pkt
【讨论】:
最后我不得不像这样侵入 ffmpeg 库:
// 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);
我终于得到了时间戳信息。
【讨论】: