我正在尝试通过 rtsp 获取帧并计算其真实世界的时间戳。我以前为此使用过 Live555(presentationTime)。
据我了解,ffmpeg 不提供这样的功能,但提供了读取每一帧的相对时间和流的开始时间的能力。在我的情况下,帧时间戳(pts)正常工作,但流开始时间(start_time_realtime)始终为 -9223372036854775808。
我正在尝试使用此 Q 中的简单示例:https ://stackoverflow.com/a/11054652/5355846
值不变。无论代码中的位置如何
int main(int argc, char** argv) {
// Open the initial context variables that are needed
SwsContext *img_convert_ctx;
AVFormatContext* format_ctx = avformat_alloc_context();
AVCodecContext* codec_ctx = NULL;
int video_stream_index;
// Register everything
av_register_all();
avformat_network_init();
//open RTSP
if (avformat_open_input(&format_ctx, "path_to_rtsp_stream",
NULL, NULL) != 0) {
return EXIT_FAILURE;
}
...
}
while (av_read_frame(format_ctx, &packet) >= 0 && cnt < 1000) { //read ~ 1000 frames
//// here!
std::cout<< " ***** "
<< std::to_string(format_ctx->start_time_realtime)
<< " | "<<format_ctx->start_time
<< " | "<<packet.pts
<< " | "
<<picture->best_effort_timestamp;
...
}
***** -9223372036854775808 | 0 | 4120 | 40801 车架:103
我究竟做错了什么?