我正面临 OpenH264 库https://github.com/cisco/openh264的问题
我想在我的 C++/Qt 程序上解码我的树莓派相机通过网络发送的流,这将显示图像。
我在 Raspberry Side 上使用 gstreamer 使用以下命令行发送流:
raspivid -n -t 0 -w 1280 -h 720 -fps 25 -b 2500000 -o - | gst-launch-1.0 fdsrc ! h264parse ! rtph264pay config-interval=1 pt=96 ! gdppay ! tcpserversink host=my_ip port=5000
当我执行时在桌面端:
gst-launch-1.0 -v tcpclientsrc host=raspberry_ip port=5000 ! gdpdepay ! rtph264depay ! avdec_h264 ! videoconvert ! autovideosink sync=false
我能够正确地看到相机的流。
好的,那么现在。我想使用 QT/C++ 和 OpenH264 解码器制作自己的解码器。
这是我的代码:
void Manager::initDecoder(int width, int height) {
long ret = WelsCreateDecoder(&(this->decoder));
if (ret == 0) {
this->decodingParam = { 0 };
this->decodingParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;
this->decoder->Initialize(&decodingParam);
this->bufferInfo = { 0 };
this->yuvData = new uint8_t*[3];
this->yuvData[0] = new uint8_t[width * height];
this->yuvData[1] = new uint8_t[width * height / 4];
this->yuvData[2] = new uint8_t[width * height / 4];
this->tcpSocket->connectToHost("ip_raspberry", 5000);
}
}
bool Manager::decodeStream(const unsigned char *rawEncodedData, const int rawEncodedDataLength, uint8_t **yuvData) {
DECODING_STATE err = decoder->DecodeFrame2(rawEncodedData, rawEncodedDataLength, yuvData, &bufferInfo);
if (err != 0) {
qDebug() << "H264 decoding failed. Error code: " << err << ".";
return false;
}
qDebug() << "----------- Succeedeeed --------------";
return true;
}
当我得到一个新数据时,我调用decodeStream
但这个函数返回一个错误:
dsBitstreamError = 0x04, ///< error bitstreams(maybe broken internal frame) the decoder cared
dsNoParamSets = 0x10, ///< no parameter set NALs involved
我不知道我做错了什么...我应该更改树莓派发送的一些参数吗?
感谢您的帮助。