Skip to content

Commit

Permalink
fix: Do not scale width by sarRatio, let decoder handle it via the pa…
Browse files Browse the repository at this point in the history
…sp box (#393)
  • Loading branch information
brandonocasey committed Jul 14, 2021
1 parent 95fe183 commit 9e9982f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
14 changes: 9 additions & 5 deletions lib/codecs/h264.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ PROFILES_WITH_OPTIONAL_SPS_DATA = {
86: true,
118: true,
128: true,

// TODO: the three profiles below don't
// appear to have sps data in the specificiation anymore?
138: true,
139: true,
134: true
Expand Down Expand Up @@ -210,10 +213,11 @@ H264Stream = function() {
trackId: trackId,
pts: currentPts,
dts: currentDts,
data: data
data: data,
nalUnitTypeCode: data[0] & 0x1f
};

switch (data[0] & 0x1f) {
switch (event.nalUnitTypeCode) {
case 0x05:
event.nalUnitType = 'slice_layer_without_partitioning_rbsp_idr';
break;
Expand All @@ -232,7 +236,6 @@ H264Stream = function() {
case 0x09:
event.nalUnitType = 'access_unit_delimiter_rbsp';
break;

default:
break;
}
Expand Down Expand Up @@ -365,7 +368,7 @@ H264Stream = function() {
picHeightInMapUnitsMinus1,
frameMbsOnlyFlag,
scalingListCount,
sarRatio,
sarRatio = [1, 1],
aspectRatioIdc,
i;

Expand Down Expand Up @@ -470,8 +473,9 @@ H264Stream = function() {
profileIdc: profileIdc,
levelIdc: levelIdc,
profileCompatibility: profileCompatibility,
width: Math.ceil((((picWidthInMbsMinus1 + 1) * 16) - frameCropLeftOffset * 2 - frameCropRightOffset * 2) * sarScale),
width: (((picWidthInMbsMinus1 + 1) * 16) - frameCropLeftOffset * 2 - frameCropRightOffset * 2),
height: ((2 - frameMbsOnlyFlag) * (picHeightInMapUnitsMinus1 + 1) * 16) - (frameCropTopOffset * 2) - (frameCropBottomOffset * 2),
// sar is sample aspect ratio
sarRatio: sarRatio
};
};
Expand Down
10 changes: 5 additions & 5 deletions test/transmuxer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ QUnit.test('properly parses seq_parameter_set_rbsp nal units', function(assert)
profileCompatibility: 192,
width: 720,
height: 404,
sarRatio: undefined
sarRatio: [1, 1]
};

h264Stream.on('data', function(event) {
Expand Down Expand Up @@ -889,7 +889,7 @@ QUnit.test('Properly parses seq_parameter_set VUI nal unit', function(assert) {
profileIdc: 66,
levelIdc: 30,
profileCompatibility: 192,
width: 64,
width: 16,
height: 16,
sarRatio: [65528, 16384]
};
Expand Down Expand Up @@ -924,7 +924,7 @@ QUnit.test('Properly parses seq_parameter_set nal unit with defined sarRatio', f
profileIdc: 77,
levelIdc: 21,
profileCompatibility: 64,
width: 640,
width: 352,
height: 480,
sarRatio: [20, 11]
};
Expand Down Expand Up @@ -959,7 +959,7 @@ QUnit.test('Properly parses seq_parameter_set nal unit with extended sarRatio',
profileIdc: 77,
levelIdc: 21,
profileCompatibility: 64,
width: 403,
width: 352,
height: 480,
sarRatio: [8, 7]
};
Expand Down Expand Up @@ -994,7 +994,7 @@ QUnit.test('Properly parses seq_parameter_set nal unit without VUI', function(as
profileCompatibility: 64,
width: 352,
height: 480,
sarRatio: undefined
sarRatio: [1, 1]
};

h264Stream.on('data', function(event) {
Expand Down

0 comments on commit 9e9982f

Please sign in to comment.