I'm trying to get a frame by rtsp and calculate its real-world timestamp. I previously used Live555 for this (presentationTime).
As far as I understand, ffmpeg does not provide such functionality, but provides the ability to read the relative time of each frame and the start time of the stream. In my case, the frame timestamps (pts) works correctly, but the stream start time (start_time_realtime) is always -9223372036854775808.
I'm trying to use simple example from this Q: https://stackoverflow.com/a/11054652/5355846
Value does not change. regardless of the position in the code
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 Frame: 103
What am I doing wrong?