On 12 Jun 2011, at 18:56, Eric Glaser <[email protected]> wrote: > Hi, I am having some trouble converting from YUYV to RGB format - it > crashes in sws_scale. I am guessing I am not filling pFrame below > properly. I use pFrame to fill in the data pointer and strides to pass > to swscale function. > > AVFrame *pFrameRGB=NULL; > AVFrame *pFrame; > > > pFrame = avcodec_alloc_frame(); > int size = avpicture_get_size(pMediaInfo->ff_pixFormat, > ww, hh); //(this is to verify - accurately gets correct size fora > YUYV frame - > > //matches with the number of bytes > i am passing) > > pFrame->data[0] = pMediaInfo->src; //src contains the RAW > image frame read with V4L2 reader function, > > //here i am just assigning the pointer to AVFrame variable. > > pFrame->linesize[0]=ww*2; //src width in bytes > pFrame->linesize[1]=0; > pFrame->linesize[2]=0; > pFrame->linesize[3]=0; > > pFrameRGB = avcodec_alloc_frame(); > > int numRGBBytes = ww * hh * 4; //src width * src height * 4 > buffer = malloc (sizeof(uint8_t)*numRGBBytes); > > > if ( avpicture_fill((AVPicture *)pFrameRGB, buffer, > PIX_FMT_RGB24, ww, hh) <= 0 ) //this essentially assigns allocated > data pointer to pFrameRGB->data > { > error = AV_PICFILL; > break; > } > > if(pOGLContext->img_convert_ctx == NULL) > { > pOGLContext->img_convert_ctx = sws_getContext(ww, hh, > pMediaInfo->ff_pixFormat, > ww, hh, PIX_FMT_RGB24, SWS_FAST_BILINEAR, NULL, NULL, > NULL); > if(pOGLContext->img_convert_ctx == NULL) > { > error = SWSCALE_INITERR; > break; > } > } > > int ret = sws_scale(pOGLContext->img_convert_ctx, > (uint8_t**)pFrame->data, pFrame->linesize, 0, hh, pFrameRGB->data, > pFrameRGB->linesize); > if(ret == -1) > { > > error = SWSCALE_ERROR; > break; > } > > If anybody could give me some insight, that would be good. Thanks > _______________________________________________ > libav-api mailing list > [email protected] > https://lists.libav.org/mailman/listinfo/libav-api
Surely it should be numRgbBytes = width*height*3; because there is no alpha value in rgb24? Cheers, Mark. _______________________________________________ libav-api mailing list [email protected] https://lists.libav.org/mailman/listinfo/libav-api
