[Libav-user] only seeing 1/3 of image after sws_scale
system159
afcrowe at gmail.com
Sat Jul 9 01:20:15 CEST 2011
Hi all! I'm trying to use ffmpeg to decode single I frames (at user given
intervals) from a transport stream. The problem comes after calling
avcodec_decode_video2, as it returns the image in a crazy format. I want
basic RGB24 so that the rest of my QT app can use it via QImage. So I call
sws_scale to convert it to RGB24. When I later on post my image, is shows up
like this:
http://i54.tinypic.com/6rtx78.jpg
Can anybody tell me what I'm doing wrong? Is it sws_scale, or the way I'm
reading the data out of the avframe into the QImage?
My code is as follows(hard coded because I'm using a fixed data set to get
it working the first time).
avcodec_init();
avcodec_register_all();
pCodecCtx = NULL;
pCodec = NULL;
pFrame = NULL;
pFrameRGB = NULL;
pSwsCtx = NULL;
pFrame = avcodec_alloc_frame();
pFrameRGB = avcodec_alloc_frame();
int frameFinished;
uint8_t *buffer;
int numBytes;
pCodecCtx = avcodec_alloc_context();
// Determine required buffer size and allocate buffer
numBytes = avpicture_get_size(PIX_FMT_RGB24, 720,
480);
pCodec = avcodec_find_decoder(CODEC_ID_MPEG2VIDEO);
// Open codec
if(avcodec_open(pCodecCtx, pCodec)<0)
{
return -1; // Could not open codec
}
AVPacket packet;
//Fill AVPacket
packet.data = codedImageData;
packet.size = cidActualSize;
//Decode video
avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished,
&packet);
if(frameFinished)
{
// Determine required buffer size and allocate buffer
numBytes=avpicture_get_size(PIX_FMT_RGB24, 720,
480);
buffer=(uint8_t*)malloc(numBytes);
// Assign appropriate parts of buffer to image planes in
pFrameRGB
avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24,
720, 480);
struct SwsContext *pSWSContext = sws_getContext(720, 480,
PIX_FMT_YUV420P,
720, 480, PIX_FMT_RGB24, SWS_BILINEAR,
NULL, NULL, NULL);
sws_scale(pSWSContext, pFrame->data, pFrame->linesize, 0,
480, pFrameRGB->data, pFrameRGB->linesize);
unsigned char *src = (unsigned char *)pFrameRGB->data[0];
QImage tmpImg(QSize(pFrame->width, pFrame->height),
QImage::Format_RGB888);
for (int y = 0; y < pFrame->height; y++)
{
QRgb *scanLine = (QRgb *)gd->iFrame.scanLine(y);
for (int x = 0; x < pFrame->width; x++)
{
tmpImg.setPixel(QPoint(x, y), qRgb(src[3*x], src[3*x+1],
src[3*x+2]));
}
src += pFrameRGB->linesize[0];
}
sws_freeContext(pSwsCtx);
ResetImageData();
free(buffer);
}
pCodec->close(pCodecCtx);
Thanks!
--
View this message in context: http://libav-users.943685.n4.nabble.com/only-seeing-1-3-of-image-after-sws-scale-tp3655408p3655408.html
Sent from the libav-users mailing list archive at Nabble.com.
More information about the Libav-user
mailing list