- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
音视频同步
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);//源数据应该包含时间戳, pInputAudioBuf是源文件解码后的音频数据
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中有,还没细看
实现转码一个普通视频文件为视频mpeg4,音频mp3的功能的程序
本程序实现转码一个普通视频文件为视频mpeg4,音频mp3的功能
#include avcodec.h
#include avformat.h
#include stdio.h
#include avutil.h
#include stdio.h
#include stdlib.h
#include string.h
main(int argc,char **argv)
{
const char *input_file_name=/root/movies/ddh1.mpg;
av_register_all();//注册库中所有可用的文件格式和编码器
AVFormatContext *ic;
//输入文件处理部分
ic=av_alloc_format_context();
if(av_open_input_file(ic,input_file_name,N
文档评论(0)