尽管我对H.264编码非常熟悉,但我还是需要更多有经验的人提供建议。我在统一的管道中使用英特尔快速同步和NVIDIA NVENC进行硬件加速的H.264编码。困扰我的问题是比特流输出缓冲区大小。英特尔快速同步提供了一种从编码器查询最大比特流大小的方法,而NVDIA NVENC没有这样的功能(或者至少我没有找到它,欢迎使用指针)。在他们的教程中,他们说:
NVIDIA recommends setting the VBV buffer size equal to single frame size. This is very
helpful in low latency applications, where network bandwidth is a concern. Single frame
VBV allows users to enable capped frame size encoding. In single frame VBV, VBV
buffer size must be set to maximum frame size which is equal to channel bitrate divided
by frame rate. With this setting, every frame can be sent to client immediately upon
encoding and the decoder can also decode without any buffering.
For example, if you have a channel bitrate of B bits/sec and you are encoding at N fps,
the following settings are recommended to enable single frame VBV buffer size.
uint32_t maxFrameSize = B/N;
NV_ENC_RC_PARAMS::vbvBufferSize= maxFrameSize;
NV_ENC_RC_PARAMS::vbvInitialDelay= maxFrameSize;
NV_ENC_RC_PARAMS::maxBitRate= NV_ENC_CONFIG::vbvBufferSize *N; // where
N is the encoding frame rate.
NV_ENC_RC_PARAMS::averageBitRate=
NV_ENC_RC_PARAMS::vbvBufferSize *N; // where N is the encoding frame
rate.
NV_ENC_RC_PARAMS::rateControlMode= NV_ENC_PARAMS_RC_TWOPASS_CBR;
我正在为很多编码会话分配一个比特流缓冲池,因此通过计算网络带宽的大小(在我的情况下,它不是瓶颈),每个缓冲区的未使用内存开销将导致无效的内存使用。
所以一般的问题是 - 假设没有帧缓冲并且每个帧应该生成NAL单元,有没有办法如何确定H.264的比特流大小?我可以假设它永远不会大于输入NV12缓冲区(这似乎不可靠,因为第一帧可能有很多NAL单位,如SPS / PPS / AUD / SEI,我不确定那些加上相同的大小IDR帧的大小不大于NV12的缓冲区大小)?标准是否对此有任何指示?还是完全依赖编码器?