[Libav-user] which function has the function of pixel format conversion

Talgorn FX - Google Mail fxtalgorn at gmail.com
Mon Sep 7 12:09:16 CEST 2015


Hi,

There is no function with the parameters you suggest.
You need first of all to set a SwsContext with desired parameters and then call sws_scale as show in the example below.
Good luck.

________________

static AVFrame* RGBtoYUV(AVFrame *frame, AVCodecContext *c){
    int ret;
    AVFrame *frameYUV=av_frame_alloc();
    assert(frameYUV);
    frameYUV->format = c->pix_fmt;
    frameYUV->width  = c->width;
    frameYUV->height = c->height;

    int numBytes=avpicture_get_size(AV_PIX_FMT_YUV420P, c->width, c->height);
    assert(numBytes);
    uint8_t *dataBuffer = (uint8_t*) av_malloc (numBytes*sizeof(uint8_t));
    
    frameYUV->data[0]=dataBuffer;

    avpicture_fill((AVPicture *)frameYUV, dataBuffer, AV_PIX_FMT_YUV420P, c->width, c->height);  

    struct SwsContext * YUVScaleCtx = sws_getContext
    (
        c->width,
        c->height,
        AV_PIX_FMT_RGB24,
        c->width,
        c->height,
        AV_PIX_FMT_YUV420P,
        SWS_BILINEAR,
        0,
        0,
        0
    );
    ret = sws_scale(
        YUVScaleCtx,
        (const uint8_t *const *)frame->data,
        frame->linesize, //stride is the size of a line + potential padding for performance issue
        0,
        c->height,
        frameYUV->data,
        frameYUV->linesize
    );
    assert(ret);
    return frameYUV;
}



Le 7 sept. 2015 à 10:31, qw <applemax82 at 163.com> a écrit :

> Hi,
> 
> There are too many ffmpeg functions. I want to find one function, which can convert one pixel format into another, and the argument is AVFrame. Does ffmpeg has this kind of function?
> 
> 
> Thanks!
> 
> B.R.
> 
> Andrew
> 
> 
>  
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20150907/bb78bc68/attachment.html>


More information about the Libav-user mailing list