float

float

0个粉丝

3

问答

0

专栏

0

资料

float  发布于  2018-06-28 15:50:15
采纳率 0%
3个问答
2860

【已解决】海思3518 venc demo 编码I帧长度只有18

 
本帖最后由 float 于 2018-6-28 19:41 编辑

用海思Hi3518E_SDK_V1.0.4.0包里的 sample 下 venc 测试视频编码
然后编出来的264 I帧都只有18个字节的长度,P帧则正常。而起录下来的视频也可以播放

请问这个正常么 ,不正常的话是哪里的问题?


我来回答
回答15个
时间排序
认可量排序

float

0个粉丝

3

问答

0

专栏

0

资料

float 2018-06-28 15:51:20
认可0
代码
[code]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];
   
    pstPara = (SAMPLE_VENC_GETSTREAM_PARA_S*)p;
    s32ChnTotal = pstPara->s32Cnt;

    /******************************************
     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;
        }
    }

    /******************************************
     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 :suggest to check both u32CurPacks and u32LeftStreamFrames at the same time,for example:
                                         if(0 == stStat.u32CurPacks || 0 == stStat.u32LeftStreamFrames)
                                         {
                                                SAMPLE_PRT("NOTE: Current  frame is NULL!\n");
                                                continue;
                                         }
                                        *******************************************************/
                                        if(0 == stStat.u32CurPacks)
                                        {
                                                  SAMPLE_PRT("NOTE: Current  frame is NULL!\n");
                                                  continue;
                                        }
                    /*******************************************************
                     step 2.3 : 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.4 : 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;
                    }

//-------------------------yy--

                                        if (stStream.pstPack->DataType.enH264EType != H264E_NALU_PSLICE && i ==0)
                                        {
                                                SAMPLE_PRT("i-%d-----------0------------%d\n", \
                               i,stStream.pstPack.u32Len);       
                                                char *video_addr = (char *)stStream.pstPack.pu8Addr + stStream.pstPack.u32Offset;
                                                printf("%x-%x-%x-%x-\n",\
                                                        video_addr[0],video_addr[1],video_addr[2],video_addr[3]);
                                        }

                                        else if(i == 0)
                                        {

                                                SAMPLE_PRT("i-%d----------X-------------%d\n", \
                               i,stStream.pstPack.u32Len);       
                                        }
//------------------------------
                    /*******************************************************
                     step 2.5 : 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;
                    }
                    /*******************************************************
                     step 2.6 : release stream
                    *******************************************************/
                    s32Ret = HI_MPI_VENC_ReleaseStream(i, &stStream);
                    if (HI_SUCCESS != s32Ret)
                    {
                        free(stStream.pstPack);
                        stStream.pstPack = NULL;
                        break;
                    }
                    /*******************************************************
                     step 2.7 : free pack nodes
                    *******************************************************/
                    free(stStream.pstPack);
                    stStream.pstPack = NULL;
                }
            }
        }
    }

    /*******************************************************
    * step 3 : close save-file
    *******************************************************/
    for (i = 0; i < s32ChnTotal; i++)
    {
        fclose(pFile);
    }

    return NULL;
}[/code]

float

0个粉丝

3

问答

0

专栏

0

资料

float 2018-06-28 15:53:52
认可0
log:如下  .

zhuangweiye

8个粉丝

0

问答

0

专栏

0

资料

zhuangweiye 2018-06-28 16:00:12
认可0
[quote][url=forum.php?mod=redirect&goto=findpost&pid=100376&ptid=50972]float 发表于 2018-6-28 15:53[/url]
log:如下  .[/quote]

估计楼主的码流是多包模式, I 帧会有SPS/PPS

可以打印一下 stStream->u32PackCount

float

0个粉丝

3

问答

0

专栏

0

资料

float 2018-06-28 16:22:21
认可0
[quote][url=forum.php?mod=redirect&goto=findpost&pid=100377&ptid=50972]zhuangweiye 发表于 2018-6-28 16:00[/url]
估计楼主的码流是多包模式, I 帧会有SPS/PPS

可以打印一下 stStream->u32PackCount[/quote]

感谢回答

97

[SAMPLE_COMM_VENC_GetVencStreamProc]-1581: i-0-----------I--u32PackCount-4---------18
0-0-0-1-

加了打印 发现u32PackCount 的值是4

