从以上链接中下载的MP4V2源码
相关接口如下:
MP4V2_EXPORT
MP4TrackId MP4AddH265VideoTrack(
MP4FileHandle hFile,
uint32_t timeScale,
MP4Duration sampleDuration,
uint16_t width,
uint16_t height,
uint8_t AVCProfileIndication,
uint8_t profile_compat,
uint8_t AVCLevelIndication,
uint8_t sampleLenFieldSizeMinusOne );
MP4V2_EXPORT
void MP4AddH265VideoParameterSet(
MP4FileHandle hFile,
MP4TrackId trackId,
const uint8_t *pSequence,
uint16_t sequenceLen);
MP4V2_EXPORT
void MP4AddH265SequenceParameterSet(
MP4FileHandle hFile,
MP4TrackId trackId,
const uint8_t* pSequence,
uint16_t sequenceLen );
MP4V2_EXPORT
void MP4AddH265PictureParameterSet(
MP4FileHandle hFile,
MP4TrackId trackId,
const uint8_t* pPict,
uint16_t pictLen );
我用的MP4v2-2.0.0 封装(打包)h265和aac到MP4文件能正常播放,
mp4info打开封装文件信息,信息中视频的宽、高为空,文件缩略图不显示第一帧图像,以上2个问题还不知道什么原因。
具体流程
从h265视频流中分离出vps、sps、pps、IDR(i)帧、p帧等信息进行后面处理。处理流程类似封装h264流
h264 使用sps帧 添加视频流MP4AddH264VideoTrack
h265 使用vps帧 添加视频流MP4AddH264VideoTrack
对于h265其中有个问题就是视频的宽 高信息 在sps帧中,vps初始化使用的宽高参数就 先自己赋值为实际的视频宽高了,
接着 以下几个参数设置了
vps帧就 MP4AddH265VideoParameterSet
sps帧就 MP4AddH265SequenceParameterSet
pps帧就 MP4AddH265PictureParameterSet
i和p帧就写数据MP4WriteSample
正常来说,传输给接口的数据没有问题的话,打包出来的文件就能正常播放。
解包h265封装的MP4
思路类似解包h264封装的MP4
这里主要是要分离出MP4视频文件中视频类型是h264还是h265
m_video_trId = MP4FindTrackId(m_hMP4File, 0, MP4_VIDEO_TRACK_TYPE, 0);
if (m_video_trId != MP4_INVALID_TRACK_ID) {
video_name = (char *) MP4GetTrackMediaDataName(m_hMP4File, m_video_trId);
if (strcmp(video_name, "avc1") == 0)
{
videotype = def_FRAME_TYPE_H264;//VIDEO_FMT_H264; // H.264
MP4GetTrackH264SeqPictHeaders(inFile, id, &spsHeader, &spsSize, &ppsHeader, &ppsSize);
}
else if (strcmp(video_name, "hvc1") == 0)
{
videotype = def_FRAME_TYPE_H265;//VIDEO_FMT_H265; // H.265
MP4GetTrackH265SeqPictHeaders(inFile,id,&vpsHeader,&vpsSize,&spsHeader, &spsSize, &ppsHeader, &ppsSize);
}
........
}
.....
}
以上