** https://code.google.com/archive/p/mp4v2/ **
** https://mp4v2.org **
交叉编译
./configure --prefix=$INSTALL_PATH \
--host=arm-none-linux-gnueabi \
--build=i486-linux-gnu \
--disable-option-checking \
--enable-optimize \
--disable-fvivibility \
--disable-gch \
--disable-largefile \
--enable-util \
--disable-cygmin-win32 \
--disable-mingw-threads \
--disable-dependency-tracking \
--enable-shared=yes \
--enable-static=no \
--enable-fast-install=yes \
--disable-libtool-lock \
--with-gnu-ld
参考示例代码
int main(void)
{
unsigned char sps_pps[14] = {0x67, 0x4d, 0x40, 0x1F, 0x96 ,0x54, 0x05, 0x01, 0xec, 0x80, 0x68, 0xce, 0x38, 0x80};
char *p[4];
p[0] = "isom";
p[1] = "iso2";
p[2] = "avc1";
p[3] = "mp41";
MP4FileHandle file = MP4CreateEx("test.mp4", 0, 1, 1, "isom", 0x00000200, p, 4);
if (file == MP4_INVALID_FILE_HANDLE)
{
printf("open file fialed.\n");
return;
}
MP4SetTimeScale(file, 90000);
MP4TrackId video = MP4AddH264VideoTrack(file, 90000, 90000/25, 640, 480,
0x4d, //sps[1] AVCProfileIndication
0x40, //sps[2] profile_compat
0x1f, //sps[3] AVCLevelIndication
3); // 4 bytes length before each NAL unit
if (video == MP4_INVALID_TRACK_ID)
{
printf("add video track failed.\n");
return;
}
MP4SetVideoProfileLevel(file, 0x7F);
MP4TrackId audio = MP4AddAudioTrack(file, 16000, 1024, MP4_MPEG4_AUDIO_TYPE);
if (video == MP4_INVALID_TRACK_ID)
{
printf("add audio track failed.\n");
return;
}
MP4SetAudioProfileLevel(file, 0x2);
while(mp4_read_h264_frame(fpMjpeg, buf, MP4_BUF_SIZE, &size) != -1)
{
buf[0] = ((size-4) & 0xff000000) >> 24;
buf[1] = ((size-4) & 0x00ff0000) >> 16;
buf[2] = ((size-4) & 0x0000ff00) >> 8;
buf[3] = (size-4) & 0x000000ff;
MP4WriteSample(file, video, buf, size, MP4_INVALID_DURATION, 0, 1);
}
while(-1 != mp4_read_aac_frame(fpPcm, buf, MP4_BUF_SIZE, &size))
{
MP4WriteSample(file, audio, buf, size, MP4_INVALID_DURATION, 0, 1);
}
MP4AddH264SequenceParameterSet(file, video, sps_pps, 10);
MP4AddH264PictureParameterSet(file, video, sps_pps+10, 4);
MP4Close(file, 0);
return 0;
}
网友评论