int reverse_img(unsigned char* src_buf, unsigned char* dst_buf, unsigned int n_src_width, unsigned int n_src_height, unsigned int n_dst_width, unsigned int n_dst_height)
{
if (src_buf == NULL || dst_buf == NULL) {
return -1;
}
AVFrame* src_frame = av_frame_alloc();
AVFrame* dst_frame = av_frame_alloc();
avpicture_fill((AVPicture*)src_frame, (uint8_t*)src_buf, AV_PIX_FMT_RGB24, n_src_width, n_src_height);
avpicture_fill((AVPicture*)dst_frame, (uint8_t*)dst_buf, AV_PIX_FMT_BGR24, n_dst_width, n_dst_height);
src_frame->data[0] += src_frame->linesize[0] * (n_src_height - 1);
src_frame->linesize[0] = -src_frame->linesize[0];
SwsContext* cxt = sws_getContext(n_src_width, n_src_height, AV_PIX_FMT_RGB24, n_dst_width, n_dst_height, AV_PIX_FMT_BGR24, SWS_FAST_BILINEAR, NULL, NULL, NULL);
if (cxt==NULL){
av_frame_free(&src_frame);
av_frame_free(&dst_frame);
return -1;
}
int n_height = sws_scale(cxt, src_frame->data, src_frame->linesize, 0, n_src_height, dst_frame->data, dst_frame->linesize);
//DP1("scale_publish_img_size: %d", n_height);
sws_freeContext(cxt);
av_frame_free(&src_frame);
av_frame_free(&dst_frame);
return 0;
}
由于DirectShow采集到的图像是倒的,可以使用这个函数进行倒转恢复过来,备注:这里仅针对RGB24或RGB32图像格式有效,对YUV格式因格式排列原因,无法使用该方法。