How to transmit H.264 video over UDP using the NVidia NVEnc hardware encoder?

This will be the question that answered the question, because it turned me on for the whole week, and I want to save my programmers from the disappointment that I experienced.

The situation is this: you want to use the NVidia NVEnc hardware encoder (available on Kepler and Maxwell cards, i.e. GT (x) 7xx and GT (x) 9xx, respectively) to stream your graphics application over UDP. This is not a trivial way, but it can be very effective, because it bypasses the need to “load” frames from video memory into system memory before the encoding stage, since NVEnc has the ability to directly access video memory.

I already managed to do this job to generate the .h264 file by simply writing NVEnc output buffers to it, frame by frame. VLC had no problems playing such a file, except that the time was turned off (I did not try to fix it, since I only need this file for debugging).

The problem arose when I tried to transmit encoded frames over UDP: neither VLC nor MPlayer could display the video. It turned out that there are two reasons for this, which I will explain in my answer.

+4
source share
1 answer

As I said in this question, there were two (well, basically, three) reasons why MPlayer could not play my UDP stream.

. NVEnc , NALU, " ", . ( szatmary's SO, B - AVCC).

, NVEnc NALU . NALU , ( ) , , .. NVEnc , NALU ( ).

, , , NALU UDP. , , ( "0" , "1" ), NALU UDP-. ( , , UDP- .)

, IP- . , SO , . , , , NVEnc "" , encoder:

m_stEncodeConfig.encodeCodecConfig.h264Config.sliceMode = 1;
m_stEncodeConfig.encodeCodecConfig.h264Config.sliceModeData = 1500 - 28;

( m_stEncodeConfig , NvEncInitializeEncoder(), 1500 - MTU Ethernet-, 28 - IP4 UDP-).

, MPlayer , , . H.264, NALU , , .., , , . , .

: , NVEnc NALU . , :

m_stEncodeConfig.encodeCodecConfig.h264Config.repeatSPSPPS = 1;

NVEnc SAL/PPS NALU ( , , IDR).

! , .

EDIT: , - UDP , . Mplayer , VLC, , . , , ( - ). , , .

+7

Source: https://habr.com/ru/post/1612040/


All Articles