Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

duration calculated from segmentIndex mismatches whats available in periodInfo #187

Closed
priyajeet opened this issue Sep 21, 2015 · 1 comment
Labels
status: archived Archived and locked; will not be updated type: bug Something isn't working correctly
Milestone

Comments

@priyajeet
Copy link

I have the following MPD

<MPD mediaPresentationDuration="PT1M3.7S" minBufferTime="PT10.0S" type="static" profiles="urn:mpeg:dash:profile:isoff-live:2011" xsi:schemaLocation="urn:mpeg:DASH:schema:MPD:2011 http://standards.iso.org/ittf/PubliclyAvailableStandards/MPEG-DASH_schema_files/DASH-MPD.xsd" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="urn:mpeg:dash:schema:mpd:2011" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <Period start="PT0.0S">
        <AdaptationSet maxFrameRate="24" bitstreamSwitching="true" segmentAlignment="true" contentType="video">
            <Representation height="800" width="1920" bandwidth="8000000" codecs="avc1.640028" mimeType="video/mp4" id="0">
                <SegmentTemplate startNumber="2" initialization="dash_1080.1.m4s" media="dash_1080.$Number$.m4s" duration="5000000" timescale="1000000"></SegmentTemplate>
            </Representation>
            <Representation height="354" width="854" bandwidth="2000000" codecs="avc1.42c01e" mimeType="video/mp4" id="1">
                <SegmentTemplate startNumber="2" initialization="dash_480.1.m4s" media="dash_480.$Number$.m4s" duration="5000000" timescale="1000000"></SegmentTemplate>
            </Representation>
        </AdaptationSet>
        <AdaptationSet bitstreamSwitching="true" segmentAlignment="true" contentType="audio">
            <Representation audioSamplingRate="44100" bandwidth="128290" codecs="mp4a.40.2" mimeType="audio/mp4" id="2">
                <AudioChannelConfiguration value="2" schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011"/>
                <SegmentTemplate startNumber="2" initialization="dash_audio.1.m4s" media="dash_audio.$Number$.m4s" duration="5000000" timescale="1000000"></SegmentTemplate>
            </Representation>
        </AdaptationSet>
    </Period>
</MPD>

The <MPD> tag has the mediaPresentationDuration="PT1M3.7S" signifying the video is ~63 seconds. However when loading the video, it reports the duration as ~65 seconds which it is calculating by

  for (var i = 0; i < segmentIndexes.length; ++i) {
    var seekRange = segmentIndexes[i].getSeekRange();
    startTime = Math.max(startTime, seekRange.start);
    if (seekRange.end != null) {
      endTime = Math.min(endTime, seekRange.end);
    }
  }

inside shaka.player.StreamVideoSource.prototype.computeStreamLimits_

As there are 13 available segments, it multiplies by 5s per segment, giving a total of 65s.
The last segment is however not a full 5s segment, so when the playback ends, it throws a warning from the else clause of shaka.player.StreamVideoSource.prototype.setUpMediaSource_

If I now add duration="PT1M3.7S" to the <Period> tag in the MPD, it still has the same issue, since fetching duration from the periodInfo happens after calculating it from the segmentIndex inside shaka.player.StreamVideoSource.prototype.computeStreamLimits_ and is protected by a endTime == Number.POSITIVE_INFINITY check.

if (endTime == Number.POSITIVE_INFINITY) {
    // TODO(story 1890046): Support multiple periods.
    var period = this.manifestInfo.periodInfos[0];
    if (period.duration) {
      endTime = (period.start || 0) + period.duration;
    } else {
      shaka.log.debug('Failed to compute a stream end time.');
      return null;
    }
  }

Questions:

  1. Is the MPD I have seem / look correct? Or is it lacking information that is messing with the player calculations?
  2. shaka-player is using mediaPresentationDuration="PT1M3.7S" to figure out the number of segments = var numSegments = Math.ceil(this.period_.duration / scaledSegmentDuration); = 1M3.7S / 5S = 13. However if it is doing that, shouldn't it know that the 13th segment is only seekable to 3.7s and not the total 5s? And why is this duration not being used as opposed to recalculating it again by iterating over all the segments?
  3. Why is segmentIndex seekable ranges given preference over period duration?
  4. Why is there not a fallback to just use mediaPresentationDuration="PT1M3.7S" as the duration incase its not available on the <Period> tag?

Thanks!

@tdrews
Copy link
Contributor

tdrews commented Sep 21, 2015

Thanks for the report.

There is a bug in the player, see #173.

  1. Your MPD looks correct.
  2. Yes, this is the bug: the last segment should not extend past the Period's duration.
  3. We use the SegmentIndexes to compute the seek range (instead of the Period's duration directly) because each stream may have slightly different start/end times than what @mediaPresentationDuration or the Period's duration indicates (e.g., @mediaPresentationDuration may be 2 minutes but a particular Representation may have a SegmentTImeline that indicates that it ends at 1:59). Moreover, the actual timestamps in the media segments may induce slightly different start/end times (i.e., when there is a timestamp correction). Also, for live content, the seek range moves.
  4. The Period's duration does fallback to @mediaPresentationDuration (see https://github.com/google/shaka-player/blob/26bfade2dff58132937af0f9168de8f73c0d7220/lib/dash/mpd_processor.js#L152).

@tdrews tdrews added the type: bug Something isn't working correctly label Sep 21, 2015
@tdrews tdrews added this to the v1.6.0 milestone Sep 21, 2015
@tdrews tdrews self-assigned this Sep 22, 2015
@tdrews tdrews closed this as completed in 9dcbda7 Sep 25, 2015
tdrews pushed a commit that referenced this issue Oct 7, 2015
For static content that uses SegmentTemplate + @duration, compress
the last SegmentReference so that it does not go beyond the
Period's duration.

Issue #173
Closes #187

Change-Id: Ifb9404ddfe267915541c035a5d6286f63f7bc032
@shaka-project shaka-project locked and limited conversation to collaborators Mar 22, 2018
@shaka-bot shaka-bot added the status: archived Archived and locked; will not be updated label Apr 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: archived Archived and locked; will not be updated type: bug Something isn't working correctly
Projects
None yet
Development

No branches or pull requests

4 participants