利用MP4v2录制MP4文件视频播放快问题
 录制场景是这样的,对一个视频会议进行录像,音频是混音后的pcmu格式的语音,视频在同一时刻,只录制某一个成员的视频,因此MP4视频构成就是 A成员视频+B成员视频+c成员视频
现在使用mp4v2进行录像,录制出来后的问题是:视频播放比音频快
这个问题怎么解决呢,视频代码如下:
  uint32_t datalen = *len - 12;
    int iframe = 0;
    uint32_t size;
    uint8_t *hdr = NULL;
    uint8_t fragment_type;
    uint8_t nal_type;
    uint8_t start_bit;
    switch_rtp_hdr_t *rtp_hdr = data;
    mp4_file_context_t *context = handle->private_info;
    uint8_t payload_number = 0;


    switch_mutex_lock(context->mutex);
    if (!context->video) {
        context->video = MP4AddH264VideoTrack(context->fd, 90000, 90000/FPS, 352, 288, H264_PROFILE_BASELINE, 0xe0, 0x1f, 3);
        if (context->video == MP4_INVALID_TRACK_ID) {
            switch_mutex_unlock(context->mutex);
            return SWITCH_STATUS_FALSE;
        }

        MP4SetVideoProfileLevel(context->fd, 0x7F);

        context->video_hint = MP4AddHintTrack(context->fd, context->video);

        if (context->video_hint == MP4_INVALID_TRACK_ID) {
            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "invalid hint track!\n");
            switch_mutex_unlock(context->mutex);
            return SWITCH_STATUS_FALSE;
        }

        MP4SetHintTrackRtpPayload(
            context->fd,
            context->video_hint,
            "H264",
            &payload_number,
            20480, // magic number, maximum payload size, can be 0? FIXME
            NULL,
            false,
            false);

        context->video_sample_id = 1;
    }

    switch_mutex_unlock(context->mutex);

    hdr = ((uint8_t *)data + 12);
    fragment_type = hdr[0] & 0x1f;
    nal_type = hdr[1] & 0x1f;
    start_bit = hdr[1] & 0x80;
    iframe = (((fragment_type == 28 || fragment_type == 29) && nal_type == 5 && start_bit == 128) || fragment_type == 5 || fragment_type ==7 || fragment_type ==8) ? 1 : 0;

    tp_hdr->m, start_bit, iframe);

    if (switch_buffer_inuse(context->buf) == 0) {
        MP4AddRtpVideoHint(context->fd, context->video_hint, iframe, (uint8_t)MP4_INVALID_DURATION);
    }

    MP4AddRtpPacket(context->fd, context->video_hint, rtp_hdr->m, (uint8_t)MP4_INVALID_DURATION);
    MP4AddRtpSampleData(context->fd, context->video_hint, context->video_sample_id++, switch_buffer_inuse(context->buf), datalen + 4);

    size = htonl(datalen);
    switch_buffer_write(context->buf, &size, 4);
    switch_buffer_write(context->buf, hdr, datalen);

    switch_mutex_lock(context->mutex);

    if (fragment_type == 7 && !context->sps_set) { //sps
        MP4AddH264SequenceParameterSet(context->fd, context->video, hdr, datalen);
        context->sps_set = 1;
    } else if (fragment_type == 8 && !context->pps_set) { //pps
        MP4AddH264PictureParameterSet(context->fd, context->video, hdr, datalen);
        context->pps_set = 1;
    }

    if (nal_type == 7 || nal_type == 8 || rtp_hdr->m == 0) {
    } else {
        uint32_t used = switch_buffer_inuse(context->buf);
        const void *data;
        switch_buffer_peek_zerocopy(context->buf, &data);
        MP4WriteRtpHint(context->fd, context->video_hint, MP4_INVALID_DURATION, iframe);
        MP4WriteSample(context->fd, context->video, data, used, DURATION, 0, iframe);
        switch_buffer_zero(context->buf);
    }

    switch_mutex_unlock(context->mutex);

    *len = datalen; // FIXME
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问