H264与AAC ES打包成MP4

H264与AAC ES打包成MP4注意设置图像的spsppsMP4AddH264SequenceParameterSet(file,video,sps,sizeof(sps));MP4AddH264PictureParameterSet(file,video,pps,sizeof(pps));设置音频解码信息MP4Se

大家好,欢迎来到IT知识分享网。H264与AAC ES打包成MP4

注意

设置图像的sps pps

MP4AddH264SequenceParameterSet(file,video,sps,sizeof(sps));

MP4AddH264PictureParameterSet(file,video,pps, sizeof(pps));

设置音频解码信息

MP4SetTrackESConfiguration(file,audio,pConfig,configSize);

 

 

 

MP4FileHandle file = MP4CreateEx(“new.mp4”);//创建mp4文件
    if (file == MP4_INVALID_FILE_HANDLE){
        printf(“open file fialed.\n”);
        return -1;
    }
    
    MP4SetTimeScale(file, 1000);

    //添加h264 track    
    MP4TrackId video = MP4AddH264VideoTrack(file, 12800, 12800 / 25, 1280, 720,
                                            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 -1;
    }
    
    MP4SetVideoProfileLevel(file, 0x01);

 // write sps
     unsigned char sps[] = {0x67,0x4D,0x40,0x1F,0xDA,0x01,0x40,0x16,0xEC,0x04,0x40,0x00,0x00,0x03,0x00,0x40,0x00,0x00,0x0C,0x83 ,0xC6 ,0x0C ,0xA8};
     unsigned char pps[] = {0x68 ,0xEF ,0x3C ,0x80};
     MP4AddH264SequenceParameterSet(file,video,sps,sizeof(sps));

 // write pps
    MP4AddH264PictureParameterSet(file,video,pps, sizeof(pps));    
    
    //添加aac音频
    MP4TrackId audio = MP4AddAudioTrack(file, 48000, 1024, MP4_MPEG4_AUDIO_TYPE);
    if (audio == MP4_INVALID_TRACK_ID){
        printf(“add audio track failed.\n”);
        return -1;
    }
    MP4SetAudioProfileLevel(file, 0x2);

    unsigned char Buf[409600] = {0};
    
    for(int i = 0; i < sampleTotalCount[0]; ++i){        
        fseek(fp, sampleList[0][i].offset, SEEK_SET);
        fread(Buf, sampleList[0][i].size, 1, fp);      
                printf(“\nsample_list[%d].size:%d#”, i, sampleList[0][i].size);
                for (int k = 0; k < 16; ++k){
                    printf(“%02x “, Buf[k]);
                }        
        MP4WriteSample(file, video, (uint8_t*)(Buf), sampleList[0][i].size, sampleList[0][i].delta, 0, 1);
    }
    
    for(int i = 0; i < sampleTotalCount[1]; ++i){
        fseek(fp, sampleList[1][i].offset, SEEK_SET);
        fread(Buf, sampleList[1][i].size, 1, fp);
        MP4WriteSample(file, audio, (uint8_t*)Buf, sampleList[1][i].size , sampleList[1][i].delta, 0, 1);
    }  
    
    MP4Close(file);    
   

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/33811.html

(0)

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

关注微信