Re: [GD-DEVEL] Problems converting AVFrame to gdImagePtr
[email protected] (Udo Pokojski) Sun, 31 May 2009 12:32:13 +0200
| Newsgroups | php.gd.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi,
Yes, I am using ffmpeg and I started with the example from cvs.
Meanwhile I have written a function whichs saves the Image as a PPM-File
without using libgd-Functions. This function looks like this:
---------------------------------------------------------------------
void SaveFrame_ppm(AVFrame *pFrame, int width, int height, int iFrame) {
FILE *pFile;
char szFilename[32];
int y;
// Open file
sprintf(szFilename, "frame%d.ppm", iFrame);
pFile=fopen(szFilename, "wb");
if(pFile==NULL)
return;
// Write header
fprintf(pFile, "P6\n%d %d\n255\n", width, height);
// Write pixel data
for(y=0; y<height; y++)
fwrite(pFrame->data[0]+y*pFrame->linesize[0], 1, width*3, pFile);
// Close file
fclose(pFile);
}
----------------------------------------------------------------------
Since the pictures are corrupted when I use libgd-Functions, there must
be an error in the example code.
Am Samstag, den 30.05.2009, 19:39 +0200 schrieb Pierre Joye:
> Hi,
>
> Do you use ffmpeg? There is an example in cvs:
>
> http://cvs.php.net/viewvc.cgi/gd/playground/ffmpeg/
>
> Cheers,
>
> On Sat, May 30, 2009 at 4:44 PM, Udo Pokojski <[email protected]> wrote:
> > Hi,
> >
> > I am trying to extract single frame from a MP2-File. The frames are
> > extracted and saved as AVFrame. For further processing I want to convert
> > the AVFrame to an gdImagePtr. The conversion should be done by this
> > code:
> > -------------------------------------------------------------------------
> > void SaveFrame_png(AVFrame *pFrame, int width, int height, int iFrame) {
> > FILE *pFile;
> > char szFilename[32];
> > int x,y;
> > gdImagePtr im;
> > int *src;
> >
> > im=gdImageCreateTrueColor(width, height);
> > //gdImageInterlace(im, 1);
> > src = (int *) pFrame->data[0];
> > for(y=0; y < height; y++) {
> > for (x=0; x < width; x++) {
> > gdImageSetPixel(im, x, y, src[x] & 0x00FFFFFF);
> > // im->tpixels[y][x] = src[x] & 0x00FFFFFF;
> > }
> > src += width;
> > }
> >
> > sprintf(szFilename, "frame%d.png", iFrame);
> > pFile=fopen(szFilename, "wb");
> > if(pFile==NULL)
> > return;
> > gdImageInterlace(im,1);
> > gdImagePng(im,pFile);
> >
> > fclose(pFile);
> >
> > }
> >
> > ------------------------------------------------------------------------------
> >
> > For a quick test, I save the gdImagePtr as a PNG-File.
> > The resulting file shows a kind of interlace and a multiple horizontal
> > shift. I have uploaded an example to
> > http://www.freeimagehosting.net/uploads/081ff0fcb2.png
> >
> > Write a JPG-File gives the same result.
> > Where is the error in this code?
> >
> > Thx,
> > Udo
> >
> >
> >
> >
> > --
> > GD Devel Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
>
>
> --
> Pierre
>
> http://blog.thepimp.net | http://www.libgd.org
>