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

fix: Do not scale width by sarRatio, we already generate a pasp box with sarRatio information. #393

Merged
merged 5 commits into from
Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default to a 1 to 1 aspect ratio, ie width and height are exact values.

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),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't need to Math.ceil if we are not scaling now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the original reason that we did scaling is because we did not encode a pasp atom with sarRatio information when mux.js was created. So We had to encode width and height as their real values at all times. I think we should have been scaling height in some scenarios too. Overall we won't have to do any of that now as the decoder will see the pasp and scale accordingly. We just have to report the values that exist.

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