[Live-devel] How to set H264 and aac live frame timestamp ?

gongfen at vgaic.com gongfen at vgaic.com
Mon Sep 15 22:54:27 PDT 2014


Dear Sir,

How to set H264 and aac live frame timestamp ?
I use live555 to do rtsp server from my h264/aac live stream.
First, I know every frame about timestamp and frame len from two linux fifo.
And I use ByteStreamFileSource.cpp and ADTSAudioFileSource.cpp to get the frame data.

For h264/aac sync, I use testProgs/testOnDemandRTSPServer.cpp to do:

ServerMediaSession* sms 
= ServerMediaSession::createNew(*env, streamName, streamName, 
descriptionString);
sms->addSubsession(H264VideoFileServerMediaSubsession 
::createNew(*env, inputFileName, reuseFirstSource));
sms->addSubsession(ADTSAudioFileServerMediaSubsession 
::createNew(*env, inputFileName3, reuseFirstSource));

Everything is good, but I use vlc to play only 30 minutes, then it's broken.
The vlc debug message is:
avcodec error: more than 5 seconds of late video -> dropping frame (computer too slow ?)
main warning: picture is too late to be displayed (missing 656606 ms)
main warning: picture is too late to be displayed (missing 656602 ms)
main warning: picture is too late to be displayed (missing 656598 ms)
main warning: picture is too late to be displayed (missing 656262 ms)
main warning: picture is too late to be displayed (missing 656298 ms)

I found that the timestamp code in ByteStreamFileSource.cpp is this:

// Set the 'presentation time': 
if (fPlayTimePerFrame > 0 && fPreferredFrameSize > 0) { 
if (fPresentationTime.tv_sec == 0 && fPresentationTime.tv_usec == 0) { 
// This is the first frame, so use the current time: 
gettimeofday(&fPresentationTime, NULL); 
} else { 
// Increment by the play time of the previous data: 
unsigned uSeconds = fPresentationTime.tv_usec + fLastPlayTime; 
fPresentationTime.tv_sec += uSeconds/1000000; 
fPresentationTime.tv_usec = uSeconds%1000000; 
} 

// Remember the play time of this data: 
fLastPlayTime = (fPlayTimePerFrame*fFrameSize)/fPreferredFrameSize; 
fDurationInMicroseconds = fLastPlayTime; 
} else { 
// We don't know a specific play time duration for this data, 
// so just record the current time as being the 'presentation time': 
gettimeofday(&fPresentationTime, NULL); 
}

And I check the timestamp in liveMedia/H264VideoStreamFramer.cpp, the true timestamp is this: 

// Note that the presentation time for the next NAL unit will be different: 
struct timeval& nextPT = usingSource()->fNextPresentationTime; // alias 
nextPT = usingSource()->fPresentationTime; 
double nextFraction = nextPT.tv_usec/1000000.0 + 1/usingSource()->fFrameRate; 
unsigned nextSecsIncrement = (long)nextFraction; 
nextPT.tv_sec += (long)nextSecsIncrement; 
nextPT.tv_usec = (long)((nextFraction - nextSecsIncrement)*1000000);

It's use framerate to get timestamp. 
So, if I set the ture video timestamp "nextPT.tv_sec and nextPT.tv_usec".

There is anything that I missing ? I found that if I change this, the same problem.





-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.live555.com/pipermail/live-devel/attachments/20140916/0acfa007/attachment.html>


More information about the live-devel mailing list