Skip to content

Commit b658015

Browse files
committed
Use segment timeline for vimeo
1 parent 872c386 commit b658015

File tree

1 file changed

+50
-6
lines changed

1 file changed

+50
-6
lines changed

chrome/player/players/vm/Vimeo2Dash.mjs

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class Vimeo2Dash {
1010
const MPD = this.makeMPD(new_base_url, playlist);
1111
const xml = new XMLSerializer().serializeToString(MPD);
1212
// console.log(JSON.stringify(playlist));
13-
// console.log(xml, playlist);
13+
console.log(xml, playlist);
1414
return '<?xml version="1.0" encoding="utf-8"?>' + xml;
1515
}
1616

@@ -32,6 +32,9 @@ export class Vimeo2Dash {
3232
const width = track.width;
3333
const height = track.height;
3434
const frameRate = track.framerate;
35+
const index_segment = track.index_segment;
36+
const init_segment_data_b64 = track.init_segment;
37+
const segments = track.segments;
3538
// sconst startWithSap = 1;
3639

3740
// const codecid = track.codecid;
@@ -55,14 +58,55 @@ export class Vimeo2Dash {
5558
Representation.appendChild(BaseURL);
5659

5760
const SegmentList = this.document.createElement('SegmentList');
58-
SegmentList.setAttribute('duration', track.max_segment_duration);
59-
SegmentList.setAttribute('timescale', 1);
61+
6062

6163
Representation.appendChild(SegmentList);
6264

63-
const index_segment = track.index_segment;
64-
const init_segment_data_b64 = track.init_segment;
65-
const segments = track.segments;
65+
// segment timeline
66+
const SegmentTimeline = this.document.createElement('SegmentTimeline');
67+
const timeScale = 1000;
68+
SegmentList.setAttribute('timescale', timeScale);
69+
// adjust segment times to timescale
70+
segments.forEach((segment)=>{
71+
segment.start = Math.floor(segment.start * timeScale);
72+
segment.end = Math.floor(segment.end * timeScale);
73+
});
74+
75+
// adjust so that the first segment starts at 0
76+
const firstStart = segments[0].start;
77+
if (firstStart !== 0) {
78+
segments.forEach((segment)=>{
79+
segment.start -= firstStart;
80+
segment.end -= firstStart;
81+
});
82+
}
83+
84+
// group segments with same duration
85+
const timeline = [];
86+
let current = {start: segments[0].start, duration: segments[0].end - segments[0].start, count: 1};
87+
for (let i = 1; i < segments.length; i++) {
88+
const segment = segments[i];
89+
const duration = segment.end - segment.start;
90+
if (duration === current.duration) {
91+
current.count++;
92+
} else {
93+
timeline.push(current);
94+
current = {start: segment.start, duration: duration, count: 1};
95+
}
96+
}
97+
timeline.push(current);
98+
99+
timeline.forEach((entry, i)=>{
100+
const S = this.document.createElement('S');
101+
S.setAttribute('t', entry.start);
102+
S.setAttribute('d', entry.duration);
103+
if (entry.count > 1) {
104+
S.setAttribute('r', entry.count - 1);
105+
}
106+
SegmentTimeline.appendChild(S);
107+
});
108+
109+
SegmentList.appendChild(SegmentTimeline);
66110

67111
if (index_segment !== undefined) {
68112
const RepresentationIndex = this.document.createElement('RepresentationIndex');

0 commit comments

Comments
 (0)