zhuangweiye

8个粉丝

0

问答

0

专栏

0

资料

zhuangweiye 2018-06-28 16:32:27
认可0
[quote][url=forum.php?mod=redirect&goto=findpost&pid=100378&ptid=50972]float 发表于 2018-6-28 16:22[/url]
感谢回答

97
[/quote]

应该是4个包的总长度

float

0个粉丝

3

问答

0

专栏

0

资料

float 2018-06-28 16:40:11
认可0
[quote][url=forum.php?mod=redirect&goto=findpost&pid=100381&ptid=50972]zhuangweiye 发表于 2018-6-28 16:32[/url]
应该是4个包的总长度[/quote]

这个18 是4个包的长度 ,那么i帧的长度怎么获取?

我通过软件查看录下来的视频数据  发现18是sps+pps的长度?

zhuangweiye

8个粉丝

0

问答

0

专栏

0

资料

zhuangweiye 2018-06-28 16:49:54
认可0
[quote][url=forum.php?mod=redirect&goto=findpost&pid=100382&ptid=50972]float 发表于 2018-6-28 16:40[/url]
这个18 是4个包的长度 ,那么i帧的长度怎么获取?

我通过软件查看录下来的视频数据  发现18是sps+pps ...[/quote]

        framelen = 0;
        for ( i = 0; i <  pStream->u32PackCount; i++)
        {
                framelen += (pStream->pstPack.u32Len - pStream->pstPack.u32Offset);
        }

float

0个粉丝

3

问答

0

专栏

0

资料

float 2018-06-28 17:06:00
认可0
[quote][url=forum.php?mod=redirect&goto=findpost&pid=100383&ptid=50972]zhuangweiye 发表于 2018-6-28 16:49[/url]
framelen = 0;
        for ( i = 0; i <  pStream->u32PackCount; i++)
        {
[/quote]

太感谢了


可以了 :D

float

0个粉丝

3

问答

0

专栏

0

资料

float 2018-06-28 17:13:00
认可0
[quote][url=forum.php?mod=redirect&goto=findpost&pid=100383&ptid=50972]zhuangweiye 发表于 2018-6-28 16:49[/url]
framelen = 0;
        for ( i = 0; i <  pStream->u32PackCount; i++)
        {
[/quote]

你好,
我再问一下
我用 insmod /lib/ko/hi3518e_h264e.ko OneStreamBuffer=1
切换为单包模式
然后录下来视频播放,但是提示无法播放
发现I帧的前4个数据 00 00 00 01 61
这个,
要设置单包模式除了 加载驱动时改变一下 还要修改别的地方么?


zhuangweiye

8个粉丝

0

问答

0

专栏

0

资料

zhuangweiye 2018-06-28 17:37:25
认可0
[quote][url=forum.php?mod=redirect&goto=findpost&pid=100388&ptid=50972]float 发表于 2018-6-28 17:13[/url]
你好,
我再问一下
我用 insmod /lib/ko/hi3518e_h264e.ko OneStreamBuffer=1
[/quote]

这个... 没有碰到过 , 应该不用设置什么了



float

0个粉丝

3

问答

0

专栏

0

资料

float 2018-06-28 19:38:32
认可0
[quote][url=forum.php?mod=redirect&goto=findpost&pid=100395&ptid=50972]zhuangweiye 发表于 2018-6-28 17:37[/url]
这个... 没有碰到过 , 应该不用设置什么了[/quote]

好的  谢谢

ioto

0个粉丝

7

问答

0

专栏

0

资料

ioto 2018-08-08 18:05:16
认可0
好帖。。。顶起来

rfk

0个粉丝

7

问答

0

专栏

0

资料

rfk 2018-08-10 12:08:16
认可0
顶帖是一种美德:lol

hero

0个粉丝

1

问答

0

专栏

0

资料

hero 2018-06-29 10:14:28
认可0
:victory::victory::victory::victory:

ppfic

0个粉丝

7

问答

0

专栏

0

资料

ppfic 2018-08-18 09:20:29
认可0
了解了。。。:victory::victory:
或将文件直接拖到这里
悬赏:
E币
网盘
* 网盘链接:
* 提取码:
悬赏:
E币

Markdown 语法

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

Markdown 语法

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

举报类型

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

详细说明

易百纳技术社区