如何加速OpenH264的解码器

时间:2021-01-04 23:36:11

Story

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).

我正在开发一个光滑的60 FPS 1080p(全高清)视频传输应用程序,它在x264中编码,通过LAN将编码数据发送到接收设备,然后使用OpenH264的解码器对其进行解码。我设法让它工作,它工作得很好而且稳定,但是我发现它非常慢(大约20个FPS,而不是期望的60个FPS)。

Problem

I did extensive testing and found that the issue lies with the OpenH264 decoder.

我做了大量的测试,发现问题在于OpenH264解码器。

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)

解码器使用了我的i5-2500的全核(25%的CPU使用率)@ 3.9Ghz,这太高了。尽管解码器是单线程的,我还是在媒体播放器Classic上测试了原始数据,它的回放(60帧/秒)只使用了0.3%的CPU。(当将渲染引擎切换到“老视频渲染”时,CPU使用率增加到12.8-14.4%——请参阅注释)

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.

所以我的问题是:我能做哪些优化来加快解码过程,我做错了什么?我无法想象OpenH264是这么慢。

Extra Info

  • The encoder is easily able to push out 60 FPS 1080p using about 20% CPU.
  • 编码器很容易推出60 FPS 1080p使用大约20%的CPU。
  • The connection is wired LAN and can push > 10MB/s, so no problem there.
  • 连接是有线局域网,可以按> 10MB/s,所以没有问题。
  • Both sender and receiver PCs have 8GB RAM.

  • 发送端和接收端pc都有8GB RAM。

Code

Below is all the C++ code related to the decoder:

下面是与解码器相关的所有c++代码:

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

1 个解决方案

#1


1  

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.

基于H.264的非优化CPU译码器很容易就会这么慢。如果你是在PC上,并且你有一个硬件H.264解码器-你不妨使用它。

I'd try: https://software.intel.com/en-us/media-sdk-support/code-samples

我尝试:https://software.intel.com/en-us/media-sdk-support/code-samples

#1


1  

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.

基于H.264的非优化CPU译码器很容易就会这么慢。如果你是在PC上,并且你有一个硬件H.264解码器-你不妨使用它。

I'd try: https://software.intel.com/en-us/media-sdk-support/code-samples

我尝试:https://software.intel.com/en-us/media-sdk-support/code-samples