Skip to content

Commit

Permalink
Fix #61
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrews54757 committed Dec 28, 2023
1 parent eab7a32 commit 48d3ffa
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
2 changes: 2 additions & 0 deletions chrome/player/modules/dash2mp4/dash2mp4.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ export class DASH2MP4 extends EventEmitter {

const movieTimescale = tracks[0].timescale;
tracks.forEach((track) => {
track.movieTimescale = movieTimescale;

track.elst.push({
media_time: (track.chunks[0].startPTS - minPts) / track.timescale * movieTimescale,
segment_duration: (track.chunks[track.chunks.length - 1].endPTS - track.chunks[0].startPTS) / track.timescale * movieTimescale,
Expand Down
2 changes: 1 addition & 1 deletion chrome/player/modules/hls2mp4/MP4Generator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ export class MP4 {
}
static tkhd(track) {
const id = track.id;
const duration = track.duration * track.timescale;
const duration = track.duration * track.movieTimescale;
const width = track.width;
const height = track.height;
const upperWordDuration = Math.floor(duration / (UINT32_MAX + 1));
Expand Down
30 changes: 25 additions & 5 deletions chrome/player/modules/hls2mp4/hls2mp4.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class HLS2MP4 extends EventEmitter {
use64Offsets: false,
nextChunkId: 1,
elst: [],
padding: 0,
};
}

Expand Down Expand Up @@ -94,6 +95,7 @@ export class HLS2MP4 extends EventEmitter {
use64Offsets: false,
nextChunkId: 1,
elst: [],
padding: 0,
};
}

Expand Down Expand Up @@ -136,6 +138,7 @@ export class HLS2MP4 extends EventEmitter {
use64Offsets: false,
nextChunkId: 1,
elst: [],
padding: 0,
};
}

Expand Down Expand Up @@ -201,22 +204,39 @@ export class HLS2MP4 extends EventEmitter {
}

const len = tracks[0].chunks.length;
let minPts = tracks[0].chunks[0].startPTS;
let minDts = tracks[0].chunks[0].startDTS;

for (let i = 0; i < tracks.length; i++) {
if (tracks[i].chunks.length !== len) {
console.log('WARNING: chunk length is not equal', tracks[i].chunks.length, len);
}

if (tracks[i].chunks[0].startPTS < minPts) {
minPts = tracks[i].chunks[0].startPTS;
if (tracks[i].chunks[0].startDTS < minDts) {
minDts = tracks[i].chunks[0].startDTS;
}
}

tracks.forEach((track) => {
const trackDTS = track.chunks[0].startDTS;
const diff = trackDTS - minDts;
if (diff > 0.01) {
const cts = track.chunks[0].startPTS - track.chunks[0].startDTS;
track.elst.push({
media_time: -1,
segment_duration: Math.floor((diff + cts) * track.timescale),
});
track.padding = diff;
}
});


const movieTimescale = tracks[0].timescale;
tracks.forEach((track) => {
track.movieTimescale = movieTimescale;

track.elst.push({
media_time: (track.chunks[0].startPTS - minPts) * movieTimescale,
segment_duration: (track.chunks[track.chunks.length - 1].endPTS - track.chunks[0].startPTS) * movieTimescale,
media_time: (track.chunks[0].startPTS - track.chunks[0].startDTS) * movieTimescale,
segment_duration: (track.chunks[track.chunks.length - 1].endDTS - track.chunks[0].startDTS - track.padding) * movieTimescale,
});

track.samples = [];
Expand Down

0 comments on commit 48d3ffa

Please sign in to comment.