Mp4V2调试经验记录

一、MP4AddAudioTrack接口

MP4TrackId MP4AddAudioTrack(
    MP4FileHandle hFile,
    uint32_t      timeScale,
    MP4Duration   sampleDuration,
    uint8_t       audioType DEFAULT(MP4_MPEG4_AUDIO_TYPE) );

timeScale 采样率 16000 32000 44100

sampleDuration  这个参数填写的是每一帧的字节数 sampleDuration * 1000000 / timeScale = Duration Time 一帧的持续时间。

 

二、MP4AddALawAudioTrack接口

MP4TrackId MP4AddALawAudioTrack(
    MP4FileHandle hFile,
    uint32_t timeScale,

这个接口是初始化添加音频为PCM的接口,接口的问题是其中默认一帧的持续时间是20ms,见下面的源码。我们可以根据自己的实际情况来更改这个值。

MP4TrackId MP4File::AddALawAudioTrack(    uint32_t timeScale )
{
    uint32_t fixedSampleDuration = (timeScale * 20)/1000; // 20mSec/Sample

    MP4TrackId trackId = AddTrack(MP4_AUDIO_TRACK_TYPE, timeScale);
    .
    .
    .

    m_pTracks[FindTrackIndex(trackId)]->SetFixedSampleDuration(fixedSampleDuration);

    return trackId;
}

三、MP4WriteSample 接口

bool MP4WriteSample(
    MP4FileHandle  hFile,
    MP4TrackId     trackId,
    const uint8_t* pBytes,
    uint32_t       numBytes,
    MP4Duration    duration DEFAULT(MP4_INVALID_DURATION),
    MP4Duration    renderingOffset DEFAULT(0),
    bool           isSyncSample DEFAULT(true) );

视频或者音画同步的主要参数是duration, 公式可以是 (当前帧录制时间-上一针录制时间)*90000/1000;

你可能感兴趣的:(音视频技术)