http-streaming icon indicating copy to clipboard operation
http-streaming copied to clipboard

Out of sync audio with video in fmp4 with different timestampOffset (possible fix)

Open Llorito opened this issue 7 years ago • 1 comments

When we have a hls with a separate video channel and an audio channel, if they have different segments timestamp offset value (it is possible), it does not play correctly. Both are out of sync.

I have found the error and fixed it in sync-controller class.

probeMp4Segment_(segmentInfo) {
    let segment = segmentInfo.segment;
    let timescales = mp4probe.timescale(segment.map.bytes);
    let startTime = mp4probe.startTime(timescales, segmentInfo.bytes);

    if (segmentInfo.timestampOffset !== null) {
      segmentInfo.timestampOffset -= startTime;

      if (segment.map.videoTrackIds.length > 0) {
        //It is Video segment
        this.syncOffset = segmentInfo.timestampOffset;
      } else {
        //It isn't Video segment
        if (segmentInfo.timestampOffset !== this.syncOffset) segmentInfo.timestampOffset = this.syncOffset;
      }
    }

    return {
      start: startTime,
      end: startTime + segment.duration
    };
  }

Llorito avatar Feb 27 '19 18:02 Llorito

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 28 '19 18:04 stale[bot]