<html><head><meta http-equiv="content-type" content="text/html; charset=GB2312"><style>body { line-height: 1.5; }body { font-size: 10.5pt; font-family: ËÎÌå; color: rgb(0, 0, 0); line-height: 1.5; }</style></head><body>
<div><span></span>Dear Sir,</div><div><br></div><div><span style="background-color: rgba(0, 0, 0, 0);">How to set H264 and aac live frame timestamp ?</span></div><div>I use live555 to do rtsp server from my h264/aac live stream.</div><div>First, I know every frame about timestamp and frame len from two linux fifo.</div><div>And I use ByteStreamFileSource.cpp and <span style="background-color: rgba(0, 0, 0, 0); font-size: 10.5pt; line-height: 1.5;">ADTSAudioFileSource.cpp to get the frame data.</span></div><div><span style="background-color: rgba(0, 0, 0, 0); font-size: 10.5pt; line-height: 1.5;"><br></span></div><div><span style="background-color: rgba(0, 0, 0, 0); font-size: 10.5pt; line-height: 1.5;">For h264/aac sync, I use </span><span style="background-color: rgba(0, 0, 0, 0); font-size: 10.5pt; line-height: 1.5;">testProgs/testOnDemandRTSPServer.cpp to do:</span></div><div><span style="background-color: rgba(0, 0, 0, 0); font-size: 10.5pt; line-height: 1.5;"><br></span></div><div><span style="background-color: rgba(0, 0, 0, 0); font-size: 10.5pt; line-height: 1.5;">ServerMediaSession* sms </span></div><div><span style="background-color: rgba(0, 0, 0, 0);">      = ServerMediaSession::createNew(*env, streamName, streamName,
<br>                      descriptionString);</span></div><div><span style="background-color: rgba(0, 0, 0, 0); font-size: 10.5pt; line-height: 1.5;">sms->addSubsession(H264VideoFileServerMediaSubsession </span></div><div><span style="background-color: rgba(0, 0, 0, 0);">                    ::createNew(*env, inputFileName, reuseFirstSource));</span></div><div><span style="background-color: rgba(0, 0, 0, 0); font-size: 10.5pt; line-height: 1.5;">sms->addSubsession(ADTSAudioFileServerMediaSubsession </span></div><div><span style="background-color: rgba(0, 0, 0, 0);">                                    ::createNew(*env, inputFileName3, reuseFirstSource));</span></div><div><span style="background-color: rgba(0, 0, 0, 0);"><br></span></div><div><span style="background-color: rgba(0, 0, 0, 0);">Everything is good, but I use vlc to play only 30 </span><span style="background-color: rgba(0, 0, 0, 0); font-size: 10.5pt; line-height: 1.5;">minutes£¬ then it's broken.</span></div><div><span style="background-color: rgba(0, 0, 0, 0); font-size: 10.5pt; line-height: 1.5;">The vlc debug message is:</span></div><div><p style="margin: 0px;"><i><span style="color: rgb(0, 0, 139);">avcodec</span><span style="color: rgb(255, 0, 0);"> error: </span>more than 5 seconds of late video -> dropping frame (computer too slow ?)</i></p>
<p style="margin: 0px;"><i><span style="color: rgb(0, 0, 139);">main</span><span style="color: rgb(0, 128, 0);"> warning: </span>picture is too late to be displayed (missing 656606 ms)</i></p>
<p style="margin: 0px;"><i><span style="color: rgb(0, 0, 139);">main</span><span style="color: rgb(0, 128, 0);"> warning: </span>picture is too late to be displayed (missing 656602 ms)</i></p>
<p style="margin: 0px;"><i><span style="color: rgb(0, 0, 139);">main</span><span style="color: rgb(0, 128, 0);"> warning: </span>picture is too late to be displayed (missing 656598 ms)</i></p>
<p style="margin: 0px;"><i><span style="color: rgb(0, 0, 139);">main</span><span style="color: rgb(0, 128, 0);"> warning: </span>picture is too late to be displayed (missing 656262 ms)</i></p>
<p style="margin: 0px;"><i><span style="color: rgb(0, 0, 139);">main</span><span style="color: rgb(0, 128, 0);"> warning: </span>picture is too late to be displayed (missing 656298 ms)</i></p><p style="margin: 0px;"><i><br></i></p><p style="margin: 0px;">I found that the timestamp code in <span style="font-size: 10.5pt; line-height: 1.5; background-color: window;">ByteStreamFileSource.cpp is this:</span></p><p style="margin: 0px;"><span style="font-size: 10.5pt; line-height: 1.5; background-color: window;"><br></span></p><p style="margin: 0px;"><i>// Set the 'presentation time':
<br>  if (fPlayTimePerFrame > 0 && fPreferredFrameSize > 0) {
<br>    if (fPresentationTime.tv_sec == 0 && fPresentationTime.tv_usec == 0) {
<br>      // This is the first frame, so use the current time:
<br>      gettimeofday(&fPresentationTime, NULL);
<br>    } else {
<br>      // Increment by the play time of the previous data:
<br>      unsigned uSeconds = fPresentationTime.tv_usec + fLastPlayTime;
<br>      fPresentationTime.tv_sec += uSeconds/1000000;
<br>      fPresentationTime.tv_usec = uSeconds%1000000;
<br>    }
<br>
<br>    // Remember the play time of this data:
<br>    fLastPlayTime = (fPlayTimePerFrame*fFrameSize)/fPreferredFrameSize;
<br>    fDurationInMicroseconds = fLastPlayTime;
<br>  } else {
<br>    // We don't know a specific play time duration for this data,
<br>    // so just record the current time as being the 'presentation time':
<br>    gettimeofday(&fPresentationTime, NULL);
<br>  }</i></p><p style="margin: 0px;"><br></p><p style="margin: 0px;">And I check the timestamp in <span style="background-color: rgba(0, 0, 0, 0); font-size: 10.5pt; line-height: 1.5;">liveMedia/H264VideoStreamFramer.cpp, the true timestamp is this: </span></p><p style="margin: 0px;"><span style="background-color: rgba(0, 0, 0, 0); font-size: 10.5pt; line-height: 1.5;"><br></span></p><p style="margin: 0px;"><span style="background-color: rgba(0, 0, 0, 0);"><i>// Note that the presentation time for the next NAL unit will be different:
<br>      struct timeval& nextPT = usingSource()->fNextPresentationTime; // alias
<br>      nextPT = usingSource()->fPresentationTime;
<br>      double nextFraction = nextPT.tv_usec/1000000.0 + 1/usingSource()->fFrameRate;
<br>      unsigned nextSecsIncrement = (long)nextFraction;
<br>      nextPT.tv_sec += (long)nextSecsIncrement;
<br>      nextPT.tv_usec = (long)((nextFraction - nextSecsIncrement)*1000000);</i></span></p><p style="margin: 0px;"><span style="background-color: rgba(0, 0, 0, 0);"><i><br></i></span></p><p style="margin: 0px;">It's use framerate to get timestamp. </p><p style="margin: 0px;">So, if I set the ture video timestamp "<span style="font-size: 10.5pt; line-height: 1.5; background-color: window;">nextPT.tv_sec and </span><span style="font-size: 10.5pt; line-height: 1.5; background-color: window;">nextPT.tv_usec".</span></p><p style="margin: 0px;"><br></p><p style="margin: 0px;">There is anything that I missing ? I found that if I change this, the same problem.</p><p style="margin: 0px;"><i><br></i></p><p style="margin: 0px;"><span style="font-size: 10.5pt; line-height: 1.5; background-color: window;"><br></span></p><p style="margin: 0px;"><span style="font-size: 10.5pt; line-height: 1.5; background-color: window;"><br></span></p><p style="margin: 0px;"><i><br></i></p></div><div><span style="background-color: rgba(0, 0, 0, 0); font-size: 10.5pt; line-height: 1.5;"><br></span></div><div><span>
</span></div>
</body></html>