|
【Linux】
关于rkmeida音视频合成的问题
发表于 2022-1-13 09:14:45
浏览:4784
|
回复:1
打印
只看该作者
[复制链接]
楼主
根据例程写的音视频合成功能,发现进入接口后就挂了。
打印消息如下
### muxer_event_cb: Handle:0x499e5c, event:0x8ae989dc
@@@ muxer_event_cb: ModeID:19, ChnID:0, EventType:2, filename:/data/work/avi/muxer_test_1.mp4, value:30
[RKMEDIA][SYS][Info]:Ready to recod new video file path:[/data/work/avi/muxer_test_1.mp4]
mpp[675]: h264e_sps: set level to 3.2
大佬能看出什么问题么,看了好几遍,例程对了好几遍,感觉也没错呀~
代码如下:
void muxer_event_cb(RK_VOID *pHandle, RK_VOID *pstEvent) {
RK_S32 s32ModeIdx = -1;
RK_S32 s32ChnIdx = -1;
printf("### %s: Handle:%p, event:%p\n", __func__, pHandle, pstEvent);
if (pHandle) {
MuxerHandle *pstMuxerHandle = (MuxerHandle *)pHandle;
s32ModeIdx = (RK_S32)pstMuxerHandle->u32ModeIdx;
s32ChnIdx = (RK_S32)pstMuxerHandle->u32ChnIdx;
}
if (pstEvent) {
MUXER_EVENT_INFO_S *pstMuxerEvent = (MUXER_EVENT_INFO_S *)pstEvent;
printf("@@@ %s: ModeID:%d, ChnID:%d, EventType:%d, filename:%s, value:%d\n",
__func__, s32ModeIdx, s32ChnIdx, pstMuxerEvent->enEvent,
pstMuxerEvent->unEventInfo.stFileInfo.asFileName,
(int)pstMuxerEvent->unEventInfo.stFileInfo.u32Duration);
}
}
camera_thread::camera_thread(QObject *parent)
{
frame = new Video_Frame;
flag =true;
char *iq_dir = "/etc/iqfiles";
video_width = 1920;
video_height = 1080;
if (SCREEN_FLAG == INCHES_7)
{
disp_width = 1024;
disp_height = 600;
}else if(SCREEN_FLAG == INCHES_8)
{
disp_width = 1280;
disp_height = 800;
}
#if RGA
//RGB
ret = SAMPLE_COMM_ISP_Init(0, RK_AIQ_WORKING_MODE_NORMAL, RK_TRUE, iq_dir);
if (ret)
return ;
SAMPLE_COMM_ISP_Run(0);
SAMPLE_COMM_ISP_SET_Contrast(0, 110);//亮度
SAMPLE_COMM_ISP_SetFrameRate(0, 30);
#endif
RK_MPI_SYS_Init();
#if RGA
memset(&vi_chn_attr, 0, sizeof(vi_chn_attr));
vi_chn_attr.pcVideoNode = "rkispp_scale0";
vi_chn_attr.u32BufCnt = 4;
vi_chn_attr.u32Width = video_width;
vi_chn_attr.u32Height = video_height;
vi_chn_attr.enPixFmt = IMAGE_TYPE_NV12;
vi_chn_attr.enWorkMode = VI_WORK_MODE_NORMAL;
vi_chn_attr.enBufType = VI_CHN_BUF_TYPE_MMAP;
ret = RK_MPI_VI_SetChnAttr(1, 1, &vi_chn_attr);
ret |= RK_MPI_VI_EnableChn(1, 1);
if (ret) {
printf("Create vi[1] failed! ret=%d\n", ret);
return ;
}
#endif
#if RGA
memset(&stRgaAttr, 0, sizeof(stRgaAttr));
stRgaAttr.bEnBufPool = RK_TRUE;
stRgaAttr.u16BufPoolCnt = 4;
//stRgaAttr.u16Rotaion = 0;
stRgaAttr.u16Rotaion = 90;
stRgaAttr.stImgIn.u32X = 0;
stRgaAttr.stImgIn.u32Y = 0;
stRgaAttr.stImgIn.imgType = IMAGE_TYPE_NV12;
stRgaAttr.stImgIn.u32Width = video_width;
stRgaAttr.stImgIn.u32Height = video_height;
stRgaAttr.stImgIn.u32HorStride = video_width;
stRgaAttr.stImgIn.u32VirStride = video_height;
stRgaAttr.stImgOut.u32X = 0;
stRgaAttr.stImgOut.u32Y = 0;
stRgaAttr.stImgOut.imgType = IMAGE_TYPE_NV12;
stRgaAttr.stImgOut.u32Width = disp_height;
stRgaAttr.stImgOut.u32Height = disp_width;
stRgaAttr.stImgOut.u32HorStride = disp_height;
stRgaAttr.stImgOut.u32VirStride = disp_width;
ret = RK_MPI_RGA_CreateChn(2, &stRgaAttr);
if (ret) {
printf("Create rga[0] falied! ret=%d\n", ret);
return ;
}
#endif
#if RGA
//90 recogize RGA
stSrcChn.enModId = RK_ID_VI;
stSrcChn.s32DevId = 1;
stSrcChn.s32ChnId = 1;
stDestChn.enModId = RK_ID_RGA;
stDestChn.s32DevId = 0;
stDestChn.s32ChnId = 2;
ret = RK_MPI_SYS_Bind(&stSrcChn, &stDestChn);
if (ret) {
printf("Bind vi[0] to rga[0] failed! ret=%d\n", ret);
return;
}
#if 1
memset(&venc_chn_attr, 0, sizeof(venc_chn_attr));
venc_chn_attr.stVencAttr.enType = RK_CODEC_TYPE_H264;
venc_chn_attr.stRcAttr.enRcMode = VENC_RC_MODE_H264CBR;
venc_chn_attr.stRcAttr.stH264Cbr.u32Gop = 30;
venc_chn_attr.stRcAttr.stH264Cbr.u32BitRate = video_width * video_height;
// frame rate: in 30/1, out 30/1.
venc_chn_attr.stRcAttr.stH264Cbr.fr32DstFrameRateDen = 1;
venc_chn_attr.stRcAttr.stH264Cbr.fr32DstFrameRateNum = 30;
venc_chn_attr.stRcAttr.stH264Cbr.u32SrcFrameRateDen = 1;
venc_chn_attr.stRcAttr.stH264Cbr.u32SrcFrameRateNum = 30;
venc_chn_attr.stVencAttr.imageType = IMAGE_TYPE_NV12;
venc_chn_attr.stVencAttr.u32PicWidth = disp_height;
venc_chn_attr.stVencAttr.u32PicHeight = disp_width;
venc_chn_attr.stVencAttr.u32VirWidth = disp_height;
venc_chn_attr.stVencAttr.u32VirHeight = disp_width;
venc_chn_attr.stVencAttr.u32Profile = 100;
ret = RK_MPI_VENC_CreateChn(0, &venc_chn_attr);
if (ret) {
printf("ERROR: create VENC[0] error! ret=%d\n", ret);
// return 0;
}
stSrcChn.enModId = RK_ID_RGA;
stSrcChn.s32DevId = 0;
stSrcChn.s32ChnId = 2;
stDestChn.enModId = RK_ID_VENC;
stDestChn.s32DevId = 0;
stDestChn.s32ChnId = 0;
ret = RK_MPI_SYS_Bind(&stSrcChn, &stDestChn);
if (ret) {
printf("Bind rga[0] to vo[0] failed! ret=%d\n", ret);
return ;
}
RK_CHAR *pAudioDevice = "default";
SAMPLE_FORMAT_E enSampleFmt = RK_SAMPLE_FMT_FLTP;
RK_U32 u32FrameCnt = 1024; // always 1024 for mp3
RK_U32 u32SampleRate = 16000;
RK_U32 u32ChnCnt = 2;
RK_U32 u32BitRate = 64000; // 64kbps
CODEC_TYPE_E enCodecType = RK_CODEC_TYPE_H264;
/************************************************
* Create Audio pipeline: AI[0] --> AENC[0]
* **********************************************/
// Create AI
// AI_CHN_ATTR_S ai_attr;
ai_attr.pcAudioNode = pAudioDevice;
ai_attr.enSampleFormat = enSampleFmt;
ai_attr.u32NbSamples = u32FrameCnt;
ai_attr.u32SampleRate = u32SampleRate;
ai_attr.u32Channels = u32ChnCnt;
ai_attr.enAiLayout = AI_LAYOUT_NORMAL;
ret = RK_MPI_AI_SetChnAttr(0, &ai_attr);
ret |= RK_MPI_AI_EnableChn(0);
if (ret) {
printf("Create AI[0] failed! ret=%d\n", ret);
// return -1;
}
// Create AENC
// AENC_CHN_ATTR_S aenc_attr;
aenc_attr.enCodecType = RK_CODEC_TYPE_AAC;
aenc_attr.u32Bitrate = u32BitRate;
aenc_attr.u32Quality = 1;
aenc_attr.stAencAAC.u32Channels = u32ChnCnt;
aenc_attr.stAencAAC.u32SampleRate = u32SampleRate;
ret = RK_MPI_AENC_CreateChn(0, &aenc_attr);
if (ret) {
printf("Create AENC[0] failed! ret=%d\n", ret);
// return -1;
}
/************************************************
* Create MediaMuxer:
* VENC[0]----->|----------|
* | MUXER[0] |
* AENC[0]----->|----------|
* **********************************************/
// MUXER_CHN_ATTR_S stMuxerAttr;
memset(&stMuxerAttr, 0, sizeof(stMuxerAttr));
//stMuxerAttr.u32MuxerId = 0;
stMuxerAttr.enMode = MUXER_MODE_AUTOSPLIT;
stMuxerAttr.enType = MUXER_TYPE_MP4;
stMuxerAttr.stSplitAttr.enSplitType = MUXER_SPLIT_TYPE_TIME;
stMuxerAttr.stSplitAttr.u32TimeLenSec = 30;
// printf("#MuxerTest: use split name callback type, cb:%p, handle:%p...\n",GetRecordFileName, &gu32FileIdx);
// stMuxerAttr.stSplitAttr.enSplitNameType = MUXER_SPLIT_NAME_TYPE_CALLBACK;
// stMuxerAttr.stSplitAttr.stNameCallBackAttr.pcbRequestFileNames =GetRecordFileName;
// stMuxerAttr.stSplitAttr.stNameCallBackAttr.pCallBackHandle =(RK_VOID *)&gu32FileIdx;
#if 1
printf("#MuxerTest: use split name auto type...\n");
stMuxerAttr.stSplitAttr.enSplitNameType = MUXER_SPLIT_NAME_TYPE_AUTO;
stMuxerAttr.stSplitAttr.stNameAutoAttr.pcPrefix = "muxer_test";
stMuxerAttr.stSplitAttr.stNameAutoAttr.pcBaseDir = "/data/work/avi";
// Split File name with timestamp.
stMuxerAttr.stSplitAttr.stNameAutoAttr.bTimeStampEnable = RK_TRUE;
stMuxerAttr.stSplitAttr.stNameAutoAttr.u16StartIdx = 1;
#endif
stMuxerAttr.stVideoStreamParam.enCodecType = enCodecType;
stMuxerAttr.stVideoStreamParam.enImageType = IMAGE_TYPE_NV12;
stMuxerAttr.stVideoStreamParam.u16Fps = 30;
stMuxerAttr.stVideoStreamParam.u16Level = 41; // for h264
stMuxerAttr.stVideoStreamParam.u16Profile = 100; // for h264
stMuxerAttr.stVideoStreamParam.u32BitRate = disp_width * disp_height;
stMuxerAttr.stVideoStreamParam.u32Width = disp_width;
stMuxerAttr.stVideoStreamParam.u32Height = disp_height;
stMuxerAttr.stAudioStreamParam.enCodecType = RK_CODEC_TYPE_AAC;
stMuxerAttr.stAudioStreamParam.enSampFmt = enSampleFmt;
stMuxerAttr.stAudioStreamParam.u32Channels = u32ChnCnt;
stMuxerAttr.stAudioStreamParam.u32NbSamples = u32FrameCnt;
stMuxerAttr.stAudioStreamParam.u32SampleRate = u32SampleRate;
ret = RK_MPI_MUXER_EnableChn(0, &stMuxerAttr);
if (ret) {
printf("Create MUXER[0] failed! ret=%d\n", ret);
}
// MPP_CHN_S stSrcChn;
// MPP_CHN_S stDestChn;
// MUXER_CHN_S stMuxerChn;
stSrcChn.enModId = RK_ID_MUXER;
stSrcChn.s32DevId = 0;
stSrcChn.s32ChnId = 0;
// MuxerHandle stMuxerHandle;
stMuxerHandle.u32ChnIdx = 0;
stMuxerHandle.u32ModeIdx = RK_ID_MUXER;
ret = RK_MPI_SYS_RegisterEventCb(&stSrcChn, &stMuxerHandle, muxer_event_cb);
if (ret) {
printf("Register event callback failed! ret=%d\n", ret);
// return -1;
}
ret = RK_MPI_MUXER_StreamStart(0);
printf("### Start muxer stream...\n");
// Bind VENC[0] to MUXER[0]:AUDIO
stSrcChn.enModId = RK_ID_VENC;
stSrcChn.s32DevId = 0;
stSrcChn.s32ChnId = 0;
stMuxerChn.enModId = RK_ID_MUXER;
stMuxerChn.enChnType = MUXER_CHN_TYPE_VIDEO;
stMuxerChn.s32ChnId = 0;
ret = RK_MPI_MUXER_Bind(&stSrcChn, &stMuxerChn);
if (ret) {
printf("ERROR: Bind VENC[0] and MUXER[0]:VIDEO error! ret=%d\n", ret);
// return 0;
}
stSrcChn.enModId = RK_ID_AENC;
stSrcChn.s32DevId = 0;
stSrcChn.s32ChnId = 0;
stMuxerChn.enModId = RK_ID_MUXER;
stMuxerChn.enChnType = MUXER_CHN_TYPE_AUDIO;
stMuxerChn.s32ChnId = 0;
ret = RK_MPI_MUXER_Bind(&stSrcChn, &stMuxerChn);
if (ret) {
printf("ERROR: Bind AENC[0] and MUXER[0]:AUDIO error! ret=%d\n", ret);
// return 0;
}
stSrcChn.enModId = RK_ID_AI;
stSrcChn.s32DevId = 0;
stSrcChn.s32ChnId = 0;
stDestChn.enModId = RK_ID_AENC;
stDestChn.s32DevId = 0;
stDestChn.s32ChnId = 0;
ret = RK_MPI_SYS_Bind(&stSrcChn, &stDestChn);
if (ret) {
printf("ERROR: Bind AI[0] and AENC[0] error! ret=%d\n", ret);
// return 0;
}
//
#endif
} |
|