Skip to content

stream.dash: failed to create accurate current segment $number$ #4607

@BluchipStudio

Description

@BluchipStudio

Checklist

Streamlink version

Latest stable release

Description

I am trying to play a Dash stream from "New York". Said stream has segment caching in place they store all segments on there server for 24 hours in order to run the same stream for different time zones.

MPD structure

<MPD xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:mpeg:dash:schema:mpd:2011" xmlns:cenc="urn:mpeg:cenc:2013" xsi:schemaLocation="urn:mpeg:dash:schema:mpd:2011 http://standards.iso.org/ittf/PubliclyAvailableStandards/MPEG-DASH_schema_files/DASH-MPD.xsd" profiles="urn:mpeg:dash:profile:isoff-live:2011,urn:com:dashif:dash264" maxSegmentDuration="PT2.048000S" minBufferTime="PT2.048000S" publishTime="2022-06-17T20:00:00Z" type="dynamic" minimumUpdatePeriod="PT2.048000S" availabilityStartTime="2022-06-17T20:00:15Z" mediaPresentationDuration="PT1800.000000S" suggestedPresentationDelay="PT4.096000S">
  <Period id="1" duration="PT1800.000000S" start="PT0.000000S">
    <BaseURL>/158/live/55941/</BaseURL>
    <AdaptationSet contentType="audio" mimeType="audio/mp4" segmentAlignment="true" startWithSAP="1" codecs="mp4a.40.2" lang="en">
      <SegmentTemplate timescale="1000" duration="2048" startNumber="18926" media="audio/$RepresentationID$/$Number%08d$.m4s" presentationTimeOffset="38760243"/>
      <AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="2"/>
      <Role schemeIdUri="urn:mpeg:dash:role:2011" value="main"/>
      <Representation id="192a158" audioSamplingRate="48000" bandwidth="196608" qualityRanking="0"/>
    </AdaptationSet>
    <AdaptationSet contentType="video" mimeType="video/mp4" segmentAlignment="true" startWithSAP="1">
      <Accessibility schemeIdUri="urn:scte:dash:cc:cea-608:2015" value="CC1=eng"/>
      <Accessibility schemeIdUri="urn:scte:dash:cc:cea-708:2015" value="1=lang:eng"/>
      <SegmentTemplate timescale="1000" duration="2048" startNumber="18926" media="video/$RepresentationID$/$Number%08d$.m4s" presentationTimeOffset="38760243"/>
      <Role schemeIdUri="urn:mpeg:dash:role:2011" value="main"/>
      <Representation id="1080v158" bandwidth="5632000" codecs="avc1.640028" width="1920" height="1080" frameRate="29970/1000" sar="1:1" qualityRanking="0"/>
    </AdaptationSet>
  </Period>
</MPD>

Things to note about this Dash stream is that it is a dynamic live stream that uses the "Number" segment names template and provide a "startNumber" of the current live segment for the manifest.

When i tried to play this stream in "Streamlink" i noticed that the stream was not correct and did not match up with the live stream from there platform. I then tried to play the stream using the "VLC" media player and it plays the correct stream matching up with the platform stream in fact "VLC" was about 10 seconds ahead of the platform stream.

This lead me to believe that the issue with "Streamlink" when debugging the issue there is not much error information provided because the stream still plays with no issues it just plays from cached segment
and not live. To debug and compare both i enabled http/https loggin on my system and checked what segment urls where being called.

Both "VLC" and "Streamlink" where playing the correct base url and stuff but the difference i noticed was that "VLC" was using a segment number higher than the "startNumber" specified in the manifest as it should but "Streamlink" seemed to start streaming from "0" segment number and then going up by one seemingly completely ignoring the "startNumber" specified in the manifest. At the time of creating this Bug report the manifest specified "startNumber" was set to "22442" but stream link was currently trying to play segment number "26".

Debug log

Debug log contains no use full information other than stream playing as it does play fine just the wrong segment number.

18/06/2022 Update

This is a screen shot of the streamlink stream and the default mpd link both playing on vlc at the same time

Untitled-1

I have done my own calculations in PHP my normal working language and managed to create the correct output from the information provided by the mpd

Sorrty the image below has a small mistake where i forgot to enter the proper manifest delay from the mpd of 4.096 but even with this small error the php code still returns a current segment number a lot closer to the proper number than streamlink is doing on playback.

2

19/08/2022 Update

After looking over the code in the MPD manifest as well as the code in "dash_manifest.py" from "streamlink" i can see the error comes from the fact the manifest contains "presentationTimeOffset" where the value is higher than the current segment number so on line 485 of "dash_manifest.py" where it checks for "presentationTimeOffset" it runs the calculations based on this thus we end up with a 0000 value from the calculations because the number is higher than the current segment number value.

I do not know why this number is higher than the current number value i can only guess as to it being used for timezone or playback functions with the custom player platform used by the service.

To get around this i have made some edits to the code in "dash_manifest.py" to check and make sure that it does not lead to a negative/null value when calculating and if it does to skip to the calculations with out the usage of "presentationTimeOffset" and this has now fixed my issue and "streamlink" is now providing the correct numbers for the current playback

To mitigate this issue with possible other services in the future it may be a good option to possibly allow the passing of a arg to ignore the usage of "presentationTimeOffset" when passing a dash source url this way "streamlink" does not need to mess with its current calculations but rather only check for an extra arg and skip said section and use the calculation code with out it.

End Notes

First of all i would like to that the developers for the amazing software that is "streamlink" it works amazing and allows me to have perfect streaming all over my house on every devices with out needing loads of complicated software and apps.

Second i would like to apologise for any spelling / grammar mistakes in my bug report aka this post i do have dyslexia and i try my best to correct mistakes when i see the red line but it does take for every to go back and forth to google to find the correct spelling so sometimes i skip doing it so am sorry!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions