简体   繁体   中英

sws_scale() does not convert image simply copying it from source to target

Trying to read arbitrary video as plain RGB24 pixels so convert frame with sws_scale() this way:

    //...
    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
    );

Everything goes without any errors, but pic_out ends up having the same data as pic_src . What could be the problem?

Full minimal example is here (supposed to be RGB24 image is there as 2.bmp which looks like actually being YUV -something)

问题是我将pic_out->data视为RGB24图像数据,但它需要是pic_out->data[0]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM