如何同步视频到音频
2013-12-25 17:08
267 查看
同步视频到音频涉及3个方面: 1.计算音频时钟 2.计算视频时钟 3.据音频时钟纠正视频时钟 // 计算音频的已解码数据需要播放的时间 int audio_decode_frame(VideoState *is, uint8_t *audio_buf, int buf_size, double *pts_ptr) { ...... /* if update, update the audio clock w/pts */ is->audio_clock += (double)data_size /bytes_per_sec; ...... } // 当前音频时钟 = 音频的已解码数据需要播放的时间 - 音频缓存中剩余数据需要播放的时间 double get_audio_clock(VideoState *is) { ...... int hw_buf_size = is->audio_buf_size - is->audio_buf_index; pts -= (double)hw_buf_size / bytes_per_sec; ...... } void video_refresh_timer(void *userdata) { // 计算前后2帧的延时 delay = vp->pts - is->frame_last_pts; /* the pts from last time */ /* update delay to sync to audio */ ref_clock = get_audio_clock(is); // 计算音频时钟和视频时钟的差值 diff = vp->pts - ref_clock; /* Skip or repeat the frame. Take delay into account FFPlay still doesn't "know if this is the best guess." */ sync_threshold = (delay > AV_SYNC_THRESHOLD) ? delay : AV_SYNC_THRESHOLD; if(fabs(diff) < AV_NOSYNC_THRESHOLD) { // 据音频时钟纠正视频帧的延时, 太晚了则Skip, 太早了则加大延时 if(diff <= -sync_threshold) { delay = 0; } else if(diff >= sync_threshold) { delay = 2 * delay; } } // 据系统时钟纠正视频帧的延时 is->frame_timer += delay; /* computer the REAL delay */ actual_delay = is->frame_timer - (av_gettime() / 1000000.0); if(actual_delay < 0.010) { /* Really it should skip the picture instead */ actual_delay = 0.010; } }
相关文章推荐
- 如何来设置时间戳让音频和视频同步呢?
- DirectSound初步教程 -- 如何从第三发音乐播放器中HOOK音频数据然后跟自己麦采集数据做同步
- 如何同步视频
- Ffmpeg和SDL如何同步视频(转)
- Ffmpeg和SDL教程(五)如何同步视频
- 视频、音频编码中如何手动计算码率、文件体积?
- 如何计算视频和音频的时间戳间隔时间
- android如何浏览并选择图片 音频 视频 转
- ffmpeg 如何音视频同步
- macOS如何正确驱动集成显卡HDMI(包括视频和音频)
- 如何检测android上的多媒体文件属于音频、视频还是图片?
- 如何使用mp4v2将H264+AAC裸流录制成mp4文件,并保持音视频同步【源码】【mp4】【录像】
- ffmpeg音视频同步---视频同步到音频时钟
- ffmpeg学习---7.音视频同步之视频同步音频
- 如何区分mp4格式里面mdat中的音频和视频数据
- 音视频同步原理解析;音频编码和解码原理
- 视频、音频打时间戳的方法及其音视频同步(播放)原理
- 1.Android如何实现相机功能... 2.如何实现音频的录制... 3.如何实现视频的录制..
- 音频视频分开传在接收端的同步方法
- ffmpeg 如何音视频同步