I have some code which uses the NVIDIA CUDA Video Encoder (NVCUENC) to do H.264 encoding of video frames captured from one of many software sources and sends the encoded frames to a player over the network. I have this more-or-less working with NVCUENC along with other software and hardware encoders, but I’m having difficulty with rate control settings when using the CUDA encoder (as summarized by the title). Specifically, I have code which looks like this:
// We tweak quality setting of P frames dynamically to adjust bandwidth of stream.
int qp_level = get_new_qp_level();
if( qp_level != m_qp_level )
{
m_qp_level = qp_level;
if( FAILED( NVSetParamValue( m_encoder, NVVE_QP_LEVEL_INTER_P, &m_qp_level ) ) )
throw exception("Unable to set frame quality parameter for P frames." );
//if( FAILED( NVCreateHWEncoder( m_encoder ) ) )
// throw exception( "Encoder: Failed to re-create Nvidia HW encoder." );
}
The commented out code which recreates the encoder is the main issue. Without recreating the encoder, I don’t see any effect from my attempt to dynamically change the rate control between P frames. When I recreate the encoder, it starts over with a new I frame, which in turn requires far more bandwidth than a P frame, thus defeating the purpose of using the encoder.
Has anyone else done something similar and got it working? Is there a way to ensure that the encoder changes the QP setting without recreating it?
Thanks!