Having some trouble writing SDL_Surface to to ffmpeg.
Creating a Surface
SDL_CreateRGBSurface(0, width, height, 32, rmask, gmask, bmask, amask);
Saves pixels into the frame
SDL_RenderReadPixels(
renderer,
NULL,
SDL_PIXELFORMAT_RGBA32,
surface->pixels,
surface->pitch
);
Later uses the pixels
uint8_t* pixels = (uint8_t*)surface->pixels;
cctx = avcodec_alloc_context3(codec);
stream->codecpar->format = AV_PIX_FMT_YUV420P;
// gets a new frame
videoFrame = av_frame_alloc();
int inLinesize[1] = { 3 * cctx->width }; // not sure
if (!swsCtx) {
swsCtx = sws_getContext(cctx->width, cctx->height, AV_PIX_FMT_RGB24, cctx->width, cctx->height, AV_PIX_FMT_YUV420P, SWS_BICUBIC, 0, 0, 0);
}
Adds the pixels to scale
sws_scale(swsCtx, &pixels, inLinesize, 0, cctx->height, videoFrame->data, videoFrame->linesize);
The result on the video frame on the right is wrong, video size and some pixels are correct.
Any experienced ffmpeg people who has an idea?