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.
pFrame->data
contains 3 planes with YUV (420P?) data, ifpFrameRGB->linesize[0]
is at least 3 times bigger thanpCodecCtx->width
, and ifpFrameRGB->data
contains 1 plane which is at leastpFrameRGB->linesize[0] * pCodecCtx->height
big. If everything seems ok then see if segfault occurs when reading value or when writing (at least you'll know if it's source or destination frame). – Andrey Turkin