关于rkmeida音视频合成的问题
根据例程写的音视频合成功能,发现进入接口后就挂了。打印消息如下
### 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
:Ready to recod new video file path:
mpp: 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 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 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 to rga 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 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 to vo 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 --> AENC
* **********************************************/
// 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 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 failed! ret=%d\n", ret);
//return -1;
}
/************************************************
* Create MediaMuxer:
* VENC----->|----------|
* | MUXER |
* AENC----->|----------|
* **********************************************/
// 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 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 to MUXER: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 and MUXER: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 and MUXER: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 and AENC error! ret=%d\n", ret);
// return 0;
}
//
#endif
} /mnt/work # ./rkmedia_muxer_test
media get entity by name: rkcif-lvds-subdev is null
media get entity by name: rkcif-lite-lvds-subdev is null
media get entity by name: rkisp-mpfbc-subdev is null
media get entity by name: rkisp_dmapath is null
media get entity by name: rockchip-mipi-dphy-rx is null
media get entity by name: rkisp-mpfbc-subdev is null
media get entity by name: rkisp_dmapath is null
:XCAM ERROR CamHwIsp20.cpp:928: No free isp&ispp needed by fake camera!
Rga built version:1.04 b62761c+2021-04-22 20:09:29
#Device: rkispp_scale0
#CodecName: H264
#Resolution: 1920x1080
#EnableCallback: -1
#CameraIdx: 0
#Aiq MultiCtx: 0
#Aiq XML Dir: (null)
##RKMEDIA Log level: 2
:text is all=2
:module is all, log_level is 2
:RK_MPI_VI_EnableChn: Enable VI:rkispp_scale0, 1920x1080 Start...
:RKAIQ: parsing /dev/media0
media get entity by name: rkcif-lvds-subdev is null
media get entity by name: rkcif-lite-lvds-subdev is null
:RKAIQ: parsing /dev/media1
media get entity by name: rkisp-mpfbc-subdev is null
media get entity by name: rkisp_dmapath is null
media get entity by name: rockchip-mipi-dphy-rx is null
:RKAIQ: model(rkisp0): isp_info(0): isp-subdev entity name: /dev/v4l-subdev5
:RKAIQ: parsing /dev/media2
media get entity by name: rkisp-mpfbc-subdev is null
media get entity by name: rkisp_dmapath is null
:RKAIQ: model(rkisp1): isp_info(1): isp-subdev entity name: /dev/v4l-subdev8
:RKAIQ: parsing /dev/media3
:RKAIQ: model(rkispp0): ispp_info(0): ispp-subdev entity name: /dev/v4l-subdev0
:RKAIQ: parsing /dev/media4
:RKAIQ: model(rkispp1): ispp_info(1): ispp-subdev entity name: /dev/v4l-subdev1
:#V4l2Stream: camraID:0, Device:rkispp_scale0
:camera_id: 0, chn: rkispp_scale0
:camera_id: 0, chn: rkispp_scale0, idx: 0
:#V4l2Stream: camera id:0, VideoNode:/dev/video31
Using mplane plugin for capture
:#V4L2Ctx: open /dev/video31, fd 5
:RK_MPI_VI_EnableChn: Enable VI:rkispp_scale0, 1920x1080 End...
:RK_MPI_VENC_CreateChn: Enable VENC, Type:6 Start...
mpp: mpp_rt: NOT found ion allocator
mpp: mpp_rt: found drm allocator
mpp: mpp_info: mpp version: 7ae6041 author: Yandong Lin 2021-02-21 : Support rotation for jpeg enc
:MPP Encoder: MPPConfig: cfg init sucess!
:MPP Encoder: qpMaxi use default value:48
:MPP Encoder: qpMini use default value:8
:MPP Encoder: qpMax use default value:48
:MPP Encoder: qpMin use default value:8
:MPP Encoder: qpInit use default value:-1
:MPP Encoder: qpStep use default value:2
:MPP Encoder: rotaion = 0
:MPP Encoder: automatically calculate bsp with bps_target
:MPP Encoder: Set output block mode.
:MPP Encoder: Set input block mode.
:MPP Encoder: bps: fps: ->, gop:30 qpInit:-1, qpMin:8, qpMax:48, qpMinI:8, qpMaxI:48.
:MPP Encoder: H264 profile use defalut value: 100:MPP Encoder: AVC: encode profile 100 level 0
mpp: mpp_enc: MPP_ENC_SET_RC_CFG bps 2073600 fps gop 30
mpp: h264e_api_v2: MPP_ENC_SET_PREP_CFG w:h stride
mpp: mpp_enc: send header for set cfg change input/format
:MPP Encoder: w x h(1920 x 1080)
mpp: mpp_enc: mode vbr bps fps fix -> fix gop i v
:RK_MPI_VENC_CreateChn: Enable VENC, Type:6 End...
:RK_MPI_AI_EnableChn: Enable AI Start...
:AlsaCaptureStream: Layout 0, output chan 2, alsa chan 2
:RK_MPI_AI_EnableChn: Enable AI End...
:av codec name=AAC (Advanced Audio Coding)
#MuxerTest: use split name callback type, cb:0x13118, handle:0x2a280...
:Muxer will use internal path
:Muxer will use default prefix
:Muxer will save video file per 30sec
:Muxer:: enable_streaming is 0
:Found video encode config!
:Found audio encode config!
:Muxer:: file_name_cb is 0x13118, file_name_handle is 0x2a280
### Start muxer stream...
### muxer_event_cb: Handle:0xaef0cb10, event:0xaeefc964
@@@ muxer_event_cb: ModeID:19, ChnID:0, EventType:0, filename:, value:0
:RK_MPI_MUXER_Bind: Bind Mode:Chn to Mode:Chn...
:RK_MPI_MUXER_Bind: Bind Mode:Chn to Mode:Chn...
:RK_MPI_SYS_Bind: Bind Mode:Chn to Mode:Chn...
:RK_MPI_SYS_Bind: Bind Mode:Chn to Mode:Chn...
main initial finish
#GetRecordFileName: Handle:0x2a280, idx:0 ...
#GetRecordFileName: NewRecordFileName:
### muxer_event_cb: Handle:0xaef0cb10, event:0x9f8daa6c
@@@ muxer_event_cb: ModeID:19, ChnID:0, EventType:2, filename:/userdata/MuxerCbTest_0.mp4, value:30
:Ready to recod new video file path:
ls
页:
[1]