介紹
在有些應(yīng)用中,發(fā)現(xiàn)I幀不夠大。MPSoC VCU CtrlSW可以設(shè)置每一幀的QP大小。因此,可以通過設(shè)置I幀的QP,提高I幀的大小,從而提高I幀的質(zhì)量。
代碼
下面是設(shè)置I幀的QP的示例代碼。
GOP長度變量
在struct EncoderSink : IFrameSink的定義里添加GOP的成員變量,記錄GOP長度。
#if USER_I_FRAME_QP
// USER_I_FRAME_QP changes START
float uFrameRate = 0.0f;
int uGopLength = 0;
// USER_I_FRAME_QP changes END
#endif // USER_I_FRAME_QP
記錄GOP長度
在EncoderSink 的EncoderSink函數(shù)設(shè)置GOP的變量的值。
struct EncoderSink : IFrameSink { EncoderSink(ConfigFile const& cfg, AL_IEncScheduler* pScheduler, AL_TAllocator* pAllocator ) : CmdFile(cfg.sCmdFileName, false), EncCmd(CmdFile.fp, cfg.RunInfo.iScnChgLookAhead, cfg.Settings.tChParam[0].tGopParam.uFreqLT), twoPassMngr(cfg.sTwoPassFileName, cfg.Settings.TwoPass, cfg.Settings.bEnableFirstPassSceneChangeDetection, cfg.Settings.tChParam[0].tGopParam.uGopLength, cfg.Settings.tChParam[0].tRCParam.uCPBSize / 90, cfg.Settings.tChParam[0].tRCParam.uInitialRemDelay / 90, cfg.MainInput.FileInfo.FrameRate), qpBuffers{cfg.Settings, cfg.RunInfo.eGenerateQpMode}, pAllocator{pAllocator}, pSettings{&cfg.Settings} { #if USER_I_FRAME_QP // USER_I_FRAME_QP changes STARTED ---------------------------------- uFrameRate = cfg.Settings.tChParam.tRCParam.uFrameRate; uGopLength = cfg.Settings.tChParam.tGopParam.uGopLength; // USER_I_FRAME_QP changes END -------------------------------------- #endif // USER_I_FRAME_QP }
設(shè)置QP
在EncoderSink 的ProcessFrame函數(shù)里,根據(jù)GOP長度,確定每個GOP開始的I幀。然后再設(shè)置QP的值??梢栽囋?0-35之間的QP值。QP值是20時,能帶來很好的圖像質(zhì)量。
void ProcessFrame(AL_TBuffer* Src) override
{
if(m_picCount == 0)
m_StartTime = GetPerfTime();
if(!Src)
{
LogVerbose("Flushing...
");
if(!AL_Encoder_Process(hEnc, nullptr, nullptr))
throw std::runtime_error("Failed");
return;
}
DisplayFrameStatus(m_picCount);
if(twoPassMngr.iPass)
{
auto pPictureMetaTP = AL_TwoPassMngr_CreateAndAttachTwoPassMetaData(Src);
if(twoPassMngr.iPass == 2)
twoPassMngr.GetFrame(pPictureMetaTP);
}
AL_TBuffer* QpBuf = qpBuffers.getBuffer(m_picCount);
std::shared_ptr QpBufShared(QpBuf, [&](AL_TBuffer* pBuf) { qpBuffers.releaseBuffer(pBuf); });
if(pSettings->hRcPluginDmaContext != NULL)
RCPlugin_SetNextFrameQP(pSettings, pAllocator);
#if USER_I_FRAME_QP
if( 0 == (m_picCount%uGopLength) )
{
AL_Encoder_SetQP(hEnc, 20 );
}
#endif // USER_I_FRAME_QP
if(!AL_Encoder_Process(hEnc, Src, QpBuf))
throw std::runtime_error("Failed");
m_picCount++;
m_picGopCount++;
}
責(zé)任編輯:haq
-
代碼
+關(guān)注
關(guān)注
30文章
4977瀏覽量
74420 -
變量
+關(guān)注
關(guān)注
0文章
616瀏覽量
29574
原文標題:設(shè)置I幀的QP,提高I幀的質(zhì)量
文章出處:【微信號:FPGA-EETrend,微信公眾號:FPGA開發(fā)圈】歡迎添加關(guān)注!文章轉(zhuǎn)載請注明出處。
發(fā)布評論請先 登錄
EtherCAT應(yīng)用示例,GOAL 應(yīng)用說明
200W 四輸出 PFC 電源:QP - 200 系列揭秘
探索 QP - 150 系列 150W 四輸出電源:特性、規(guī)格與應(yīng)用考量
基于Matter over Thread的照明應(yīng)用示例簡要設(shè)置步驟
TE Connectivity推出QP 6.5多色電源連接器
中穎電子8位單片機的I/O設(shè)置介紹
MCU軟件核心庫及示例代碼速覽 !
基于芯源CW32 MCU的LED閃爍示例及代碼分析
淘寶京東API商品詳情接口示例參考
淘寶拍立淘接口實戰(zhàn):圖像優(yōu)化、識別調(diào)優(yōu)與避坑代碼示例
如何使用20829 can-fd發(fā)送64字節(jié)擴展標識符數(shù)據(jù)幀?
CYW20721如何在A2DP接收器中更改I2S時鐘設(shè)置?
NXP i.MX RT1060移植TinyUSB:快速擴展大量USB Class示例
設(shè)置I幀的QP的示例代碼
評論