canalplus / rx-player

DASH/Smooth HTML5 Video Player
https://developers.canal-plus.com/rx-player/
Apache License 2.0
870 stars 131 forks source link

RX player producest bad number for file names #550

Open Maciejszuchta opened 5 years ago

Maciejszuchta commented 5 years ago

Hello I'm very new to this subject but I managed to run DashCast that will produce m4s files for my Rx-player in angular app. However, after dash cast producest such mpd file

<?xml version="1.0"?>
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" profiles="urn:mpeg:dash:profile:full:2011" minBufferTime="PT1.000000S" type="dynamic" availabilityStartTime="2019-06-14T13:07:22.348Z" timeShiftBufferDepth="PT00H00M10S" publishTime="2019-06-14T13:07:24Z">
 <ProgramInformation moreInformationURL="http://gpac.io">
  <Title>dashcast.mpd</Title>
 </ProgramInformation>
 <Period start="PT0H0M0.000S" id="P1">
  <AdaptationSet segmentAlignment="true" bitstreamSwitching="false">
   <SegmentTemplate timescale="25" duration="12" media="$RepresentationID$_gpac.m4s" startNumber="1" initialization="$RepresentationID$_init_gpac.mp4"/>
   <Representation id="v1" mimeType="video/mp4" codecs="avc1.64001E" width="640" height="480" frameRate="25" sar="1:1" startWithSAP="1" bandwidth="1000000">
   </Representation>
  </AdaptationSet>
 </Period>
</MPD>

the files are created with names like v1_1_gpac.m4s, v1_2_gpac.m4s, v1_3_gpac.m4s etc... But Rx-player tries to get the file with name like v1_942_gpac.m4s. Refreshing the page makes Rx-player change the number of the file randomly.

I don't understand such behavior. Can you explain or point what I am doing wrong?

peaBerberian commented 5 years ago

Hi,

When playing a live content (we deduce that from the MPD type, for us dynamic == live content), we try to play close to the "live edge", which means close to what should be broadcasted now.

From your MPD file, the RxPlayer can see that your stream started at availabilityStartTime="2019-06-14T13:07:22.348Z" and thus it counts this point in time as the beginning of the content.

As the startNumber of the first Period is 1 this would correspond to v1_1_gpac.mp4s.

But as we said earlier, by default the RxPlayer will try to play closer to the edge of the content.

Each segment has a duration of duration / timescale seconds. Judging from your MPD, each segment here has a duration of 12 / 25 = 0.48s.

v1_942_gpac.m4s thus corresponds to the 942th segments which starts 941*duration = 451,68s after the beginning of the content which means 7min 31 after or roughly "2019-06-14T13:14:53.348Z".

If you do it now you will obtain an even bigger number as the current time evolves.

You can resolve that situation in multiple ways:

Maciejszuchta commented 5 years ago

@peaBerberian thanks for the response :) I tried adding startAt: {position: 0} to loadVideo but still player requests wrong file numbers. Do you know if it is even possible to create a live stream from dynamically incoming mp4 files?

grenault73 commented 5 years ago

Hi, As @peaBerberian said, your stream is a live stream. In your manifest, you define the timeShiftBufferDepth at 10 seconds. This value defines the time from now where content is available to download. As an example, if you load a live manifest at time = 1000, and your timeShiftBufferDepth is 10 seconds, you will be able to download segments that starts from 990 to 1000. If it is not set, the timeShiftBufferDepth is considered to be infinite, and all the announced content shall be available to download.

In our code, we define that if you try to start playback under this minimum time, you will play from the minimum time. So, as your timeShiftBufferDepth is defined to 10, the RxPlayer still tries to fetch segment with another number that the one you're expecting.

If you still plan to use a "dynamic" manifest, you should considerate that the player is legitimate in trying to play from an advanced time if the content is live. If you fetch dynamically a mp4 to create live streams, you should considerate starting from 0 and trying not to set the timeShiftBufferDepth.

Maciejszuchta commented 5 years ago

Hello I managed to set up my manifest so rx-player requests next files, however, although files are available on the server player doesn't display them.

image

Maciejszuchta commented 5 years ago

Also why rx-player requests for the same file for so many times ? image

grenault73 commented 5 years ago

Hello, It is possible that Chrome blocks requests responses due to CORS ! Your file server may respond with the headerAccess-Control-Allow-Origin set to * (a wildcard) in order to tell Chrome he's authorized to use the response in the requesting code, from an other origin (RxPlayer).

Maciejszuchta commented 5 years ago

Ok, it happens indeed but only for some of the requests. As you can see video sometime loads and plays for a few seconds.

Maciejszuchta commented 5 years ago

Ok, I resolved it by returning 404 when the file is missing. However, this doesn't fix the issue. Also, I noticed weird behaviour. Although all files are available on the server rx-player only requests for init file and then just refreshes mpd file. It doesnt request for m4s files.

image

Here you can see files on server, empty web player and requests done only for mpd file which looks like this:

<?xml version="1.0"?>
<!-- MPD file Generated with GPAC version 0.9.0-DEV-rev2609-g759c91dc-filters at 2019-07-25T07:06:49.400Z -->
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" minBufferTime="PT1.500S" type="dynamic" availabilityStartTime="2019-07-25T07:00:32.090Z" publishTime="2019-07-25T07:06:49.400Z" minimumUpdatePeriod="PT0H0M5.000S" maxSegmentDuration="PT0H0M3.020S" profiles="urn:mpeg:dash:profile:isoff-live:2011">
 <ProgramInformation moreInformationURL="http://gpac.io">
  <Title>live.mpd generated by GPAC</Title>
 </ProgramInformation>

 <Period id="DID1" start="PT0H0M0.000S">
  <AdaptationSet segmentAlignment="true" maxWidth="1440" maxHeight="2960" maxFrameRate="30" par="1440:2960" lang="und" startWithSAP="1">
   <SegmentTemplate media="9887a8334f4b49314e_dash$Number$.m4s" initialization="9887a8334f4b49314e_dashinit.mp4" timescale="90000" startNumber="1" duration="900000"/>
   <Representation id="1" mimeType="video/mp4" codecs="avc1.428034" width="1440" height="2960" frameRate="90000/2925" sar="1:1" bandwidth="3627502">
   </Representation>
  </AdaptationSet>
 </Period>
</MPD>