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

MP4: Parse initial PAR from H.265 SPS and include it in HevcConfig #9421

Merged
merged 4 commits into from
Sep 24, 2021

Conversation

MarcusWichelmann
Copy link
Contributor

Currently, the initial H.265 SPS from the hvcC atom/box is not parsed for its pixel aspect ratio which resulted in all content being played back with aspect ratio 1:1 if no pasp box is present.

This PR ...

  • introduces a parseH265SpsNalUnitPayload method to parse a SPS NAL unit, just like it's done for H.264, too. The parsing code is derived from H265Reader.parseMediaFormat.
  • extends the HevcConfig class to parse the initial SPS and propagate the PAR into the Format if no pasp is present.
  • refactors the buildHevcCodecStringFromSps method to re-use the parsed SPS data - just like it's done for H.264.

This PR was split up from #9318.

…de the PAR for propagating it into the Format
@google-cla google-cla bot added the cla: yes label Sep 13, 2021
@MarcusWichelmann MarcusWichelmann changed the title Parse initial PAR from H.265 SPS and include it in HevcConfig MP4: Parse initial PAR from H.265 SPS and include it in HevcConfig Sep 13, 2021
@ojw28 ojw28 self-assigned this Sep 13, 2021
@MarcusWichelmann
Copy link
Contributor Author

MarcusWichelmann commented Sep 13, 2021

Re-added the methods now and reverted some changes that were required to adopt to the breaking change. Way cleaner now. 👍🏼

@@ -105,6 +118,9 @@ public static HevcConfig parse(ParsableByteArray data) throws ParserException {
@Nullable public final List<byte[]> initializationData;
/** The length of the NAL unit length field in the bitstream's container, in bytes. */
public final int nalUnitLengthFieldLength;
public final int width;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please could you Javadoc these three fields. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@ojw28 ojw28 merged commit 9108dc5 into google:dev-v2 Sep 24, 2021
public static H265SpsData parseH265SpsNalUnitPayload(byte[] nalData, int nalOffset, int nalLimit) {
ParsableNalUnitBitArray data = new ParsableNalUnitBitArray(nalData, nalOffset, nalLimit);
// Skip sps_video_parameter_set_id.
data.skipBits(8 + 4);
Copy link
Contributor

Choose a reason for hiding this comment

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

It was pointed out during internal review that sps_video_parameter_set_id is only 4 bits long. Furthermore, it appears that the NAL unit header for H265 is 16 bits long, so L451 should be adding 2 to the offset rather than 1. We've fixed this as part of merging the change.

Please see the merge here and let us know if there are any problems! Thanks

Copy link
Contributor Author

@MarcusWichelmann MarcusWichelmann Sep 27, 2021

Choose a reason for hiding this comment

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

@ojw28 Thanks for merging.

Furthermore, it appears that the NAL unit header for H265 is 16 bits long ...

Than makes sense, thanks for fixing. Interesting that it worked anyway. 😄

I just tested latest dev-v2 and everything looks fine. 👍🏼

@google google locked and limited conversation to collaborators Nov 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants