Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tsdemuxer: if PES does not contain PTS/DTS, use last PES PTS/DTS instead #2109

Merged
merged 1 commit into from Jan 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/demux/tsdemuxer.js
Expand Up @@ -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);
}

Expand All @@ -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 {
Expand All @@ -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);
}

Expand Down Expand Up @@ -279,15 +279,15 @@ 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 {
// either avcData null or PES truncated, keep it for next frag parsing
avcTrack.pesData = avcData;
}

if (audioData && (pes = parsePES(audioData)) && pes.pts !== undefined) {
if (audioData && (pes = parsePES(audioData))) {
if (audioTrack.isAAC) {
parseAACPES(pes);
} else {
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down