[Live-devel] wrong timestamping for MPEG-4 ES

Bernhard Feiten Bernhard at Feiten.de
Mon Oct 31 14:33:34 PST 2005


Hi Ross, hi all,

for a MPEG-4 video stream, generated with ffmpeg,  we found out that the timestamps were not generated always correcctly. The timestamps are not increasing monoton. The video also showed flickering and short breaks.

Without having fully understood the parsing of the MPEG-4 stream, I found out that the problem disappeares when the variable fPrevNewTotalTicks is reseted when a new time code is parsed from the file. (see code below)

Perhaps somebody better understands the code and can verify that the change makes sense. 

Best regards,

Bernhard

------------------------------------------------------
MPEG4VideoStreamFramer.cpp
 
...
unsigned MPEG4VideoStreamParser::parseGroupOfVideoObjectPlane() {
#ifdef DEBUG
  fprintf(stderr, "parsing GroupOfVideoObjectPlane\n");
#endif
  // Note that we've already read the GROUP_VOP_START_CODE
  save4Bytes(GROUP_VOP_START_CODE);

  // Next, extract the (18-bit) time code from the next 3 bytes:
  u_int8_t next3Bytes[3];
  getBytes(next3Bytes, 3);
  saveByte(next3Bytes[0]);saveByte(next3Bytes[1]);saveByte(next3Bytes[2]);
  unsigned time_code
    = (next3Bytes[0]<<10)|(next3Bytes[1]<<2)|(next3Bytes[2]>>6);
  unsigned time_code_hours    = (time_code&0x0003E000)>>13;
  unsigned time_code_minutes  = (time_code&0x00001F80)>>7;
#if defined(DEBUG) || defined(DEBUG_TIMESTAMPS)
  Boolean marker_bit          = (time_code&0x00000040) != 0;
#endif
  unsigned time_code_seconds  = (time_code&0x0000003F);
#if defined(DEBUG) || defined(DEBUG_TIMESTAMPS)
  fprintf(stderr, "time_code: 0x%05x, hours %d, minutes %d, marker_bit %d, seconds %d\n", time_code, time_code_hours, time_code_minutes, marker_bit, time_code_seconds);
#endif

  // Now, copy all bytes that we see, up until we reach a VOP_START_CODE:
  u_int32_t next4Bytes = get4Bytes();
  while (next4Bytes != VOP_START_CODE) {
    saveToNextCode(next4Bytes);
  }

  // Compute this frame's presentation time:
  usingSource()->computePresentationTime(fTotalTicksSinceLastTimeCode);

  // Record the time code:
  usingSource()->setTimeCode(time_code_hours, time_code_minutes,
                             time_code_seconds, 0, 0);
    // Note: Because the GOV header can appear anywhere (not just at a 1s point), we
    // don't pass "fTotalTicksSinceLastTimeCode" as the "picturesSinceLastGOP" parameter.
  fSecondsSinceLastTimeCode = 0;

  fPrevNewTotalTicks = 0;    //>>>>>>>>>>>>> bf 051031, try to eliminate some errors with wrong time stamps

  if (fixed_vop_rate) fTotalTicksSinceLastTimeCode = 0;

  setParseState(PARSING_VIDEO_OBJECT_PLANE);

  return curFrameSize();
}
...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.live555.com/pipermail/live-devel/attachments/20051031/4b5cf459/attachment.html


More information about the live-devel mailing list