cisco / openh264

Open Source H.264 Codec
BSD 2-Clause "Simplified" License
5.58k stars 1.8k forks source link

Error while decoding frame #2923

Closed AhmedX6 closed 1 year ago

AhmedX6 commented 6 years ago

would like to decode a stream sent by my my raspberry camera over network on my C++/Qt Program which will display the image.

I'm using gstreamer on Raspberry Side to send the stream with this command line :

raspivid -n -t 0 -w 1280 -h 720 -fps 25 -b 2500000 -o - | gst-launch-1.0 -v fdsrc ! h264parse ! rtph264pay config-interval=1 pt=96 ! gdppay ! tcpserversink host=my_ip port=5000 On desktop side when I execute :

gst-launch-1.0 -v tcpclientsrc host=raspberry_ip port=5000 ! gdpdepay ! rtph264depay ! avdec_h264 ! videoconvert ! autovideosink sync=false

I'm able to see the stream of the camera correctly.

Okay, so now. I would like to make my own decoder using QT/C++ & OpenH264 decoder.

Here is my code :

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;
}

When I get a new data I call decodeStream but this function is returning an error :

dsBitstreamError      = 0x04,   ///< error bitstreams(maybe broken internal frame) the decoder cared
  dsNoParamSets         = 0x10,   ///< no parameter set NALs involved

I don't know what I'm doing wrong... Should I change some parameters on the raspberry sending ? Or do I have a problem with the way I'm initializing the decoder or my decoding.. ?

Thanks for helping.

bo01ean commented 6 years ago

It looks like a keyframe I frame is not being sent ... or the receiver (your program) doesn't know where to look for one. You can tell raspivid to send one using -g 25 ( I frame every 25 frames)

https://raspberrypi.stackexchange.com/questions/54189/how-do-i-insert-key-frames-at-particular-times-with-picamera