Derek Halden
Derek Halden

Reputation: 2323

FFmpeg c++ how to get the timestamp, in seconds since epoch that a frame was taken at

I've been looking around for this, and Can't seem to find it. I have an RTSP stream that I am pulling from using ffmpeg. Objects at my disposal include an AVPacket, AVFrame, AVCodecContext, and an AVFormatContext . I would like to get the absolute time that a frame was taken at. (ideally with granularity as small as milliseconds, though that's not completely necessary).

Is there an easy way to do this using the ffmpeg libraries? I've looked at av_frame_get_best_effort_timestamp as well as codec_context->time_base, but that seems to give the answers in seconds since the beginning of the video, and I don't necessarily know when the video started.

Upvotes: 2

Views: 5555

Answers (1)

Rama
Rama

Reputation: 3305

Use int64_t AVFormatContext::start_time_realtime, and then add the frame time since the beginning of the stream.

[EDIT]

Also take into account that start_time_realtime is expressed in milliseconds, while AVFrame::best_effort_timestamp is expressed in AVStream->time_base units

Upvotes: 2

Related Questions