问题
能够提供一个H264 新接口的编码DEMO ?
#旧接口--可正常使用
DPRCT_W virtual int encode(const void* inputBuf, unsigned int inputLen,
void* outputBuf, unsigned int outputLen) = 0;
# 新接口
virtual int encode(AVPacket* inPacket) = 0;
使用上述接口编码NV12->H264. 可以正常工作. 但根据官方提示, 该接口已废弃. 推荐使用新的接口
// init part
if (!m_avPacket )
{
m_avPacket = (AVPacket*)calloc(1,sizeof(AVPacket));
if (!m_avPacket->pAddrVir0)
{
int32_t frameSize = encode_param_.srcW * encode_param_.srcH *1.5;
m_avPacket->pAddrVir0 = (unsigned char* )calloc(frameSize, sizeof(int8_t));
m_avPacket->pAddrVir1 = m_avPacket->pAddrVir0+ encode_param_.srcW * encode_param_.srcH;
}
}
p_encoder_ = AWVideoEncoder::create();
p_encoder_->init(&encode_param_,this);
int32_t Encoder::EncodeFrame(int8_t *buff, uint32_t buffSize, int64_t pts, int32_t format)
{
if (buff == NULL || !m_avPacket)
{
PLOGE.printf("raw image data is null and return!\n");
return -1;
}
static int64_t frameIndex =0;
m_avPacket->id = frameIndex ++;
m_avPacket->pts = pts;
int32_t frameUint = encode_param_.srcW * encode_param_.srcH ;
m_avPacket->dataLen0 = frameUint;
m_avPacket->dataLen1 = frameUint/2;
memcpy(m_avPacket->pAddrVir0 , buff,frameUint*1.5);
// memcpy(m_avPacket->pAddrVir1 , buff+frameUint,frameUint/2);
int32_t ret = p_encoder_->encode(m_avPacket);
LOGI("encode input pts:%d , index:%d result:%d", buffSize, pts, m_avPacket->id,ret);
}
替换使用新的接口, 编码第二帧数据的时候, 编码器内部一直提示一下错误
ERROR : cedarc <ReturnOneAllocateInputBuffer:424>: this buffer isn't allocate buffer,can't return
ERROR : cedarc <ReturnOneAllocInputBuffer:390>: ReturnOneAllocInputBuffer failed
根据提示信息大意为未分配内存. 但实际输入的avpacket已经正常分配内存. 这个问题是SDKbug? 还是外部接口调用需要修改?