Make sure the output resolution of encoder doesn't exceed the Openh264 capability
This commit is contained in:
parent
acab999b45
commit
00e89b89f0
@ -34,6 +34,7 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <cmath>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -115,6 +116,7 @@ const char* kLogStrings[] = {
|
|||||||
"Debug"
|
"Debug"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define OPENH264_MAX_MB 36864
|
||||||
|
|
||||||
GMPPlatformAPI* g_platform_api = nullptr;
|
GMPPlatformAPI* g_platform_api = nullptr;
|
||||||
|
|
||||||
@ -249,8 +251,27 @@ class OpenH264VideoEncoder : public GMPVideoEncoder, public RefCounted {
|
|||||||
// Set up layers. Currently we have one layer.
|
// Set up layers. Currently we have one layer.
|
||||||
SSpatialLayerConfig* layer = ¶m.sSpatialLayers[0];
|
SSpatialLayerConfig* layer = ¶m.sSpatialLayers[0];
|
||||||
|
|
||||||
|
// Make sure the output resolution doesn't exceed the Openh264 capability
|
||||||
|
double width_mb = std::ceil(codecSettings.mWidth/16.0);
|
||||||
|
double height_mb = std::ceil(codecSettings.mHeight/16.0);
|
||||||
|
double input_mb = width_mb * height_mb;
|
||||||
|
if (static_cast<uint32_t>(input_mb) > OPENH264_MAX_MB) {
|
||||||
|
double scale = std::sqrt(OPENH264_MAX_MB / input_mb);
|
||||||
|
layer->iVideoWidth = static_cast<uint32_t>(width_mb * 16 * scale);
|
||||||
|
layer->iVideoHeight = static_cast<uint32_t>(height_mb * 16 * scale);
|
||||||
|
GMPLOG (GL_INFO, "InitEncode: the output resolution overflows, w x h = " << codecSettings.mWidth << " x " << codecSettings.mHeight
|
||||||
|
<< ", turned to be " << layer->iVideoWidth << " x " << layer->iVideoHeight);
|
||||||
|
} else {
|
||||||
layer->iVideoWidth = codecSettings.mWidth;
|
layer->iVideoWidth = codecSettings.mWidth;
|
||||||
layer->iVideoHeight = codecSettings.mHeight;
|
layer->iVideoHeight = codecSettings.mHeight;
|
||||||
|
}
|
||||||
|
if (layer->iVideoWidth < 16) {
|
||||||
|
layer->iVideoWidth = 16;
|
||||||
|
}
|
||||||
|
if (layer->iVideoHeight < 16) {
|
||||||
|
layer->iVideoHeight = 16;
|
||||||
|
}
|
||||||
|
|
||||||
layer->fFrameRate = param.fMaxFrameRate;
|
layer->fFrameRate = param.fMaxFrameRate;
|
||||||
layer->iSpatialBitrate = param.iTargetBitrate;
|
layer->iSpatialBitrate = param.iTargetBitrate;
|
||||||
layer->iMaxSpatialBitrate = param.iMaxBitrate;
|
layer->iMaxSpatialBitrate = param.iMaxBitrate;
|
||||||
|
Loading…
Reference in New Issue
Block a user