Why to create each time SDL_CreateTexture?

Hello All,

I am trying to build media player with ffmpeg/SDL.

I do the below…

while ( read packet)
{

  1. do whatever conversion is required.
  2. Create Texture like:
    texture1 = SDL_CreateTexture (renderer, SDL_PIXELFORMAT_IYUV, SDL_TEXTUREACCESS_STREAMING, pCodecCtx->width, pCodecCtx->height);

}

main()

{
// Event Handling.
// Copy texter1 to renderer,
// present the renderer.
}

I tried creating texture1 so that it is created only once. But that doesn’t work.

My question is why do we need each time to create texture each time , is it is right way ?. or am i doing something wrong ?

Kindly help me.

2014-02-03 keestu :

Hello All,

I am trying to build media player with ffmpeg/SDL.

I do the below…

while ( read packet)
{

  1. do whatever conversion is required.
  2. Create Texture like:
    texture1 = SDL_CreateTexture (renderer, SDL_PIXELFORMAT_IYUV,
    SDL_TEXTUREACCESS_STREAMING, pCodecCtx->width, pCodecCtx->height);

}

main()

{
// Event Handling.
// Copy texter1 to renderer,
// present the renderer.
}

I tried creating texture1 so that it is created only once. But that
doesn’t work.

My question is why do we need each time to create texture each time , is
it is right way ?. or am i doing something wrong ?

Kindly help me.

Hi,

you don’t have to recreate a texture each time, if the size you
need stays constant. Look into SDL_UpdateTexture [1] on how
to push new pixels into an existing texture.

[1] http://wiki.libsdl.org/SDL_UpdateTexture

Thanks Jonas for the reply,

I have been trying YUVUpdate already, Now i moved the CreateTexture to the main function, and did the below.

mytexture ()
{

  1. Read Packet from ffmpeg
  2. Update Texture with SDL_UpdateYUVTexture,
    }

main ()
{

  • Create Texture here,

while loop,
- Handle Event Loop
- Invoke mytexture,
- RenderCopy Texture,
- Render Present.

}

NOw i get the below error, Texture dimensions can’t be 0 while creating texture, is it something related to avcodec_decode_video2 ? which might be updating the texture dimension ?

KIndly let know if my approach is wrong ?

Sorry to type wrongly. avcodec_decode_video2 is no way related to texture, both are from different space. :slight_smile:

Sorry to type wrongly. avcodec_decode_video2 is no way related to
texture, both are from different space. [image: Smile]

I think your problem may be related to invalid frame sizes, you have to
skip a frame if width of height in the avcontext is 0 and reallocate the
texture if width or height is different from the ones of the texture.On Mon, Feb 3, 2014 at 1:21 PM, keestu wrote:


Bye,
Gabry

Thanks, and will try to do the same.