From cebe2ff70f36ad7383c11732519c62cdd648d2ae Mon Sep 17 00:00:00 2001 From: Guillaume du Pontavice Date: Tue, 29 Jan 2019 21:58:14 -0800 Subject: [PATCH] tsdemuxer: if PES does not contain PTS/DTS, use last PES PTS/DTS instead --- src/demux/tsdemuxer.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/demux/tsdemuxer.js b/src/demux/tsdemuxer.js index 81ae6e7b9e9..9e396b8a4da 100644 --- a/src/demux/tsdemuxer.js +++ b/src/demux/tsdemuxer.js @@ -184,7 +184,7 @@ class TSDemuxer { switch (pid) { case avcId: if (stt) { - if (avcData && (pes = parsePES(avcData)) && pes.pts !== undefined) { + if (avcData && (pes = parsePES(avcData))) { parseAVCPES(pes, false); } @@ -197,7 +197,7 @@ class TSDemuxer { break; case audioId: if (stt) { - if (audioData && (pes = parsePES(audioData)) && pes.pts !== undefined) { + if (audioData && (pes = parsePES(audioData))) { if (audioTrack.isAAC) { parseAACPES(pes); } else { @@ -213,7 +213,7 @@ class TSDemuxer { break; case id3Id: if (stt) { - if (id3Data && (pes = parsePES(id3Data)) && pes.pts !== undefined) { + if (id3Data && (pes = parsePES(id3Data))) { parseID3PES(pes); } @@ -279,7 +279,7 @@ class TSDemuxer { } } // try to parse last PES packets - if (avcData && (pes = parsePES(avcData)) && pes.pts !== undefined) { + if (avcData && (pes = parsePES(avcData))) { parseAVCPES(pes, true); avcTrack.pesData = null; } else { @@ -287,7 +287,7 @@ class TSDemuxer { avcTrack.pesData = avcData; } - if (audioData && (pes = parsePES(audioData)) && pes.pts !== undefined) { + if (audioData && (pes = parsePES(audioData))) { if (audioTrack.isAAC) { parseAACPES(pes); } else { @@ -304,7 +304,7 @@ class TSDemuxer { audioTrack.pesData = audioData; } - if (id3Data && (pes = parsePES(id3Data)) && pes.pts !== undefined) { + if (id3Data && (pes = parsePES(id3Data))) { parseID3PES(pes); id3Track.pesData = null; } else { @@ -534,6 +534,18 @@ class TSDemuxer { if (avcSample.units.length && avcSample.frame) { const samples = avcTrack.samples; const nbSamples = samples.length; + // if sample does not have PTS/DTS, patch with last sample PTS/DTS + if (isNaN(avcSample.pts)) { + if (nbSamples) { + const lastSample = samples[nbSamples - 1]; + avcSample.pts = lastSample.pts; + avcSample.dts = lastSample.dts; + } else { + // dropping samples, no timestamp found + avcTrack.dropped++; + return; + } + } // only push AVC sample if starting with a keyframe is not mandatory OR // if keyframe already found in this fragment OR // keyframe found in last fragment (track.sps) AND