学习过程中敲的代码及编译makefile文件 ,已上传至http://download.csdn.net/detail/gavinr/3798699
2).音频解码函数
/* len1 = avcodec_decode_audio2(aCodecCtx, (int16_t *) audio_buf, &data_size, audio_pkt_data, audio_pkt_size); */ len1 = avcodec_decode_audio3(aCodecCtx, (int16_t *) audio_buf, &data_size, &pkt);
/* avcodec_decode_video(pCodecCtx, pFrame, &frameFinished, packet.data, packet.size); */ avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet);
/* *此函数已经不用 img_convert((AVPicture *)pFrameRGB, PIX_FMT_RGB24, (AVPicture*)pFrame, pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height); */ static struct SwsContext *img_convert_ctx; ... // Convert the image into YUV format that SDL uses if(img_convert_ctx == NULL) { int w = is->video_st->codec->width; int h = is->video_st->codec->height; img_convert_ctx = sws_getContext(w, h, is->video_st->codec->pix_fmt, w, h, dst_pix_fmt, SWS_BICUBIC, NULL, NULL, NULL); if(img_convert_ctx == NULL) { fprintf(stderr, "Cannot initialize the conversion context!\n"); exit(1); } } sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0, is->video_st->codec->height, pict.data, pict.linesize);
4.其它一些问题
1) 编译的程序播放音频时,会比较卡,这应该是代码本身的问题。例程中的音频解码,是在回调函数中进行的,这浪费了一定的时间,如果将解码过程放到其它线程中,应该能解决这个问题。
2)关于音视频同步这块也是就tutorial 05与tutorial06的内容还没有完全弄清楚