Skip to content

Commit

Permalink
EncoderConfig: introduce GetMaxBFrameCount
Browse files Browse the repository at this point in the history
The default value for B Frame count is 3 but some
implementation does not support B Frame.
Set the value to the max B Frame count supported
by the implementation.

Signed-off-by: Stéphane Cerveau <scerveau@igalia.com>
  • Loading branch information
dabrain34 committed Oct 28, 2024
1 parent 41a88df commit d50734d
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions vk_video_encoder/libs/VkVideoEncoder/VkEncoderConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,8 @@ struct EncoderConfig : public VkVideoRefCountBase {
virtual int8_t InitDpbCount() { return 16; };

virtual bool InitRateControl();

virtual uint8_t GetMaxBFrameCount() { return 0;}
};

// Create codec configuration for H.264 encoder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ VkResult EncoderConfigH264::InitDeviceCapabilities(const VulkanDeviceContext* vk
std::cout << "\t\t\t" << "maxExtent: " << videoCapabilities.maxCodedExtent.width << " x " << videoCapabilities.maxCodedExtent.height << std::endl;
std::cout << "\t\t\t" << "maxDpbSlots: " << videoCapabilities.maxDpbSlots << std::endl;
std::cout << "\t\t\t" << "maxActiveReferencePictures: " << videoCapabilities.maxActiveReferencePictures << std::endl;
std::cout << "\t\t\t" << "maxBPictureL0ReferenceCount: " << h264EncodeCapabilities.maxBPictureL0ReferenceCount << std::endl;
}

return VK_SUCCESS;
Expand Down
2 changes: 2 additions & 0 deletions vk_video_encoder/libs/VkVideoEncoder/VkEncoderConfigH264.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ struct EncoderConfigH264 : public EncoderConfig {
// 2. First h.264 determine the rate control parameters
virtual bool InitRateControl();

virtual uint8_t GetMaxBFrameCount() { return h264EncodeCapabilities.maxBPictureL0ReferenceCount; }

bool GetRateControlParameters(VkVideoEncodeRateControlInfoKHR *rcInfo,
VkVideoEncodeRateControlLayerInfoKHR *pRcLayerInfo,
VkVideoEncodeH264RateControlInfoKHR *rcInfoH264,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ VkResult EncoderConfigH265::InitDeviceCapabilities(const VulkanDeviceContext* vk
std::cout << "\t\t\t" << "maxExtent: " << videoCapabilities.maxCodedExtent.width << " x " << videoCapabilities.maxCodedExtent.height << std::endl;
std::cout << "\t\t\t" << "maxDpbSlots: " << videoCapabilities.maxDpbSlots << std::endl;
std::cout << "\t\t\t" << "maxActiveReferencePictures: " << videoCapabilities.maxActiveReferencePictures << std::endl;
std::cout << "\t\t\t" << "maxBPictureL0ReferenceCount: " << h265EncodeCapabilities.maxBPictureL0ReferenceCount << std::endl;
}

return VK_SUCCESS;
Expand Down
2 changes: 2 additions & 0 deletions vk_video_encoder/libs/VkVideoEncoder/VkEncoderConfigH265.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ struct EncoderConfigH265 : public EncoderConfig {
// 2. First h.265 determine the rate control parameters
virtual bool InitRateControl();

virtual uint8_t GetMaxBFrameCount() { return h265EncodeCapabilities.maxBPictureL0ReferenceCount; }

bool GetRateControlParameters(VkVideoEncodeRateControlInfoKHR *rcInfo,
VkVideoEncodeRateControlLayerInfoKHR *pRcLayerInfo,
VkVideoEncodeH265RateControlInfoKHR *rcInfoH265,
Expand Down
5 changes: 5 additions & 0 deletions vk_video_encoder/libs/VkVideoEncoder/VkVideoEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,11 @@ VkResult VkVideoEncoder::InitEncoder(VkSharedBaseObj<EncoderConfig>& encoderConf
// specific GOP structure. For example it may not support B-frames.
// gopStructure.Init() should be called after encoderConfig->InitDeviceCapabilities().
m_encoderConfig->gopStructure.Init(m_encoderConfig->numFrames);
if (encoderConfig->GetMaxBFrameCount() < m_encoderConfig->gopStructure.GetConsecutiveBFrameCount()) {
std::cout << "Max consecutive B frames: " << (uint32_t)encoderConfig->GetMaxBFrameCount() << " lower than the configured one: " << (uint32_t)m_encoderConfig->gopStructure.GetConsecutiveBFrameCount() << std::endl;
std::cout << "Fallback to the max value: " << (uint32_t)m_encoderConfig->gopStructure.GetConsecutiveBFrameCount() << std::endl;
m_encoderConfig->gopStructure.SetConsecutiveBFrameCount(encoderConfig->GetMaxBFrameCount());
}
std::cout << std::endl << "GOP frame count: " << (uint32_t)m_encoderConfig->gopStructure.GetGopFrameCount();
std::cout << ", IDR period: " << (uint32_t)m_encoderConfig->gopStructure.GetIdrPeriod();
std::cout << ", Consecutive B frames: " << (uint32_t)m_encoderConfig->gopStructure.GetConsecutiveBFrameCount();
Expand Down

0 comments on commit d50734d

Please sign in to comment.