文章目录
##ffmpeg-视频帧转换420p格式
ffmpeg-sws_scale的应用
说明:传入解码后的视频帧通过sws_scale方式进去转换
对应方法:
AVFrame* goAVFrameFormat420P(AVFrame *src){
SwsContext *sws = NULL;
AVFrame *temp;
temp = av_frame_alloc();
temp->format = AV_PIX_FMT_YUV420P;
temp->width = src->width;
temp->height = src->height;
av_frame_get_buffer(temp,0);
sws = sws_getContext(src->width, src->height, static_cast<AVPixelFormat>(src->format), src->width, src->height, AV_PIX_FMT_YUV420P, 2, NULL, NULL, NULL);
sws_scale(sws,src->data,src->linesize,0,src->height,temp->data,temp->linesize);
temp->pts = src->pts;
if(sws != NULL) {
sws_freeContext(sws);
}
return temp;
}