本文來源電子發燒友社區,作者:羈傲不馴, 帖子地址:https://bbs.elecfans.com/jishu_2306118_1_1.html
兩個輸出節點規格分別如下上節介紹了RK平臺下的rockit視頻處理接口的簡單介紹,本期就針對rockit的一些簡單介紹和理念作以具體的介紹。
需要明確一點的是在ARM中的視頻處理鏈路?什么是鏈路?ARM中視頻是怎么樣的?
這些基礎我們以后再談,相信做過驅動適配的朋友都知道,各個廠家都有各個廠家的玩法,接口也不盡相同,還需要不斷兼容向上提供接口。
rockit充分分離了這一點,他將我們所有的設備全部抽離出來,將每一個單獨的功能都能使用一個類來進行使用。
本章節就介紹下rockit的 vi 與 venc模塊,視頻輸入 與編碼
本節程序如下:
本節代碼基本上參考了官方的程序。
rockit使用的第一步首先是:RK_MPI_SYS_Init 初始化RK MPI系統。
之后進入vi系統,RK平臺下vi系統如下:
兩個輸出節點規格分別如下:
代碼大概流程如下:
TEST_VI_CTX_S *ctx;
ctx = reinterpret_cast(malloc(sizeof(TEST_VI_CTX_S)));
memset(ctx, 0, sizeof(TEST_VI_CTX_S));
ctx->width = 1920;
ctx->height = 1080;
ctx->devId = 0;
ctx->pipeId = ctx->devId;
ctx->channelId = 1;
ctx->loopCountSet = 100;
//0. get dev config status
s32Ret = RK_MPI_VI_GetDevAttr(ctx->devId, &ctx->stDevAttr);
if (s32Ret == RK_ERR_VI_NOT_CONFIG) {
//0-1.config dev
s32Ret = RK_MPI_VI_SetDevAttr(ctx->devId, &ctx->stDevAttr);
if (s32Ret != RK_SUCCESS) {
ctx->stChnAttr.stSize.u32Height = ctx->height;
s32Ret = RK_MPI_VI_SetChnAttr(ctx->pipeId, ctx->channelId, &ctx->stChnAttr);
if (s32Ret != RK_SUCCESS) {
RK_LOGE("RK_MPI_VI_SetChnAttr %x", s32Ret);
goto __FAILED2;
} /
/3.enable channel
s32Ret = RK_MPI_VI_EnableChn(ctx->pipeId, ctx->channelId);
if (s32Ret != RK_SUCCESS) {
RK_LOGE("RK_MPI_VI_EnableChn %x", s32Ret);
goto __FAILED2;
} /
/4.save debug file
if (ctx->stDebugFile.bCfg) {
s32Ret = RK_MPI_VI_ChnSaveFile(ctx->pipeId, ctx->channelId, &ctx->stDebugFile);
RK_LOGE("RK_MPI_VI_ChnSaveFile %x", s32Ret);
}
while (loopCount < ctx->loopCountSet) {
//5.get the frame
s32Ret = RK_MPI_VI_GetChnFrame(ctx->pipeId, ctx->channelId, &ctx->stViFrame,waitTime);
if (s32Ret == RK_SUCCESS) {
void *data = RK_MPI_MB_Handle2VirAddr(ctx->stViFrame.pMbBlk);
//6.get the channel status
s32Ret = RK_MPI_VI_QueryChnStatus(ctx->pipeId, ctx->channelId, &ctx->stChnStatus);
//7.release the frame
s32Ret = RK_MPI_VI_ReleaseChnFrame(ctx->pipeId, ctx->channelId, &ctx-
>stViFrame);
if (s32Ret != RK_SUCCESS) {
RK_LOGE("RK_MPI_VI_ReleaseChnFrame fail %x", s32Ret);
} l
oopCount ++;
} else {
RK_LOGE("RK_MPI_VI_GetChnFrame timeout %x", s32Ret);
} u
sleep(10*1000);
} /
/8. disable one chn
s32Ret = RK_MPI_VI_DisableChn(ctx->pipeId, ctx->channelId);
RK_LOGE("RK_MPI_VI_DisableChn %x", s32Ret);
//9.disable dev(will diabled all chn)
__FAILED2:
s32Ret = RK_MPI_VI_DisableDev(ctx->devId);
RK_LOGE("RK_MPI_VI_DisableDev %x", s32Ret);
除了單獨使用VI設備之外,VI設備還可以與其流程中關聯的設備進行綁定,如VO、VENC,這樣就不用在代碼的流程中進行圖像采集到內存,從內存在拷貝到其他設備中。關聯的方式如下:
- RK_MPI_SYS_Bind
我的test程序就將這個接口關聯到了VENC模塊中,可以直接進行視頻的編碼。實現如下:
// bind vi to venc
stSrcChn.enModId = RK_ID_VI;
stSrcChn.s32DevId = ctx->devId;
stSrcChn.s32ChnId = ctx->channelId;
stDestChn[i].enModId = RK_ID_VENC;
stDestChn[i].s32DevId = i;
stDestChn[i].s32ChnId = ctx->stVencCfg[i].s32ChnId;
s32Ret = RK_MPI_SYS_Bind(&stSrcChn, &stDestChn[i]);
if (s32Ret != RK_SUCCESS) {
RK_LOGE("create %d ch venc failed", ctx->stVencCfg[i].s32ChnId);
goto __FAILED2;
}
最終實現了可以將攝像頭直接采集編碼到H264文件中,可以使用播放器來打開啦。
-
RK3568
+關注
關注
5文章
584瀏覽量
6382 -
開發板試用
+關注
關注
3文章
302瀏覽量
2400
發布評論請先 登錄
【HZ-RK3568開發板免費體驗】HZ-RK3568開發板初步接觸
【HZ-RK3568開發板免費體驗】01 開箱+環境搭建+系統燒錄升級
一文掌握RK3568開發板Android13掛載Windows共享目錄

RK3568開發板教程:以iTOP-RK3568開發板為例 Android13通過CIFS協議掛載Windows共享目錄

正式發布 | 啟揚RK3568開發板已成功適配OpenHarmony4.0版本

瑞芯微RK3568開發板Linux編譯報錯404怎么辦?觸覺智能教你輕松解決

評論