【Stone from other hills】音视频同步原理[ffmpeg]
来源:互联网 发布:洛阳农村淘宝招聘 编辑:程序博客网 时间:2024/04/30 19:52
output_example.c 中AV同步的代码如下(我的代码有些修改),这个实现相当简单,不过挺说明问题。
阅读前希望大家先了解一下时间戳的概念。
/* compute current audio and video time */if (pOutputVars->pOutAudio_st)//存在音频流 pOutputVars->audio_pts = (double)pOutputVars->pOutAudio_st->pts.val * pOutputVars->pOutAudio_st->time_base.num / pOutputVars- >pOutAudio_st->time_base.den; //(pts是时间戳结构)输出音频的时间戳, 转换为基准时间else pOutputVars->audio_pts = 0.0;if (pOutputVars->pOutVideo_st) pOutputVars->video_pts = (double)pOutputVars->pOutVideo_st->pts.val * pOutputVars->pOutVideo_st->time_base.num / pOutputVars- >pOutVideo_st->time_base.den;//输出视频时间戳else pOutputVars->video_pts = 0.0;if (!pOutputVars->pOutAudio_st && !pOutputVars->pOutVideo_st) return 0;/* write interleaved audio and video frames */if (!pOutputVars->pOutVideo_st || (pOutputVars->pOutVideo_st && pOutputVars->pOutAudio_st && pOutputVars->audio_pts < pOutputVars->video_pts)) { write_audio_frame(pOutputVars->pOutFormatCtx, pOutputVars->pOutAudio_st, pInputAudioBuf);//没有视频流,或者音频流时间没赶上视频流(通过比较时间戳), 则输出(编码输出)音频祯数据 } else { write_video_frame(pOutputVars->pOutFormatCtx, pOutputVars->pOutVideo_st, pInputVedioFrame);//否则输出视频祯数据}
输出数据的时间戳怎么得到的, 以音频为例: pkt.size= avcodec_encode_audio(c, audio_outbuf, audio_outbuf_size, pInputAudioBuf);//源数据应该包含时间戳, pInputAudio是源文件解码后的音频数据 pkt.pts= av_rescale_q(c->coded_frame->pts, c->time_base, st->time_base);//编码后的祯也含有源文件的时间戳,这个函数应该是转换同时间基准,没研究过 pkt.flags |= PKT_FLAG_KEY; pkt.stream_index= st->index; pkt.data= audio_outbuf;...
应该就是这么个过程了,然后用av_write_frame(oc, &pkt), 把音频祯和视频祯交错写入到输出文件. 通过上面分析,可以看到,有时候可能连续写几个音频祯或视频祯. 播放时的同步可能ffplay中有,还没细看
- 【Stone from other hills】音视频同步原理[ffmpeg]
- 【Stones from other hills】音频/视频同步算法
- 【Stones from other hills】mplayer音视频同步浅度学习
- 【Stones from other hills】视频解码优化
- 【Stones from other hills】手机视频监控系统需求
- 【Stones from other hills】视频监控的一些文章
- 【Stones from other hills】DM642DSP高效率视频编码优化方法
- 【Stones from other hills】手机视频监控系统小结
- 【Stones from other hills】手机视频监控系统小结 收藏
- ffmpeg音视频同步原理
- 音视频同步原理[ffmpeg]
- ffmpeg音视频同步原理
- ffmpeg音视频同步原理
- 音视频同步原理[ffmpeg]
- ffmpeg音视频同步原理
- 【Stones from other hills】MPEG-2传输流分析与视音频同步问题的研究
- 【Stones from other hills】IP视频通信中的丢包恢复技术
- 【Stones from other hills】各种MPEG-4 AVC/H.264 视频编解码器
- Http请求流程,模拟Http请求
- LM3s8962学习笔记
- 指针赋值时的相容性
- SOAP 简单对象访问协议
- IIS与127.0.0.1访问问题
- 【Stone from other hills】音视频同步原理[ffmpeg]
- 光伏逆变器的选择
- Spring BlazeDs 集成问题
- 公司绝不会告诉你的20大秘密 值得一看很受用
- asp数字分页示例共三个
- RegQueryValueEx 读取 DWORD
- 用友的一道java笔试题(多态,Override)
- 【Stones from other hills】音频/视频同步算法
- 成语典故(1)