Skip to content

encode: codec profile fixes#203

Open
srinathkr-nv wants to merge 6 commits intonvpro-samples:mainfrom
srinathkr-nv:codec-profile-fixes
Open

encode: codec profile fixes#203
srinathkr-nv wants to merge 6 commits intonvpro-samples:mainfrom
srinathkr-nv:codec-profile-fixes

Conversation

@srinathkr-nv
Copy link
Contributor

This PR completes the work started in #179 to refactor the code related to the determination of the codec profile and level (and tier, as applicable) for all codecs, in order to avoid redundant calculations / storage and to provide a single point early in the encoder initialization stage where these values are decided.

Another effect of this refactoring is to use the proper codec profile when creating the video profile used for queries of capabilities and recommended settings. Previously, the video profile constructed for these purposes used a default codec profile, which may not be representative of (or may not support) the coding tools requested.

Commit 7734964, which introduced the
InitProfileLevel method, also introduced a bug in that code where a call
to the GOP structure's GetConsecutiveBFrameCount() method was replaced
by the GetMaxBFrameCount() method. This is problematic because
GetMaxBFrameCount() depends on device capabilities which have not been
queried yet. This commit restores the call to
GetConsecutiveBFrameCount() in the profile determination code.

This commit also removes a check on the rate control mode when lossless
encoding is requested, as the rate control mode may not have been
specified by the user (and it will be determined later when querying the
quality level properties). This change works as lossless encoding
inherently requires the HIGH_444_PREDICTIVE profile regardless of rate
control settings.

Together, these changes make it safe to call InitProfileLevel() early in
the overall initialization sequence, before any capabilities or
recommended settings have been queried.

Signed-off-by: Srinath Kumarapuram <skr@nvidia.com>
The current call to EncoderConfigH264::InitProfileLevel() happens in the
following sequence:

    VkVideoEncoderH264::InitEncoderCodec()
    |
    +-- EncoderConfigH264::InitProfileLevel()
    |
    +-- InitEncoder()
        |
        +-- InitVideoProfile()
        |
        +-- InitDeviceCapabilities()

This serves the purpose of initializing the codec profile and level
before constructing the video profile but as InitProfileLevel()
initializes more parameters within the encoder config structure itself,
calling it from within VkVideoEncoderH264 seems a bit awkward.

A much better place to call it from is
EncoderConfigH264::InitializeParameters(), which is what this commit
implements. This gets done immediately after the command line parameters
have been parsed and is part of the overall encoder config structure
initialization process

Signed-off-by: Srinath Kumarapuram <skr@nvidia.com>
…er init

This commit adds an InitProfileLevel() method similar to what
EncoderConfigH264 contains, for common initialization of the codec
profile, level and tier. This makes use of the preexisting profile and
levelIdc members defined in EncoderConfigH265 but not used otherwise.

With this addition, the InitParamameters() and InitRateControl() methods
have been changed to remove the redundant and repetitive initialization
of the profile and level. The codec profile and level determined earlier
in the encoder config initialization are now used directly instead.

Signed-off-by: Srinath Kumarapuram <skr@nvidia.com>
This change is not a plain renaming, as it also modifies the method to
directly set the level and tier members in the class instead of
initializing and returning a StdVideoH265ProfileTierLevel structure. The
method name is also now consistent with that for the other codecs.

Signed-off-by: Srinath Kumarapuram <skr@nvidia.com>
…r init

This commit adds an InitProfileLevel() method similar to what
EncoderConfigH264 and EncoderConfigH265 contain, for common
initialization of the codec profile, level and tier.

With this addition, the InitRateControl() method have been changed to
remove the redundant and repetitive initialization of the level and
tier. The codec profile and level determined earlier in the encoder
config initialization are now used directly instead.

Signed-off-by: Srinath Kumarapuram <skr@nvidia.com>
Prior to this commit, the profile was computed twice:
1. InitProfileLevel() set the codec-specific profile member based on
   encoding features (B-frames, CABAC, bit depth, chroma format, etc.)
2. InitVideoProfile() recomputed the profile via
   GetDefaultVideoProfileIdc() based only on bit depth and chroma
   format, storing it in videoProfileIdc

Importantly, there were cases where the codec profile determined by
InitProfileLevel() was different from videoProfileIdc. As
videoProfileIdc is used for constructing the video profile structure
used in capability and recommended settings queries, there was a
possibility of the encoder getting configured with a different codec
profile than the one required for the user configuration.

This refactoring eliminates redundant profile storage and computation by
using the codec-specific profile members (profileIdc/profile) that are
already set by InitProfileLevel(). The main changes in this refactoring
are:
- Remove videoProfileIdc member variable from EncoderConfig base class
- Replace GetDefaultVideoProfileIdc() virtual method with
  GetCodecProfile()
- Add GetCodecProfile() implementations in H.264/H.265/AV1 that return
  the already-initialized codec-specific profile members
- Update InitVideoProfile() to call GetCodecProfile() instead of using
  videoProfileIdc
- Add an assertion in each GetCodecProfile() implementation to ensure
  that the profile is initialized

With this change, the codec profile is determined once and used
everywhere else in the codebase.

Signed-off-by: Srinath Kumarapuram <skr@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant