[Libav-user] Decoded frame upside down

Rafael do Nascimento Pereira rnp at 25ghz.net
Thu Sep 6 23:31:13 CEST 2012


Hello folks,

I am decoding a video with an PIX_FMT_YUV420P pixel format, and then saving
it as a BMP file.

The decoding is successful and i have a raw YUV frame and then i convert it
to PIX_FMT_RGB24:

*swsctx = sws_getCachedContext(swsctx,
                                  codecctx->width,
                                  codecctx->height,
                                  codecctx->pix_fmt,
                                  codecctx->width,
                                  codecctx->height,
                                  PIX_FMT_RGB24,
                                  SWS_BICUBIC,
                                  NULL,
                                  NULL,
                                  NULL);

sws_scale(swsctx, frame->data, frame->linesize, 0, codecctx->height,
                              framergb->data, framergb->linesize);*


And finally i save it on disk with the appropriate BMP header and then the
RGB24 frame.

*for (y = 0; y < codecctx->height; y++) {
    fwrite(framergb->data[0] + y * framergb->linesize[0], 1,
(codecctx->width * BYTESPERPIXEL), pFile);
}*

The strange thing is that the image, when opened (e.g. viewnior or gimp) is
shown upside down. I started to
write on disk from the beginning of the buffer til the end.

If i do the opposite:

*uint8_t *end = framergb->data[0] + (codecctx->height *
framergb->linesize[0]);

for (y = 0; y < codecctx->height; y++) {
     fwrite(end - (y * framergb->linesize[0]), 1, (codecctx->width *
BYTESPERPIXEL), pFile);
}
*
The BMP image is shown correctly.  I really don't know if i made some
mistake in this proccess,
or this is the way the ffmpeg library actually works. relevant infos:

ffmpeg  0.10.4
Linux     (Fedora 17)
gcc        4.7.0 20120507


Thanks in advance.


Regards,
Rafael.



*"If you can't explain it simply, you don't understand it well enough."
--Albert Einstein*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20120906/e6d58d81/attachment.html>


More information about the Libav-user mailing list