sws_scale()不会转换图像,只需将其从源复制到目标即可

问题描述 投票:0回答:1

尝试将任意视频读取为纯RGB24像素,因此以sws_scale()方式转换帧:

    //...
    AVFrame* pic_out = av_frame_alloc();
    pic_out->format = AV_PIX_FMT_RGB24;
    pic_out->width  = 1920;
    pic_out->height = 1080;
    av_frame_get_buffer( pic_out, 32 );

    struct SwsContext * img_convert_ctx = sws_getContext(
        1920, 1080, AV_PIX_FMT_YUV420P,
        1920, 1080, AV_PIX_FMT_RGB24,
        SWS_BICUBIC,
        NULL, NULL, NULL
    );
    //...
    sws_scale(
        img_convert_ctx,
        pic_src->data,     //pic_src is from avcodec_receive_frame()
        pic_src->linesize,
        0,
        1080,
        pic_out->data,
        pic_out->linesize
    );

[一切顺利,但pic_out最终得到的数据与pic_src相同。可能是什么问题?

完整的最小示例是here(假定为RGB24图像作为2.bmp出现,实际上看起来像是[[YUV-某物)]

ffmpeg libav swscale
1个回答
0
投票
问题是我将pic_out->data视为

RGB24图像数据,但必须是pic_out->data[0]

© www.soinside.com 2019 - 2024. All rights reserved.