2

I am using libav/ffmpeg for connecting to IP cameras. I do need to extract the absolute timestamp from the frames, not pts/dts. How can I have this value?

Using Wireshark I can see the following response from the camera (Axis P1355):

RTP-Info: url=rtsp://xxx.dyndns.org:4378/axis-media/media.amp/trackID=1?fps=4&resolution=1280x720&compression=60;seq=32446;rtptime=3287715479\r\n

Didac Perez Parera
  • 3,734
  • 3
  • 52
  • 87
  • What have you tried so far? What have worked? What haven't worked? And you might want to read [the Stack Overflow question checklist](http://meta.stackexchange.com/questions/156810/stack-overflow-question-checklist) if you haven't done so. – Some programmer dude Nov 20 '13 at 11:46
  • 1
    I have not tried anything since I could not find any method for extracting timestamp. Nothing worked, so... – Didac Perez Parera Nov 20 '13 at 11:50
  • Will this help http://www.ffmpeg.org/doxygen/2.0/timestamp_8h.html#ad344b91ede6b86fc0a530611293f42da ? – Sergei Nikulov Nov 26 '13 at 14:52
  • 1
    Hi Sergey, thank you for your comment. May be useful but actually the problem is that I don't know how to retrieve that timestamp, the question is not about how do I parse/represent it. – Didac Perez Parera Nov 26 '13 at 14:59
  • What do you mean with "absolute timestamp"? RTP packages contain timestamps relative to previous sent package and RTCP SR and RR contains a 64 bit timestamp that indicates the wallclock time the report was sent (no hour:mins:sec) – jcm Nov 26 '13 at 21:05
  • It is related to the information I have written in my edited question? – Didac Perez Parera Nov 27 '13 at 09:09
  • 1
    @DídacPérez Is related to your initial question. I mean, what do you expect as "absolute timestamp", in best scenario, you'll be able to get a wallclock time but not a real time. – jcm Nov 27 '13 at 11:30

2 Answers2

6

The RTP packets only contain relative timestamps. The absolute timestamps are included in the sender report (SR) being part of RTCP.

Some incomplete implemented IP cameras don't send SR packets - then you are out of luck. I would give live555's testRTSPClient (http://www.live555.com/liveMedia/#testProgs) a try that gives you access to the absolute timestamp - if transmitted.

The "afterGettingFrame" function hands you an absolute timestamp and with RTPSource::hasBeenSynchronizedUsingRTCP you can verify it.

Markus Schumann
  • 7,636
  • 1
  • 21
  • 27
  • Hi, thank you for your answer. I will try testRTSPClient. However, my question is about retrieving that timestamp using ffmpeg lib, so I can't mark your answer as the correct one :( – Didac Perez Parera Nov 26 '13 at 09:01
  • This looks similar, may be it can help you http://stackoverflow.com/questions/6149983/h-264-rtsp-absolute-timestamp – Rahul Shukla Nov 27 '13 at 06:48
  • `testRTSPClient` is really a good test util for RTCP Sender Report, I've tested it. The source code is also helpful. – zhy May 12 '22 at 06:13
6

Finally I solved the problem.

I had to catch the RTSPState from the context, in order to get the RTSPStream array and get the video one, and after that get the RTPDemuxContext which contains the timestamp.

Didac Perez Parera
  • 3,734
  • 3
  • 52
  • 87
  • 5
    Can you post some snippets? – Arun Apr 09 '15 at 05:53
  • 2
    @Arun Starting with a reference to a AVFormatContext, do the following: `RTSPState *state = _formatCtx->priv_data;` `RTSPStream *stream = state->rtsp_streams[0];` `RTPDemuxContext *demux = stream->transport_priv;` `demux->timestamp` – Kyle Redfearn Feb 15 '17 at 20:10