通过网络OpenH264解码H264流

时间:2018-02-20 10:41:14

标签: c++ gstreamer h.264 openh264

我遇到OpenH264库https://github.com/cisco/openh264

的问题

我想在我的C ++ / Qt程序中解析我的覆盆子pi相机通过网络发送的流,这将显示图像。

我在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 ++& amp; 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

我不知道我做错了什么...我应该更改树莓派的一些参数吗?

感谢您的帮助。

0 个答案:

没有答案