2247
- 收藏
- 点赞
- 分享
- 举报
用MP4V2库封装H.264播放出来只有一秒是怎么回事?
[code]#include "mp4v2/mp4v2.h"
MP4TrackId video = 0;
MP4FileHandle hMP4File = NULL;
void mp4write(char *_naluData,int size,int width,int height)
{
int index = -1;
if(_naluData[0]==0 && _naluData[1]==0 && _naluData[2]==0 && _naluData[3]==1 && _naluData[4]==0x67)
{
index = _NALU_Iframe;
isSyncSample = 1;
}
if(_naluData[0]==0 && _naluData[1]==0 && _naluData[2]==0 && _naluData[3]==1 && _naluData[4]==0x61)
{
index = _NALU_Pframe;
isSyncSample = 0;
}
switch(index)
{
case _NALU_Iframe:
video = MP4AddH264VideoTrack(hMP4File, 90000, 90000 / 30, width, height, _naluData[4+1], _naluData[4+2], _naluData[4+3],3);
if (video == MP4_INVALID_TRACK_ID)
{
printf("add video track fialed.\n");
return;
}
MP4SetVideoProfileLevel(hMP4File, 0X7F);
MP4AddH264SequenceParameterSet(hMP4File, video, _naluData+4, 15);//sps
MP4AddH264PictureParameterSet(hMP4File, video, _naluData+23, 4);//pps
_naluData[36] = (size- 36 - 4) >> 24;
_naluData[37] = (size- 36 - 4) >> 16;
_naluData[38] = (size- 36 - 4) >> 8;
_naluData[39] = (size- 36 - 4) & 0XFF;
MP4WriteSample(hMP4File, video, _naluData+36, size-36, MP4_INVALID_DURATION, 0, isSyncSample);
break;
case _NALU_Pframe:
_naluData[0] = (size - 4) >> 24;
_naluData[1] = (size - 4) >> 16;
_naluData[2] = (size - 4) >> 8;
_naluData[3] = (size - 4) & 0Xff;
MP4WriteSample(hMP4File, video, _naluData, size, MP4_INVALID_DURATION, 0, isSyncSample);
break;
}
}
void mp4init()
{
if(hMP4File == NULL)
{
hMP4File = MP4CreateEx("./test.mp4",0, 1, 1, 0, 0, 0, 0);
if (hMP4File == MP4_INVALID_FILE_HANDLE)
{
printf("open file fialed.\n");
return ;
}
MP4SetTimeScale(hMP4File, 90000);
}
}
void mp4close()
{
MP4Close(hMP4File,0);
hMP4File = NULL;
video = 0;
}
[/code]
Iframe是包含了SPS(4+15字节)、PPS(4+4字节)、SEI(4+5字节)、I帧的数据。。最后录出来的视频数据显示确实有那么大(单独存H264数据正常播放,MP4文件与H264差不多大),但是只能播一秒。
请问是哪里设置不对吗
MP4TrackId video = 0;
MP4FileHandle hMP4File = NULL;
void mp4write(char *_naluData,int size,int width,int height)
{
int index = -1;
if(_naluData[0]==0 && _naluData[1]==0 && _naluData[2]==0 && _naluData[3]==1 && _naluData[4]==0x67)
{
index = _NALU_Iframe;
isSyncSample = 1;
}
if(_naluData[0]==0 && _naluData[1]==0 && _naluData[2]==0 && _naluData[3]==1 && _naluData[4]==0x61)
{
index = _NALU_Pframe;
isSyncSample = 0;
}
switch(index)
{
case _NALU_Iframe:
video = MP4AddH264VideoTrack(hMP4File, 90000, 90000 / 30, width, height, _naluData[4+1], _naluData[4+2], _naluData[4+3],3);
if (video == MP4_INVALID_TRACK_ID)
{
printf("add video track fialed.\n");
return;
}
MP4SetVideoProfileLevel(hMP4File, 0X7F);
MP4AddH264SequenceParameterSet(hMP4File, video, _naluData+4, 15);//sps
MP4AddH264PictureParameterSet(hMP4File, video, _naluData+23, 4);//pps
_naluData[36] = (size- 36 - 4) >> 24;
_naluData[37] = (size- 36 - 4) >> 16;
_naluData[38] = (size- 36 - 4) >> 8;
_naluData[39] = (size- 36 - 4) & 0XFF;
MP4WriteSample(hMP4File, video, _naluData+36, size-36, MP4_INVALID_DURATION, 0, isSyncSample);
break;
case _NALU_Pframe:
_naluData[0] = (size - 4) >> 24;
_naluData[1] = (size - 4) >> 16;
_naluData[2] = (size - 4) >> 8;
_naluData[3] = (size - 4) & 0Xff;
MP4WriteSample(hMP4File, video, _naluData, size, MP4_INVALID_DURATION, 0, isSyncSample);
break;
}
}
void mp4init()
{
if(hMP4File == NULL)
{
hMP4File = MP4CreateEx("./test.mp4",0, 1, 1, 0, 0, 0, 0);
if (hMP4File == MP4_INVALID_FILE_HANDLE)
{
printf("open file fialed.\n");
return ;
}
MP4SetTimeScale(hMP4File, 90000);
}
}
void mp4close()
{
MP4Close(hMP4File,0);
hMP4File = NULL;
video = 0;
}
[/code]
Iframe是包含了SPS(4+15字节)、PPS(4+4字节)、SEI(4+5字节)、I帧的数据。。最后录出来的视频数据显示确实有那么大(单独存H264数据正常播放,MP4文件与H264差不多大),但是只能播一秒。
请问是哪里设置不对吗
我来回答
回答2个
时间排序
认可量排序
认可0
认可0
或将文件直接拖到这里
悬赏:
E币
网盘
* 网盘链接:
* 提取码:
悬赏:
E币
Markdown 语法
- 加粗**内容**
- 斜体*内容*
- 删除线~~内容~~
- 引用> 引用内容
- 代码`代码`
- 代码块```编程语言↵代码```
- 链接[链接标题](url)
- 无序列表- 内容
- 有序列表1. 内容
- 缩进内容
- 图片![alt](url)
相关问答
-
2019-12-06 14:20:53
-
2017-05-01 13:07:33
-
2018-06-21 16:23:19
-
2016-05-20 17:29:59
-
2017-12-06 15:23:45
-
2017-12-06 16:08:34
-
2014-10-23 10:06:21
-
2021-06-28 19:06:15
-
2021-11-15 16:19:06
-
2017-05-01 12:24:48
-
2016-12-30 20:45:05
-
2015-06-29 16:32:19
-
2020-12-07 09:52:38
-
2020-11-03 11:52:31
-
2016-08-02 17:38:22
-
2022-05-30 18:08:10
-
2016-07-04 11:16:24
-
2017-08-22 11:09:36
-
2018-01-08 11:31:09
无更多相似问答 去提问
点击登录
-- 积分
-- E币
提问
—
收益
—
被采纳
—
我要提问
切换马甲
上一页
下一页
悬赏问答
-
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处理并显示
-
10EB-RV1126-BC-191板子运行自己编码的程序
举报反馈
举报类型
- 内容涉黄/赌/毒
- 内容侵权/抄袭
- 政治相关
- 涉嫌广告
- 侮辱谩骂
- 其他
详细说明
提醒
你的问题还没有最佳答案,是否结题,结题后将扣除20%的悬赏金
取消
确认
提醒
你的问题还没有最佳答案,是否结题,结题后将根据回答情况扣除相应悬赏金(1回答=1E币)
取消
确认