Skip to content

Commit

Permalink
Implement filtering for nalUnit streams that do not begin with an AUD…
Browse files Browse the repository at this point in the history
… in mp4 transmuxer
  • Loading branch information
jrivera committed Nov 6, 2015
1 parent cb4836d commit ebfa7cc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
14 changes: 6 additions & 8 deletions lib/flv/transmuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ VideoSegmentStream = function(track) {
nalUnits = [],
nalUnitsLength = 0,
config,
pps,
h264Frame;
VideoSegmentStream.prototype.init.call(this);

Expand Down Expand Up @@ -221,12 +220,6 @@ VideoSegmentStream = function(track) {
currentNal,
tags = [];

// return early if no video data has been observed
if (nalUnits.length === 0) {
this.trigger('done');
return;
}

// Throw away nalUnits at the start of the byte stream until we find
// the first AUD
while (nalUnits.length) {
Expand All @@ -236,6 +229,12 @@ VideoSegmentStream = function(track) {
nalUnits.shift();
}

// return early if no video data has been observed
if (nalUnits.length === 0) {
this.trigger('done');
return;
}

while (nalUnits.length) {
currentNal = nalUnits.shift();

Expand All @@ -252,7 +251,6 @@ VideoSegmentStream = function(track) {
h264Frame.endNalUnit();
} else if (currentNal.nalUnitType === 'pic_parameter_set_rbsp') {
track.newMetadata = true;
pps = currentNal.data;
track.pps = [currentNal.data];
h264Frame.endNalUnit();
} else if (currentNal.nalUnitType === 'access_unit_delimiter_rbsp') {
Expand Down
9 changes: 9 additions & 0 deletions lib/mp4/transmuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,15 @@ VideoSegmentStream = function(track) {
this.flush = function() {
var startUnit, currentNal, moof, mdat, boxes, i, data, view, sample, duration;

// Throw away nalUnits at the start of the byte stream until we find
// the first AUD
while (nalUnits.length) {
if (nalUnits[0].nalUnitType === 'access_unit_delimiter_rbsp') {
break;
}
nalUnits.shift();
}

// return early if no video data has been observed
if (nalUnitsLength === 0) {
this.trigger('done');
Expand Down
8 changes: 7 additions & 1 deletion test/transmuxer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,10 @@ test('concatenates NAL units into AVC elementary streams', function() {
videoSegmentStream.on('data', function(data) {
segment = data.boxes;
});
videoSegmentStream.push({
nalUnitType: 'access_unit_delimiter_rbsp',
data: new Uint8Array([0x09, 0x01])
});
videoSegmentStream.push({
data: new Uint8Array([
0x08,
Expand All @@ -1202,9 +1206,11 @@ test('concatenates NAL units into AVC elementary streams', function() {
ok(segment, 'generated a data event');
boxes = muxjs.tools.inspectMp4(segment);
equal(boxes[1].byteLength,
(4 + 4) + (4 + 6),
(2 + 4) + (4 + 4) + (4 + 6),
'wrote the correct number of bytes');
deepEqual(new Uint8Array(segment.subarray(boxes[0].size + 8)), new Uint8Array([
0, 0, 0, 2,
0x09, 0x01,
0, 0, 0, 4,
0x08, 0x01, 0x02, 0x03,
0, 0, 0, 6,
Expand Down

0 comments on commit ebfa7cc

Please sign in to comment.