Skip to content

Commit

Permalink
fix: Do not trim audio output when keepOriginalTimestamps is set (vid…
Browse files Browse the repository at this point in the history
…eojs#329)

Co-authored-by: Garrett Singer <[email protected]>
  • Loading branch information
joeyparrish and gesinger authored Apr 7, 2020
1 parent 48bfe00 commit b9bfdd8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
9 changes: 5 additions & 4 deletions lib/mp4/transmuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1010,10 +1010,11 @@ Transmuxer = function(options) {
pipeline.videoSegmentStream = new VideoSegmentStream(videoTrack, options);

pipeline.videoSegmentStream.on('timelineStartInfo', function(timelineStartInfo) {
// When video emits timelineStartInfo data after a flush, we forward that
// info to the AudioSegmentStream, if it exists, because video timeline
// data takes precedence.
if (audioTrack) {
// When video emits timelineStartInfo data after a flush, we forward that
// info to the AudioSegmentStream, if it exists, because video timeline
// data takes precedence. Do not do this if keepOriginalTimestamps is set,
// because this is a particularly subtle form of timestamp alteration.
if (audioTrack && !options.keepOriginalTimestamps) {
audioTrack.timelineStartInfo = timelineStartInfo;
// On the first segment we trim AAC frames that exist before the
// very earliest DTS we have seen in video because Chrome will
Expand Down
13 changes: 10 additions & 3 deletions test/transmuxer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3486,8 +3486,9 @@ QUnit.test('adjusts caption and ID3 times when configured to adjust timestamps',

QUnit.test('Audio frames trimmed before video, ' + name, function() {
var
segments = [],
segments = [],
earliestDts = 15000,
baseTime = test.options.baseMediaDecodeTime || test.baseMediaSetter || 0,
transmuxer = createTransmuxer();

transmuxer.on('data', function(segment) {
Expand All @@ -3506,7 +3507,7 @@ QUnit.test('adjusts caption and ID3 times when configured to adjust timestamps',

transmuxer.push(packetize(audioPes([
0x19, 0x47
], true, earliestDts - (test.options.baseMediaDecodeTime || test.baseMediaSetter || 0) - 1)));
], true, earliestDts - baseTime - 1)));
transmuxer.push(packetize(videoPes([
0x09, 0x01 // access_unit_delimiter_rbsp
], true, earliestDts)));
Expand All @@ -3529,7 +3530,13 @@ QUnit.test('adjusts caption and ID3 times when configured to adjust timestamps',
QUnit.equal(segments.length, 1, 'generated a combined segment');
// The audio frame is 10 bytes. The full data is 305 bytes without anything
// trimmed. If the audio frame was trimmed this will be 295 bytes.
QUnit.equal(segments[0].data.length, 295, 'trimmed audio frame');
// Note that if the baseMediaDecodeTime is set via options or the setter, frames may still
// be removed, even if keepOriginalTimestamps is true.
if (test.options.keepOriginalTimestamps && !baseTime) {
QUnit.equal(segments[0].data.length, 305, 'trimmed audio frame');
} else {
QUnit.equal(segments[0].data.length, 295, 'trimmed audio frame');
}
});
});

Expand Down

0 comments on commit b9bfdd8

Please sign in to comment.