2280
- 收藏
- 点赞
- 分享
- 举报
用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
-
2018-06-21 16:23:19
-
2017-05-01 13:07:33
-
2016-05-20 17:29:59
-
2017-12-06 16:08:34
-
2017-12-06 15:23:45
-
2014-10-23 10:06:21
-
2021-06-28 19:06:15
-
2021-11-15 16:19:06
-
2016-12-30 20:45:05
-
2015-06-29 16:32:19
-
2017-05-01 12:24:48
-
2020-12-07 09:52:38
-
2020-11-03 11:52:31
-
2016-08-02 17:38:22
-
2016-07-04 11:16:24
-
2017-08-22 11:09:36
-
2018-03-08 09:57:45
-
2022-05-30 18:08:10
无更多相似问答 去提问
点击登录
-- 积分
-- E币
提问
—
收益
—
被采纳
—
我要提问
切换马甲
上一页
下一页
悬赏问答
-
5SS928的emmc有32GB,bootargs设置使用16GB,但是为啥能用的只有rootfs的大小
-
33SS928怎样烧写ubuntu系统
-
10ToolPlatform下载rootfs提示网络失败
-
10谁有GK7205V500的SDK
-
5Hi3516CV610 烧录不进去
-
10Hi3559AV100 芯片硬解码h265编码格式的视频时出现视频播放错误,解码错误信息 s32PackErr:码流有错
-
5海思SS928 / SD3403的sample_venc.c摄像头编码Demo中,采集到的摄像头的YUV数据在哪个相关的函数中?
-
5海鸥派openEuler无法启动网卡,连接WIFI存在问题
-
66有没有ISP相关的巨佬帮忙看看SS928对接IMX347的图像问题
-
50求助hi3559与FPGA通过SLVS-EC接口对接问题
举报反馈
举报类型
- 内容涉黄/赌/毒
- 内容侵权/抄袭
- 政治相关
- 涉嫌广告
- 侮辱谩骂
- 其他
详细说明
提醒
你的问题还没有最佳答案,是否结题,结题后将扣除20%的悬赏金
取消
确认
提醒
你的问题还没有最佳答案,是否结题,结题后将根据回答情况扣除相应悬赏金(1回答=1E币)
取消
确认