11959
- 收藏
- 点赞
- 分享
- 举报
3518E录制视频,音视频不同步
本帖最后由 Benz 于 2016-11-9 21:16 编辑
请教各位大神,为什么我用3518E录制mp4,音频会慢慢的快于视频啊?播放的开始时间和结束时间都是一致的,搞不明白啊?我是将venc和audio两个例子融合在一起,在一个线程里面调用音频和视频的getstrame的,分别保存了pcm和h264文件,两个同时播放,发现和转码后封mp4差不多,都是音频会慢慢的快于视频。拜托给位帮忙给点思路 !谢谢大家-----这是我的代码,音频用libfacc转码,最后用mp4v2封装mp4:
while(pstAencCtl->bStart)
{
m++;
FD_ZERO(&readVenc_fds);
for (i = 0; i < s32ChnTotal; i++)
{
FD_SET(VencFd, &readVenc_fds);
}
TimeoutVal.tv_sec = 2;
TimeoutVal.tv_usec = 0;
FD_ZERO(&readAenc_fds);
FD_SET(AencFd,&readAenc_fds);
s32Ret = select(maxfd + 1, &readVenc_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, &readVenc_fds))
{
/*******************************************************
step 2.1 : query how many packs in one-frame stream.
*******************************************************/
memset(&videostStream, 0, sizeof(videostStream));
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.
*******************************************************/
videostStream.pstPack = (VENC_PACK_S*)malloc(sizeof(VENC_PACK_S) * stStat.u32CurPacks);
if (NULL == videostStream.pstPack)
{
SAMPLE_PRT("malloc stream pack failed!\n");
break;
}
/*******************************************************
step 2.3 : call mpi to get one-frame stream
*******************************************************/
videostStream.u32PackCount = stStat.u32CurPacks;
s32Ret = HI_MPI_VENC_GetStream(i, &videostStream, HI_TRUE);
if (HI_SUCCESS != s32Ret)
{
free(videostStream.pstPack);
videostStream.pstPack = NULL;
SAMPLE_PRT("HI_MPI_VENC_GetStream failed with %#x!\n", \
s32Ret);
break;
}
if(m>25) //从下一个I帧开始,写视频到mp4
{
s32Ret=SAMPLE_COMM_VENC_SaveH264(mp4file,&videostStream);
}
/*******************************************************
step 2.5 : release stream
*******************************************************/
s32Ret = HI_MPI_VENC_ReleaseStream(i, &videostStream);
if (HI_SUCCESS != s32Ret)
{
free(videostStream.pstPack);
videostStream.pstPack = NULL;
break;
}
}
}
}
s32Ret = select(AencFd+1, &readAenc_fds, NULL, NULL, &TimeoutVal);
if (s32Ret < 0)
{
break;
}
else if (0 == s32Ret)
{
printf("%s: get aenc stream select time out\n", __FUNCTION__);
break;
}
if (FD_ISSET(AencFd, &readAenc_fds))
{
s32Ret = HI_MPI_AENC_GetStream(pstAencCtl->AeChn, &audiostStream, HI_TRUE);
if (HI_SUCCESS != s32Ret )
{
printf("%s: HI_MPI_AENC_GetStream(%d), failed with %#x!\n", __FUNCTION__, pstAencCtl->AeChn, s32Ret);
pstAencCtl->bStart = HI_FALSE;
return NULL;
}
fwrite(audiostStream.pStream,1,audiostStream.u32Len, pcm);
if(m>15) //libfaac编码前3帧会失败,跳过前面的25帧,获取下一个I帧再写mp4
{
//AAC转码
memcpy(&buf_tmp[pos],audiostStream.pStream,audiostStream.u32Len);
pos+=640;
// printf("pos is:%d\n",pos);
if(pos < 2048)
{
goto got_the_stream;
}
memcpy(InputBuffer,buf_tmp,2048);
memset(buf_tmp,0,2048);
memcpy(buf_tmp,&buf_tmp[2048],pos-2048);
pos=pos-2048;
flag=faacEncEncode(hEncoder, (int*)InputBuffer,inputSamples,OutputBuffer,maxOutputBytes);
if(flag <= 0)
{
printf("start the Encoder failure\n");
}
if(flag > 0) //音频转ACC再写MP4
{
bool ret=MP4SetTrackESConfiguration(mp4file,audio,spec_buf,spec_len);
if(1!=ret)
{
printf("MP4SetTrackESConfiguration audio failed\n");
}
int nret=MP4WriteSample(mp4file, audio, &OutputBuffer[0], flag,128*8000/1000, 0, 1);
if(1!=nret)
{
printf("MP4WriteSample audio failed\n");
}
}
memset(InputBuffer,0,2048);
memset(OutputBuffer,0,768);
}
got_the_stream:
/*******************************************************
step 2.6 : free pack nodes
*******************************************************/
free(videostStream.pstPack);
videostStream.pstPack = NULL;
// finally you must release the stream
HI_MPI_AENC_ReleaseStream(pstAencCtl->AeChn, &audiostStream);
}
// pasttime=nowtime;
}
faacEncClose(hEncoder);
pstAencCtl->bStart = HI_FALSE;
return NULL;
}
请教各位大神,为什么我用3518E录制mp4,音频会慢慢的快于视频啊?播放的开始时间和结束时间都是一致的,搞不明白啊?我是将venc和audio两个例子融合在一起,在一个线程里面调用音频和视频的getstrame的,分别保存了pcm和h264文件,两个同时播放,发现和转码后封mp4差不多,都是音频会慢慢的快于视频。拜托给位帮忙给点思路 !谢谢大家-----这是我的代码,音频用libfacc转码,最后用mp4v2封装mp4:
while(pstAencCtl->bStart)
{
m++;
FD_ZERO(&readVenc_fds);
for (i = 0; i < s32ChnTotal; i++)
{
FD_SET(VencFd, &readVenc_fds);
}
TimeoutVal.tv_sec = 2;
TimeoutVal.tv_usec = 0;
FD_ZERO(&readAenc_fds);
FD_SET(AencFd,&readAenc_fds);
s32Ret = select(maxfd + 1, &readVenc_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, &readVenc_fds))
{
/*******************************************************
step 2.1 : query how many packs in one-frame stream.
*******************************************************/
memset(&videostStream, 0, sizeof(videostStream));
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.
*******************************************************/
videostStream.pstPack = (VENC_PACK_S*)malloc(sizeof(VENC_PACK_S) * stStat.u32CurPacks);
if (NULL == videostStream.pstPack)
{
SAMPLE_PRT("malloc stream pack failed!\n");
break;
}
/*******************************************************
step 2.3 : call mpi to get one-frame stream
*******************************************************/
videostStream.u32PackCount = stStat.u32CurPacks;
s32Ret = HI_MPI_VENC_GetStream(i, &videostStream, HI_TRUE);
if (HI_SUCCESS != s32Ret)
{
free(videostStream.pstPack);
videostStream.pstPack = NULL;
SAMPLE_PRT("HI_MPI_VENC_GetStream failed with %#x!\n", \
s32Ret);
break;
}
if(m>25) //从下一个I帧开始,写视频到mp4
{
s32Ret=SAMPLE_COMM_VENC_SaveH264(mp4file,&videostStream);
}
/*******************************************************
step 2.5 : release stream
*******************************************************/
s32Ret = HI_MPI_VENC_ReleaseStream(i, &videostStream);
if (HI_SUCCESS != s32Ret)
{
free(videostStream.pstPack);
videostStream.pstPack = NULL;
break;
}
}
}
}
s32Ret = select(AencFd+1, &readAenc_fds, NULL, NULL, &TimeoutVal);
if (s32Ret < 0)
{
break;
}
else if (0 == s32Ret)
{
printf("%s: get aenc stream select time out\n", __FUNCTION__);
break;
}
if (FD_ISSET(AencFd, &readAenc_fds))
{
s32Ret = HI_MPI_AENC_GetStream(pstAencCtl->AeChn, &audiostStream, HI_TRUE);
if (HI_SUCCESS != s32Ret )
{
printf("%s: HI_MPI_AENC_GetStream(%d), failed with %#x!\n", __FUNCTION__, pstAencCtl->AeChn, s32Ret);
pstAencCtl->bStart = HI_FALSE;
return NULL;
}
fwrite(audiostStream.pStream,1,audiostStream.u32Len, pcm);
if(m>15) //libfaac编码前3帧会失败,跳过前面的25帧,获取下一个I帧再写mp4
{
//AAC转码
memcpy(&buf_tmp[pos],audiostStream.pStream,audiostStream.u32Len);
pos+=640;
// printf("pos is:%d\n",pos);
if(pos < 2048)
{
goto got_the_stream;
}
memcpy(InputBuffer,buf_tmp,2048);
memset(buf_tmp,0,2048);
memcpy(buf_tmp,&buf_tmp[2048],pos-2048);
pos=pos-2048;
flag=faacEncEncode(hEncoder, (int*)InputBuffer,inputSamples,OutputBuffer,maxOutputBytes);
if(flag <= 0)
{
printf("start the Encoder failure\n");
}
if(flag > 0) //音频转ACC再写MP4
{
bool ret=MP4SetTrackESConfiguration(mp4file,audio,spec_buf,spec_len);
if(1!=ret)
{
printf("MP4SetTrackESConfiguration audio failed\n");
}
int nret=MP4WriteSample(mp4file, audio, &OutputBuffer[0], flag,128*8000/1000, 0, 1);
if(1!=nret)
{
printf("MP4WriteSample audio failed\n");
}
}
memset(InputBuffer,0,2048);
memset(OutputBuffer,0,768);
}
got_the_stream:
/*******************************************************
step 2.6 : free pack nodes
*******************************************************/
free(videostStream.pstPack);
videostStream.pstPack = NULL;
// finally you must release the stream
HI_MPI_AENC_ReleaseStream(pstAencCtl->AeChn, &audiostStream);
}
// pasttime=nowtime;
}
faacEncClose(hEncoder);
pstAencCtl->bStart = HI_FALSE;
return NULL;
}
我来回答
回答34个
时间排序
认可量排序
认可0
认可0
认可0
认可0
认可0
认可0
认可0
认可0
认可0
认可0
认可0
认可0
认可0
认可0
认可0
认可0
认可0
认可0
认可0
认可0
加载中···
或将文件直接拖到这里
悬赏:
E币
网盘
* 网盘链接:
* 提取码:
悬赏:
E币
Markdown 语法
- 加粗**内容**
- 斜体*内容*
- 删除线~~内容~~
- 引用> 引用内容
- 代码`代码`
- 代码块```编程语言↵代码```
- 链接[链接标题](url)
- 无序列表- 内容
- 有序列表1. 内容
- 缩进内容
- 图片![alt](url)
相关问答
-
22014-06-30 17:26:38
-
2017-02-23 10:16:53
-
2015-03-13 13:58:02
-
12019-05-20 14:20:24
-
2017-02-23 10:10:53
-
2016-02-20 20:10:27
-
2014-05-30 14:43:27
-
2017-09-19 12:34:49
-
2016-05-07 17:23:08
-
2017-03-28 17:27:32
-
2015-06-08 11:44:07
-
2024-11-15 10:13:05
-
2016-12-26 21:18:32
-
2014-11-18 17:10:06
-
2018-03-08 09:57:45
-
2017-06-08 17:41:13
-
2016-07-08 14:26:05
-
02015-05-11 13:38:56
-
42019-10-10 22:37:03
无更多相似问答 去提问
点击登录
-- 积分
-- E币
提问
—
收益
—
被采纳
—
我要提问
切换马甲
上一页
下一页
悬赏问答
-
20帮忙交叉编译个源码
-
5Hi3516CV610 如何使用SD卡升级固件
-
5cat /dev/logmpp 报错 <3>[ vi] [func]:vi_send_frame_node [line]:99 [info]:vi pic queue is full!
-
50如何获取vpss chn的图像修改后发送至vo
-
5FPGA通过Bt1120传YUV422数据过来,vi接收不到数据——3516dv500
-
50SS928 运行PQtools 拼接 推到设备里有一半画面会异常
-
53536AV100的sample_vdec输出到CVBS显示
-
10海思板子mpp怎么在vi阶段改变视频数据尺寸
-
10HI3559AV100 多摄像头同步模式
-
9海思ss928单路摄像头vio中加入opencv处理并显示
举报反馈
举报类型
- 内容涉黄/赌/毒
- 内容侵权/抄袭
- 政治相关
- 涉嫌广告
- 侮辱谩骂
- 其他
详细说明
提醒
你的问题还没有最佳答案,是否结题,结题后将扣除20%的悬赏金
取消
确认
提醒
你的问题还没有最佳答案,是否结题,结题后将根据回答情况扣除相应悬赏金(1回答=1E币)
取消
确认