Zach Zundel
Zach Zundel

Reputation: 415

Segmentation fault on ffmpeg sws_scale

I'm trying to convert an AVFrame from a JPEG (YUV pixel format) to an RGB24 format using ffmpeg's sws_scale function. I set up the SwsContext as follows:

struct SwsContext *sws_ctx = NULL;
    int frameFinished;
    AVPacket packet;
    // initialize SWS context for software scaling
    sws_ctx = sws_getContext(pCodecCtx->width,
        pCodecCtx->height,
        pCodecCtx->pix_fmt,
        pCodecCtx->width,
        pCodecCtx->height,
        AV_PIX_FMT_RGB24,
        SWS_BICUBIC,
        NULL, NULL, NULL
        );

And then, I perform the sws_scale, with the following command

sws_scale(sws_ctx,
          (uint8_t const * const *)pFrame->data,
          pFrame->linesize,
          0,
          pCodecCtx->height,
          pFrameRGB->data,
          pFrameRGB->linesize);

which gives me a segfault, though I'm not sure why. I've tried examining the values through prints and the heights and linesizes and everything all appear to have valid values.

Upvotes: 4

Views: 2454

Answers (1)

Zach Zundel
Zach Zundel

Reputation: 415

For anyone who comes on this in the future, my issues was that I was not properly initalizing pFrame and pFrameRGB. The memory first has to be allocated for the frame struct using av_frame_alloc(), then the data buffers must be allocated with av_image_alloc().

Upvotes: 2

Related Questions