Firefly开源社区

打印 上一主题 下一主题

[Linux] 关于rkmeida音视频合成的问题

74

积分

0

威望

0

贡献

技术小白

积分
74

关于rkmeida音视频合成的问题

发表于 2022-1-13 09:14:45      浏览:4780 | 回复: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
}
回复

使用道具 举报

74

积分

0

威望

0

贡献

技术小白

积分
74
发表于 2022-1-13 13:53:42        只看该作者  沙发
/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
[13:49:44.636429][CAMHW]: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
[RKMEDIA][SYS][Info]:text is all=2
[RKMEDIA][SYS][Info]:module is all, log_level is 2
[RKMEDIA][SYS][Info]:RK_MPI_VI_EnableChn: Enable VI[0:0]:rkispp_scale0, 1920x1080 Start...
[RKMEDIA][SYS][Info]: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
[RKMEDIA][SYS][Info]: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
[RKMEDIA][SYS][Info]:RKAIQ: model(rkisp0): isp_info(0): isp-subdev entity name: /dev/v4l-subdev5
[RKMEDIA][SYS][Info]:RKAIQ: parsing /dev/media2
media get entity by name: rkisp-mpfbc-subdev is null
media get entity by name: rkisp_dmapath is null
[RKMEDIA][SYS][Info]:RKAIQ: model(rkisp1): isp_info(1): isp-subdev entity name: /dev/v4l-subdev8
[RKMEDIA][SYS][Info]:RKAIQ: parsing /dev/media3
[RKMEDIA][SYS][Info]:RKAIQ: model(rkispp0): ispp_info(0): ispp-subdev entity name: /dev/v4l-subdev0
[RKMEDIA][SYS][Info]:RKAIQ: parsing /dev/media4
[RKMEDIA][SYS][Info]:RKAIQ: model(rkispp1): ispp_info(1): ispp-subdev entity name: /dev/v4l-subdev1
[RKMEDIA][SYS][Info]:#V4l2Stream: camraID:0, Device:rkispp_scale0
[RKMEDIA][SYS][Warn]:camera_id: 0, chn: rkispp_scale0
[RKMEDIA][SYS][Warn]:camera_id: 0, chn: rkispp_scale0, idx: 0
[RKMEDIA][SYS][Info]:#V4l2Stream: camera id:0, VideoNode:/dev/video31
Using mplane plugin for capture
[RKMEDIA][SYS][Info]:#V4L2Ctx: open /dev/video31, fd 5
[RKMEDIA][SYS][Info]:RK_MPI_VI_EnableChn: Enable VI[0:0]:rkispp_scale0, 1920x1080 End...
[RKMEDIA][SYS][Info]:RK_MPI_VENC_CreateChn: Enable VENC[0], Type:6 Start...
mpp[2220]: mpp_rt: NOT found ion allocator
mpp[2220]: mpp_rt: found drm allocator
mpp[2220]: mpp_info: mpp version: 7ae6041 author: Yandong Lin    2021-02-21 [jpege_vepu]: Support rotation for jpeg enc
[RKMEDIA][VENC][Info]:MPP Encoder: MPPConfig: cfg init sucess!
[RKMEDIA][VENC][Info]:MPP Encoder: qpMaxi use default value:48
[RKMEDIA][VENC][Info]:MPP Encoder: qpMini use default value:8
[RKMEDIA][VENC][Info]:MPP Encoder: qpMax use default value:48
[RKMEDIA][VENC][Info]:MPP Encoder: qpMin use default value:8
[RKMEDIA][VENC][Info]:MPP Encoder: qpInit use default value:-1
[RKMEDIA][VENC][Info]:MPP Encoder: qpStep use default value:2
[RKMEDIA][VENC][Info]:MPP Encoder: rotaion = 0
[RKMEDIA][VENC][Info]:MPP Encoder: automatically calculate bsp with bps_target
[RKMEDIA][VENC][Info]:MPP Encoder: Set output block mode.
[RKMEDIA][VENC][Info]:MPP Encoder: Set input block mode.
[RKMEDIA][VENC][Info]:MPP Encoder: bps:[2304000,2073600,1843200] fps: [30/1]->[30/1], gop:30 qpInit:-1, qpMin:8, qpMax:48, qpMinI:8, qpMaxI:48.
[RKMEDIA][VENC][Info]:MPP Encoder: H264 profile use defalut value: 100[RKMEDIA][VENC][Info]:MPP Encoder: AVC: encode profile 100 level 0
mpp[2220]: mpp_enc: MPP_ENC_SET_RC_CFG bps 2073600 [1843200 : 2304000] fps [30:30] gop 30
mpp[2220]: h264e_api_v2: MPP_ENC_SET_PREP_CFG w:h [1920:1080] stride [1920:1080]
mpp[2220]: mpp_enc: send header for set cfg change input/format
[RKMEDIA][VENC][Info]:MPP Encoder: w x h(1920[1920] x 1080[1080])
mpp[2220]: mpp_enc: mode vbr bps [1843200:2073600:2304000] fps fix [30/1] -> fix [30/1] gop i [30] v [0]
[RKMEDIA][SYS][Info]:RK_MPI_VENC_CreateChn: Enable VENC[0], Type:6 End...
[RKMEDIA][SYS][Info]:RK_MPI_AI_EnableChn: Enable AI[0] Start...
[RKMEDIA][SYS][Info]:AlsaCaptureStream: Layout 0, output chan 2, alsa chan 2
[RKMEDIA][SYS][Info]:RK_MPI_AI_EnableChn: Enable AI[0] End...
[RKMEDIA][AENC][Info]:av codec name=AAC (Advanced Audio Coding)
#MuxerTest: use split name callback type, cb:0x13118, handle:0x2a280...
[RKMEDIA][SYS][Info]:Muxer will use internal path
[RKMEDIA][SYS][Info]:Muxer will use default prefix
[RKMEDIA][SYS][Info]:Muxer will save video file per 30sec
[RKMEDIA][SYS][Info]:Muxer:: enable_streaming is 0
[RKMEDIA][SYS][Info]:Found video encode config!
[RKMEDIA][SYS][Info]:Found audio encode config!
[RKMEDIA][SYS][Info]: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
[RKMEDIA][SYS][Info]:RK_MPI_MUXER_Bind: Bind Mode[VENC]:Chn[0] to Mode[MUXER]:Chn[0]...
[RKMEDIA][SYS][Info]:RK_MPI_MUXER_Bind: Bind Mode[AENC]:Chn[0] to Mode[MUXER]:Chn[0]...
[RKMEDIA][SYS][Info]:RK_MPI_SYS_Bind: Bind Mode[VI]:Chn[0] to Mode[VENC]:Chn[0]...
[RKMEDIA][SYS][Info]:RK_MPI_SYS_Bind: Bind Mode[AI]:Chn[0] to Mode[AENC]:Chn[0]...
main initial finish
#GetRecordFileName: Handle:0x2a280, idx:0 ...
#GetRecordFileName: NewRecordFileName:[/userdata/MuxerCbTest_0.mp4]
### muxer_event_cb: Handle:0xaef0cb10, event:0x9f8daa6c
@@@ muxer_event_cb: ModeID:19, ChnID:0, EventType:2, filename:/userdata/MuxerCbTest_0.mp4, value:30
[RKMEDIA][SYS][Info]:Ready to recod new video file path:[/userdata/MuxerCbTest_0.mp4]
ls
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

友情链接 : 爱板网 电子发烧友论坛 云汉电子社区 粤ICP备14022046号-2
快速回复 返回顶部 返回列表