hello

hello

0个粉丝

7

问答

0

专栏

0

资料

hello  发布于  2015-06-29 16:32:19
采纳率 0%
7个问答
3569

hisi3520d的samples怎么利用mp4v2库合成MP4

 
hisi3520d的samples怎么利用mp4v2库合成MP4,求高手指点
我来回答
回答3个
时间排序
认可量排序

ecomsbz

1个粉丝

22

问答

0

专栏

36

资料

ecomsbz 2015-06-30 12:50:05
认可0
mp4v2下不是有 doc和demo么? 看下就明白了。

qn1513131564

0个粉丝

13

问答

0

专栏

3

资料

qn1513131564 2018-05-17 11:30:08
认可0
我也遇到同样的问题,我的代码贴一下
HI_VOID* SAMPLE_COMM_VENC_GetVencStreamProc(HI_VOID *p)

{

    HI_S32 i;

    HI_S32 s32ChnTotal;

    VENC_CHN_ATTR_S stVencChnAttr;

    SAMPLE_VENC_GETSTREAM_PARA_S *pstPara;

    HI_S32 maxfd = 0;

    struct timeval TimeoutVal;

    fd_set read_fds;

    HI_S32 VencFd[VENC_MAX_CHN_NUM];

    HI_CHAR aszFileName[VENC_MAX_CHN_NUM][64];

    FILE *pFile[VENC_MAX_CHN_NUM];

    char szFilePostfix[10];

    VENC_CHN_STAT_S stStat;

    VENC_STREAM_S stStream;

    HI_S32 s32Ret;

    VENC_CHN VencChn;

    PAYLOAD_TYPE_E enPayLoadType[VENC_MAX_CHN_NUM];
#ifdef MP4

    char* bigbuffer = NULL;
#endif

    pstPara = (SAMPLE_VENC_GETSTREAM_PARA_S*)p;
#ifdef MP4

    s32ChnTotal = 1;//pstPara->s32Cnt;
#else
    s32ChnTotal = pstPara->s32Cnt;

#endif

    /******************************************

     step 1:  check & prepare save-file & venc-fd

    ******************************************/

    if (s32ChnTotal >= VENC_MAX_CHN_NUM)

    {

        SAMPLE_PRT("input count invaild\n");

        return NULL;

    }

    for (i = 0; i < s32ChnTotal; i++)

    {

        /* decide the stream file name, and open file to save stream */

        VencChn = i;

        s32Ret = HI_MPI_VENC_GetChnAttr(VencChn, &stVencChnAttr);

        if(s32Ret != HI_SUCCESS)

        {

            SAMPLE_PRT("HI_MPI_VENC_GetChnAttr chn[%d] failed with %#x!\n", \

                   VencChn, s32Ret);

            return NULL;

        }

        enPayLoadType = stVencChnAttr.stVeAttr.enType;



        s32Ret = SAMPLE_COMM_VENC_GetFilePostfix(enPayLoadType, szFilePostfix);

        if(s32Ret != HI_SUCCESS)

        {

            SAMPLE_PRT("SAMPLE_COMM_VENC_GetFilePostfix [%d] failed with %#x!\n", \

                   stVencChnAttr.stVeAttr.enType, s32Ret);

            return NULL;

        }

        sprintf(aszFileName, "stream_chn%d%s", i, szFilePostfix);

        pFile = fopen(aszFileName, "wb");

        if (!pFile)

        {

            SAMPLE_PRT("open file[%s] failed!\n",

                   aszFileName);

            return NULL;

        }



        /* Set Venc Fd. */

        VencFd = HI_MPI_VENC_GetFd(i);

        if (VencFd < 0)

        {

            SAMPLE_PRT("HI_MPI_VENC_GetFd failed with %#x!\n",

                   VencFd);

            return NULL;

        }

        if (maxfd <= VencFd)

        {

            maxfd = VencFd;

        }

    }
#ifdef MP4

        printf("inital the MP4CreateEx\n");
        MP4FileHandle file = MP4CreateEx("test.mp4", 0, 1, 1, 0, 0, 0, 0);
   
        if (file == MP4_INVALID_FILE_HANDLE)
        {
                printf("open file fialed.\n");
                return;
        }
       
        MP4SetTimeScale(file, 90000);
        printf("MP4SetTimeScale set\n");
        MP4TrackId video = MP4AddH264VideoTrack(file, 90000, 90000 / 25, stVencChnAttr.stVeAttr.stAttrH264e.u32PicWidth, stVencChnAttr.stVeAttr.stAttrH264e.u32PicHeight,
                                            0x64, //sps[1] AVCProfileIndication
                                            0x00, //sps[2] profile_compat
                                            0x1f, //sps[3] AVCLevelIndication
                                            3); // 4 bytes length before each NAL unit
        if (video == MP4_INVALID_TRACK_ID)
        {
                printf("add video track fialed.\n");
                return;
        }
        printf("MP4AddH264VideoTrack set\n ");
        MP4SetVideoProfileLevel(file, 0x01);
        printf("MP4SetVideoProfileLevel \n");
#endif

    /******************************************

     step 2:  Start to get streams of each channel.

    ******************************************/

    while (HI_TRUE == pstPara->bThreadStart)

    {

        FD_ZERO(&read_fds);

        for (i = 0; i < s32ChnTotal; i++)

        {

            FD_SET(VencFd, &read_fds);

        }



        TimeoutVal.tv_sec  = 2;

        TimeoutVal.tv_usec = 0;

        s32Ret = select(maxfd + 1, &read_fds, NULL, NULL, &TimeoutVal);

        if (s32Ret < 0)

        {

            SAMPLE_PRT("select failed!\n");

            break;

        }

        else if (s32Ret == 0)

        {

            SAMPLE_PRT("get venc stream time out, exit thread\n");

            continue;

        }

        else

        {

            for (i = 0; i < s32ChnTotal; i++)

            {

                if (FD_ISSET(VencFd, &read_fds))

                {

                    /*******************************************************

                     step 2.1 : query how many packs in one-frame stream.

                    *******************************************************/

                    memset(&stStream, 0, sizeof(stStream));

                    s32Ret = HI_MPI_VENC_Query(i, &stStat);

                    if (HI_SUCCESS != s32Ret)

                    {

                        SAMPLE_PRT("HI_MPI_VENC_Query chn[%d] failed with %#x!\n", i, s32Ret);

                        break;

                    }



                    /*******************************************************

                     step 2.2 : malloc corresponding number of pack nodes.

                    *******************************************************/

                    stStream.pstPack = (VENC_PACK_S*)malloc(sizeof(VENC_PACK_S) * stStat.u32CurPacks);

                    if (NULL == stStream.pstPack)

                    {

                        SAMPLE_PRT("malloc stream pack failed!\n");

                        break;

                    }

                    

                    /*******************************************************

                     step 2.3 : call mpi to get one-frame stream

                    *******************************************************/

                    stStream.u32PackCount = stStat.u32CurPacks;

                    s32Ret = HI_MPI_VENC_GetStream(i, &stStream, HI_TRUE);

                    if (HI_SUCCESS != s32Ret)

                    {

                        free(stStream.pstPack);

                        stStream.pstPack = NULL;

                        SAMPLE_PRT("HI_MPI_VENC_GetStream failed with %#x!\n", \

                               s32Ret);

                        break;

                    }



                    /*******************************************************

                     step 2.4 : save frame to file

                    *******************************************************/

                    s32Ret = SAMPLE_COMM_VENC_SaveStream(enPayLoadType, pFile, &stStream);

                    if (HI_SUCCESS != s32Ret)

                    {

                        free(stStream.pstPack);

                        stStream.pstPack = NULL;

                        SAMPLE_PRT("save stream failed!\n");

                        break;

                   }
#ifdef MP4
        unsigned int tlen = 0;
        unsigned int len = 0;
        for (i = 0; i < stStream.u32PackCount; i++)
        {
                tlen = tlen + stStream.pstPack.u32Len[0];
                tlen = tlen + stStream.pstPack.u32Len[1];
        }
        printf("the tlen is %d\n",tlen);
        bigbuffer = (char*)malloc(tlen);
        for (i = 0; i < stStream.u32PackCount; i++)
              {

                memcpy(bigbuffer, stStream.pstPack.pu8Addr[0],stStream.pstPack.u32Len[0]);
                bigbuffer = bigbuffer + stStream.pstPack.u32Len[0];
                len = len + stStream.pstPack.u32Len[0];
                memcpy(bigbuffer, stStream.pstPack.pu8Addr[1],stStream.pstPack.u32Len[1]);
                bigbuffer = bigbuffer +  stStream.pstPack.u32Len[1];
                len = len+ stStream.pstPack.u32Len[1];

              }

        MP4WriteSample(file, video, bigbuffer+4, len-4, MP4_INVALID_DURATION, 0, 1);
#endif

                    /*******************************************************

                     step 2.5 : release stream

                    *******************************************************/

                    s32Ret = HI_MPI_VENC_ReleaseStream(i, &stStream);

                    if (HI_SUCCESS != s32Ret)

                    {

                        free(stStream.pstPack);

                        stStream.pstPack = NULL;

                        break;

                    }

                    /*******************************************************

                     step 2.6 : free pack nodes

                    *******************************************************/

                    free(stStream.pstPack);

                    stStream.pstPack = NULL;

                }

            }

        }

    }



    /*******************************************************

    * step 3 : close save-file

    *******************************************************/

    for (i = 0; i < s32ChnTotal; i++)

    {

        fclose(pFile);

    }
#ifdef MP4

        MP4Close(file,0);
#endif

    return NULL;

}

