其他分享
首页 > 其他分享> > 录像存储mp4格式

录像存储mp4格式

作者:互联网

视频录像为mp4格式,采用的libmp4v2库来实现。

初始化文件

mp4fileHandle_ = MP4Create(filename);//创建mp4文件

        //MP4SetTimeScale(mp4fileHandle_, 90000);
//添加h264 track    
mp4VideoTrack_ = MP4AddH264VideoTrack(mp4fileHandle_, 90000, 90000 / 25, 1920, 1080,
0x64,//0x64, //sps[1] AVCProfileIndication
0x00, //sps[2] profile_compat
0x1e,//0x1f, //sps[3] AVCLevelIndication
3); // 4 bytes length before each NAL unit
if (mp4VideoTrack_ == MP4_INVALID_TRACK_ID)
{
printf("add video track failed.\n");
}
//MP4SetVideoProfileLevel(mp4fileHandle_, 0x7F);


//添加aac音频
mp4AudioTrack_ = MP4AddAudioTrack(mp4fileHandle_, 44100, 1024, MP4_MPEG4_AUDIO_TYPE);
if (mp4AudioTrack_ == MP4_INVALID_TRACK_ID)
{
printf("add audio track failed.\n");
}
MP4SetAudioProfileLevel(mp4fileHandle_, 0x2);

 

存储视频数据

MP4WriteSample(mp4fileHandle_, mp4VideoTrack_, (const uint8_t *)pBuffer, dwBufSize, MP4_INVALID_DURATION, 0, 1);

 

存储音频数据

MP4WriteSample(mp4fileHandle_, mp4AudioTrack_, (const uint8_t *)pBuffer, dwBufSize, MP4_INVALID_DURATION, 0, 1);

 

关闭文件

MP4Close(mp4fileHandle_);

 

 

 

 

标签:mp4VideoTrack,sps,90000,录像,INVALID,mp4,mp4fileHandle,MP4,格式
来源: https://blog.csdn.net/lipku/article/details/78138645