美文网首页
mp4v2 x264+faac->mp4

mp4v2 x264+faac->mp4

作者: Caiaolun | 来源:发表于2019-12-04 15:04 被阅读0次

    原文地址:https://blog.csdn.net/jasonwang1002/article/details/49330573

    int aa(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);
     
        //添加h264 track     
        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); 
     
        //添加aac音频 
        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;
    }
    

    相关文章

      网友评论

          本文标题:mp4v2 x264+faac->mp4

          本文链接:https://www.haomeiwen.com/subject/pvklgctx.html