但我的程序根本不成功,# ./sample_venc 0
[SAMPLE_COMM_SYS_CalcPicVbBlkSize]-167: w:768, u32AlignWidth:64
please choose rc mode:
        0) CBR
        1) VBR
        2) FIXQP
0
please press twice ENTER to exit this sample
inital the MP4CreateEx
MP4SetTimeScale set
Aborted

直接晕掉了。

qn1533003427

0个粉丝

1

问答

0

专栏

0

资料

qn1533003427 2018-08-01 17:01:07
认可0
加我QQ  2746318932  我帮你看看
或将文件直接拖到这里
悬赏:
E币
网盘
* 网盘链接:
* 提取码:
悬赏:
E币

Markdown 语法

  • 加粗**内容**
  • 斜体*内容*
  • 删除线~~内容~~
  • 引用> 引用内容
  • 代码`代码`
  • 代码块```编程语言↵代码```
  • 链接[链接标题](url)
  • 无序列表- 内容
  • 有序列表1. 内容
  • 缩进内容
  • 图片![alt](url)
+ 添加网盘链接/附件

Markdown 语法

  • 加粗**内容**
  • 斜体*内容*
  • 删除线~~内容~~
  • 引用> 引用内容
  • 代码`代码`
  • 代码块```编程语言↵代码```
  • 链接[链接标题](url)
  • 无序列表- 内容
  • 有序列表1. 内容
  • 缩进内容
  • 图片![alt](url)
相关问答
无更多相似问答 去提问
举报反馈

举报类型

  • 内容涉黄/赌/毒
  • 内容侵权/抄袭
  • 政治相关
  • 涉嫌广告
  • 侮辱谩骂
  • 其他

详细说明

易百纳技术社区