I'm working on a smooth 60 FPS 1080p (Full HD) video transfer application that encodes in x264, sends the encoded data via LAN to a receiving device, which then decodes it using the OpenH264's decoder. I managed to get it working, and it works fine and is stable, but I found it to be very slow (around 20 FPS as opposed to the desired 60 FPS).
I did extensive testing and found that the issue lies with the OpenH264 decoder.
The decoder makes use of a full core (25% CPU usage total) of my i5-2500 @ 3.9Ghz, which is way too high. Even though the decoder is single-threaded, I tested the raw data on a Media Player Classic, and its playback (at 60 FPS) resulted in mere 0.3% CPU usage. (When switching the render engine to 'Old Video Render' it increased to 12.8-14.4% CPU usage--see comments)
So my question is: What optimizations can I do to speed up the decoding process and what am I doing wrong? I can't possibly imagine OpenH264 is just this slow.
Below is all the C++ code related to the decoder:
ISVCDecoder *decoder;
SBufferInfo bufferInfo;
SDecodingParam decodingParam;
uint8_t** yuvData;
void init(int width, int height) {
WelsCreateDecoder(&decoder);
decodingParam = { 0 };
decodingParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_AVC;
decoder->Initialize(&decodingParam);
bufferInfo = { 0 };
yuvData = new uint8_t*[3];
yuvData[0] = new uint8_t[width*height];
yuvData[1] = new uint8_t[width*height / 4];
yuvData[2] = new uint8_t[width*height / 4];
}
bool decode(cont unsigned char* rawEncodedData, int rawEncodedDataLength, uint8_t** yuvData) {
int err = decoder->DecodeFrameNoDelay(rawEncodedData, rawEncodedDataLength, yuvData, &bufferInfo);
if(err != 0) {
std::cout << "H264 decoding failed. Error code: " << err << "." << std::endl;
return false;
}
return true;
}
A relatively un-optimized CPU based H.264 decoder can easily be that slow. If you are on a PC and you have a hardware H.264 decoder - you might as well use it.
I'd try: https://software.intel.com/en-us/media-sdk-support/code-samples
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With