-
Notifications
You must be signed in to change notification settings - Fork 353
Description
你好,我这边使用glReadPixels抓取的一帧数据,
int width = 1920;
int height = 870;
int frameRate = 60;
int fmt_size = sizeof(unsigned char) * 4;
int row_size = width * fmt_size;
int bufferSize = width * height * fmt_size * 2;
HANDLE hEvent;
unsigned char *_data;
unsigned char *_tmpdata = new unsigned char[bufferSize];
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE /0x8035/,
_tmpdata);
for (int i = 0; i < height; i++) {
memcpy(&_data[i * row_size], &_tmpdata[(height - i - 1) * row_size],
row_size);
}
EncoderManager::getInstance().encode(_tmpdata, width, height);
先进行转换YUV, scale时报错了。 传入的宽高是一个固定的值: 1920*870, 帮给看看
AVFrame *EncoderManager::toAVFrame(unsigned char *data, int width, int height) {
AVFrame *avFrame = av_frame_alloc();
av_image_alloc(avFrame->data, avFrame->linesize, width,
height, encoder->getCodecContext()->pix_fmt, 1);
std::int32_t row_pitch {};
row_pitch = width * 4;
const int linessizes[2] {
row_pitch, 0
};
const uint8_t *tmp[2] = { (uint8_t *)data, NULL };
SwsContext *sws = sws_getContext(width, height, AV_PIX_FMT_RGBA, width, height,
AV_PIX_FMT_YUV420P, SWS_FAST_BILINEAR, NULL, NULL, NULL);
int ret = sws_scale(sws, tmp, linessizes, 0, encoder->getCodecContext()->height,
avFrame->data, avFrame->linesize);
printfString("toAVFrame scale", ret);
return avFrame;
}
EncoderManager::encode:1920, 870
toAVFrame scale error code:870, mean:Error number 870 occurred
encode sw
MediaCodec::queueInputToEncoder::error input to encoder
queueInputToEncoder result error code:-1, mean:Operation not permitted
EncoderManager::run:frameCount:1