Dash-Industry-Forum / dash.js

A reference client implementation for the playback of MPEG DASH via Javascript and compliant browsers.
http://reference.dashif.org/dash.js/nightly/samples/dash-if-reference-player/index.html
Other
5.13k stars 1.68k forks source link

Dash.js fetches non-existent .m4s files when setting time using player.seek(timeInSeconds) and results in errors. #4523

Closed YadneshD closed 3 months ago

YadneshD commented 3 months ago
Environment
Steps to reproduce
  1. Set time using player.seek
        // Function to seek to a specific time (in seconds)
        function seekToTime(timeInSeconds) {
            player.seek(timeInSeconds);
        }

        // Example: Seek to 60 seconds (1 minute) after video is loaded
        player.on(dashjs.MediaPlayer.events.STREAM_INITIALIZED, function() {
            seekToTime(60); // Seek to 60 seconds
        });
Observed behavior

The player keeps buffering.

Console output
XHRLoader.js:102 - GET http://localhost:5000/videos/m4d/video_dash33.m4s 404 (NOT FOUND)
XHRLoader.js:102 - GET http://localhost:5000/videos/m4d/video_dash34.m4s 404 (NOT FOUND)
XHRLoader.js:102 - GET http://localhost:5000/videos/m4d/video_dash35.m4s 404 (NOT FOUND)
Expected behavior

Basically I need to start playing my .mpd file from a given duration using dash.js I am able to play my .mpd file properly from start to end using dash.js in browser. But when I want to play it from a specific duration specified in secs, it requests for few non-existent .m4s files and results in 404 error from server. I have few .m4s files but the player requests non-existent .m4s files of higher segments which leads the server to throw 404 error. I am mentioning the code again for reference though I have already added it in Steps to reproduce section.

        // Function to seek to a specific time (in seconds)
        function seekToTime(timeInSeconds) {
            player.seek(timeInSeconds);
        }

        // Example: Seek to 60 seconds (1 minute) after video is loaded
        player.on(dashjs.MediaPlayer.events.STREAM_INITIALIZED, function() {
            seekToTime(60); // Seek to 60 seconds
        });

My video is of 4 minutes and setting it to 50 secs or more results in errors.

dsilhavy commented 3 months ago

The timing in the MPD is probably not correct. When you play the content from the beginning, dash.js fetches the segments one after another. When you seek, the player needs to calculate the right segment based on the timing information in the MPD. If the timing is not correct, it will fetch the wrong segments and the target buffer position is never filled.

Please check the timing in your MPD and make sure that the signaled segment duration is correct.

YadneshD commented 3 months ago

Thanks for your reply @dsilhavy

Which all parameters should I check in the mpd file? I had converted it from a .mp4 file using MP4Box command - MP4Box -dash 4000 -frag 4000 -profile dashavc264:live -out ./m4d/21-06-2024_18-19-26.mpd 21-06-2024_18-19-26.mp4. My video is of 4 minutes, 21 secs and 30 F.P.S?

If possible, can you please tell me what is wrong in the below file contents of my .mpd file -

<?xml version="1.0"?>
<!-- MPD file Generated with GPAC version 2.5-DEV-rev337-g9674ae8d6-master at 2024-06-28T09:07:34.067Z -->
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" minBufferTime="PT1.500S" type="static" mediaPresentationDuration="PT0H4M21.733S" maxSegmentDuration="PT0H0M8.334S" profiles="urn:mpeg:dash:profile:isoff-live:2011,http://dashif.org/guidelines/dash264">
 <ProgramInformation moreInformationURL="https://gpac.io">
  <Title>21-06-2024_18-19-26.mpd generated by GPAC</Title>
 </ProgramInformation>

 <Period duration="PT0H4M21.733S">
  <AdaptationSet segmentAlignment="true" maxWidth="960" maxHeight="540" maxFrameRate="30" par="16:9" mimeType="video/mp4" startWithSAP="1">
   <SegmentTemplate media="21-06-2024_18-19-26_h264_dash$Number$.m4s" initialization="21-06-2024_18-19-26_h264_dashinit.mp4" timescale="15360" startNumber="1" duration="61440"/>
   <Representation id="1" codecs="avc1.64001F" width="960" height="540" frameRate="30" sar="1:1" bandwidth="5237337">
   </Representation>
  </AdaptationSet>
 </Period>
</MPD>
dsilhavy commented 3 months ago

Please upload your media segments on a server as well, then I try to have a look in between. Only looking at the MPD it is hard to tell if anything is wrong.

YadneshD commented 3 months ago

Thank you for your help @dsilhavy

Here is the link to my zipped mpd and m4s files -

link

dsilhavy commented 3 months ago

@YadneshD It looks like the duration of the media segments signaled in the MPD is different from the “real” segment duration. Looking into the media segments, the real duration seems to be 128000. If you change the duration in SegmentTemplate to 128000 it should work.

YadneshD commented 3 months ago

Thank you so much for your help @dsilhavy

The .mp4 video is being converted to .mpd using mp4box. I have used command -

MP4Box -dash 4000 -frag 4000 -profile dashavc264:live -out ./m4d/21-06-2024_18-19-26.mpd 21-06-2024_18-19-26.mp4

Should I make any changes here so the conversion happens properly? Am I missing something or is it some error from mp4box GPAC?

dsilhavy commented 3 months ago

You will need to check the GPAC documentation for this. Probably the GoP size/IDR frame interval of your content does not match the specified segment duration which is 4000ms. But this is rather an encoding/packaging question than a dash.js/player question.

YadneshD commented 3 months ago

@dsilhavy Thank you very much for the clarifications.