[英]Reading RTCP packets from an IP camera using FFMPEG
我正在使用 ffmpeg C 庫。 我需要攔截來自攝像頭的 RTCP 數據包,以便從發件人報告中獲取時間戳。 ffmpeg 中是否有任何方法或結構可以提供此信息? 我完全被卡住了,但我無法解決這個問題。
任何幫助將不勝感激。 提前致謝,
最后我不得不像這樣入侵 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);
我終於得到了時間戳信息。
我在 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=4.4.1 中提取此內容的任何人,這是我制作的一個漂亮補丁: https://github.com/necla-ml/feedstocks/blob/main/recipes/ffmpeg/patches/add_rtp_ntp_timestamp_4.4.1。修補
這將為 AVPacket 添加一些新屬性
uint32_t timestamp;
uint64_t last_rtcp_ntp_time;
uint32_t last_rtcp_timestamp;
uint16_t seq;
bool synced;
您也可以從我們的 conda 頻道安裝 fffmpeg: mamba install -c necla-ml ffmpeg=4.4.1=*ntp*
並使用https://github.com/LukasBommes/mv-extractor完成計算絕對值的工作ntp 時間戳,同時保持 opencv 之類的接口。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.