Converting AVPicure to SDL_Surface

Hi.
I’m trying to convert AVPicture I got from decoder to SDL_Surface. I tried the SDL_CreateRGBSurfaceFrom and I’m pretty sure that this is the way to do it but I had no luck with it. AVPicture has a 2 elements defined as uint8_t *data[4] and int linesize[4]; How do I incorporate this into the SDL_CreateRGBSurfaceFrom parameters which accept void *pixels and int pitch? AVPicture is decoded in the 32 RGB format by the way.

Regards,
Dario

ELMA Kurtalj d.o.o. (ELMA Kurtalj ltd.)
Vitezi?eva 1a, 10000 Zagreb, Hrvatska (Viteziceva 1a, 10000 Zagreb, Croatia)
Tel: 01/3035555, Faks: 01/3035599 (Tel: ++385-1-3035555, Fax: ++385-1-3035599 )

Www:
www.elma.hr; shop.elma.hr

E-mail:
elma at elma.hr (elma at elma.hr)
pitanje at elma.hr (questions at elma.hr)
primjedbe at elma.hr (complaints at elma.hr)
prodaja at elma.hr (sales at elma.hr)
servis at elma.hr (servicing at elma.hr)
shop at elma.hr (shop at elma.hr)
skladiste at elma.hr (warehouse at elma.hr)

Hi.
I’m trying to convert AVPicture I got from decoder to SDL_Surface. I tried
the SDL_CreateRGBSurfaceFrom and I’m pretty sure that this is the way to do
it but I had no luck with it. AVPicture has a 2 elements defined as uint8_t
*data[4] and int linesize[4]; How do I incorporate this into the
SDL_CreateRGBSurfaceFrom parameters which accept void *pixels and int pitch?
AVPicture is decoded in the 32 RGB format by the way.

Regards,
Dario


ELMA Kurtalj d.o.o. (ELMA Kurtalj ltd.)

Vitezi?eva 1a, 10000 Zagreb, Hrvatska (Viteziceva 1a, 10000 Zagreb, Croatia)
Tel: 01/3035555, Faks: 01/3035599 (Tel: ++385-1-3035555, Fax:
++385-1-3035599 )

Www:
www.elma.hr; shop.elma.hr

E-mail:
elma at elma.hr (elma at elma.hr)
pitanje at elma.hr (questions at elma.hr)
primjedbe at elma.hr (complaints at elma.hr)
prodaja at elma.hr (sales at elma.hr)
servis at elma.hr (servicing at elma.hr)
shop at elma.hr (shop at elma.hr)
skladiste at elma.hr (warehouse at elma.hr)


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

'lo!

I seem to be answering a lot of these lately.

Anyhoo, modified from the examples, try something like:On Thu, Apr 7, 2011 at 10:46 AM, Dario wrote:

======

SDL_LockSurface(vp->bmp);

dst_pix_fmt = PIX_FMT_RGB565; // or whatever is appropriate for your display

// point pict at the queue

pict.data[0] = vp->bmp->pixels;
pict.linesize[0] = vp->bmp->pitch;

img_convert (&pict, dst_pix_fmt, (AVPicture *) pFrame,
is->video_st->codec->pix_fmt, is->video_st->codec->width,
is->video_st->codec->height);

SDL_UnlockSurface(vp->bmp);

========

This can also work with a sws_scale() setup if you want it to. The
dst_pix_fmt variable I hard coded cause I could :slight_smile: – you can hard code
yours for now, or work with an array of translated sdl -> ffmpeg formats.

-Will

It works!!
img_convert is deprecated so I used sw_scale. It seems I was on the right track and only thing I had to do was set the pointers plus some minor tweaks.
My previous application uses SDL_Overlay for video but it got tiresome to build all the GUI myself and I decided to port it to MFC and was immediatly hit with “You must use a surface obtained from SDL_SetVideoMode to work with SDL_Overlay”

Today is my deadline to make it work and you are a life saver. What a nice morning!
Thank you.

Best wishes,
Dario.> ----- Original Message -----

From: Will Langford
To: SDL Development List
Sent: Thursday, April 07, 2011 6:16 PM
Subject: Re: [SDL] converting AVPicure to SDL_Surface

On Thu, Apr 7, 2011 at 10:46 AM, Dario <@Dario> wrote:
Hi.
I’m trying to convert AVPicture I got from decoder to SDL_Surface. I tried the SDL_CreateRGBSurfaceFrom and I’m pretty sure that this is the way to do it but I had no luck with it. AVPicture has a 2 elements defined as uint8_t *data[4] and int linesize[4]; How do I incorporate this into the SDL_CreateRGBSurfaceFrom parameters which accept void *pixels and int pitch? AVPicture is decoded in the 32 RGB format by the way.

Regards,
Dario

ELMA Kurtalj d.o.o. (ELMA Kurtalj ltd.)
Vitezi?eva 1a, 10000 Zagreb, Hrvatska (Viteziceva 1a, 10000 Zagreb, Croatia)
Tel: 01/3035555, Faks: 01/3035599 (Tel: ++385-1-3035555, Fax: ++385-1-3035599 )

Www:
www.elma.hr; shop.elma.hr

E-mail:
elma at elma.hr (elma at elma.hr)
pitanje at elma.hr (questions at elma.hr)
primjedbe at elma.hr (complaints at elma.hr)
prodaja at elma.hr (sales at elma.hr)
servis at elma.hr (servicing at elma.hr)
shop at elma.hr (shop at elma.hr)
skladiste at elma.hr (warehouse at elma.hr)


_______________________________________________
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

'lo!

I seem to be answering a lot of these lately.

Anyhoo, modified from the examples, try something like:

======

SDL_LockSurface(vp->bmp);

dst_pix_fmt = PIX_FMT_RGB565; // or whatever is appropriate for your display

// point pict at the queue

pict.data[0] = vp->bmp->pixels;
pict.linesize[0] = vp->bmp->pitch;

img_convert (&pict, dst_pix_fmt, (AVPicture *) pFrame, is->video_st->codec->pix_fmt, is->video_st->codec->width, is->video_st->codec->height);

SDL_UnlockSurface(vp->bmp);

========

This can also work with a sws_scale() setup if you want it to. The dst_pix_fmt variable I hard coded cause I could :slight_smile: – you can hard code yours for now, or work with an array of translated sdl -> ffmpeg formats.

-Will



SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

ELMA Kurtalj d.o.o. (ELMA Kurtalj ltd.)
Vitezi?eva 1a, 10000 Zagreb, Hrvatska (Viteziceva 1a, 10000 Zagreb, Croatia)
Tel: 01/3035555, Faks: 01/3035599 (Tel: ++385-1-3035555, Fax: ++385-1-3035599 )

Www:
www.elma.hr; shop.elma.hr

E-mail:
elma at elma.hr (elma at elma.hr)
pitanje at elma.hr (questions at elma.hr)
primjedbe at elma.hr (complaints at elma.hr)
prodaja at elma.hr (sales at elma.hr)
servis at elma.hr (servicing at elma.hr)
shop at elma.hr (shop at elma.hr)
skladiste at elma.hr (warehouse at elma.hr)