【发布时间】:2016-02-02 07:00:12
【问题描述】:
我正在尝试通过 sws_scale 将解码的 YUV420p 帧(1018x700)缩放为 RGBA,我将数据保存到原始视频文件,然后使用 ffplay 播放原始视频以查看结果。
这是我的代码:
sws_ctx = sws_getContext(video_dec_ctx->width, video_dec_ctx->height,AV_PIX_FMT_YUV420P, video_dec_ctx->width, video_dec_ctx->height, AV_PIX_FMT_BGR32, SWS_LANCZOS | SWS_ACCURATE_RND, 0, 0, 0);
ret = avcodec_decode_video2(video_dec_ctx, yuvframe, got_frame, &pkt);
if (ret < 0) {
std::cout<<"Error in decoding"<<std::endl;
return ret;
}else{
//the source and destination heights and widths are the same
int sourceX = video_dec_ctx->width;
int sourceY = video_dec_ctx->height;
int destX = video_dec_ctx->width;
int destY = video_dec_ctx->height;
//declare destination frame
AVFrame avFrameRGB;
avFrameRGB.linesize[0] = destX * 4;
avFrameRGB.data[0] = (uint8_t*)malloc(avFrameRGB.linesize[0] * destY);
//scale the frame to avFrameRGB
sws_scale(sws_ctx, yuvframe->data, yuvframe->linesize, 0, yuvframe->height, avFrameRGB.data, avFrameRGB.linesize);
//write to file
fwrite(avFrameRGB.data[0], 1, video_dst_bufsize, video_dst_file);
}
这是使用 ffplay 播放时的缩放后(即 RGBA 格式)
我使用以下命令运行 ffplay('video' 是原始视频文件)
ffplay -f rawvideo -pix_fmt bgr32 -video_size 1018x700 video
我应该如何解决才能使 RGB32 发生正确的缩放?
【问题讨论】:
-
字节序不同 - 用
bgr32试试ffplay -
您的问题文本显示为 1024x76,但您的 ffplay 为 1024x760 - 尝试不同的 Y 值,看看您是否得到正确的输出。这应该可以帮助您调试。
-
从表面上看,
avFrameRGB.linesize[0]应该是 3072 = 1024x3;但是你发布了缩放的图像,所以很难说这里到底发生了什么。 -
@Alex Cohn Ive 更新了 1018 的尺寸,我发布了新结果。为什么我要乘以 3 来表示 RGBA 中的线宽? RGB 是 *3,RGBA 是 *4?