SDL 1.3 and SDL_ffmpeg

Hi,

I’m trying to convert Arjan Houben’s SDL_ffmpeg to work directly with SDL1.3 Textures. I have previously used his library using SDL 1.2 and Overlays. I have found that using Surfaces is far too slow for my hardware. Therefore I can’t really use the SDL_CreateTextureFromSurface ( Too bad there is no SDL_CreateTextureFromOverlay )

First I created a texture with,

Code:

videoFrame->texture = SDL_CreateTexture( renderer, SDL_PIXELFORMAT_YUY2, SDL_TEXTUREACCESS_STREAMING, w, h ); //3plane

And then I attempted to modify Arjan’s library with,

Code:

if ( frame->texture )
{
void *pixels;
int tpitch[3];

    SDL_LockTexture(frame->texture, NULL, &pixels, &tpitch[0]);
		
    sws_scale( getContext( &file->videoStream->conversionContext,
                               file->videoStream->_ffmpeg->codec->width,
                               file->videoStream->_ffmpeg->codec->height,
                               file->videoStream->_ffmpeg->codec->pix_fmt,
                               frame->tempw, frame->temph,
                               PIX_FMT_YUYV422 ),
                   ( const uint8_t* const* )file->videoStream->decodeFrame->data,
                   file->videoStream->decodeFrame->linesize,
                   0,
                   file->videoStream->_ffmpeg->codec->height,
                   ( uint8_t* const* )pixels,
                   tpitch );	
    SDL_UnlockTexture( frame->texture );		

}

Below is similar code, except with the pixles of an SDL Overlay (SDL 1.2) being written to,

Code:

/* convert YUV 420 to YUYV 422 data */
else if ( frame->overlay && frame->overlay->format == SDL_YUY2_OVERLAY )
{
int pitch[] =
{
frame->overlay->pitches[ 0 ],
frame->overlay->pitches[ 1 ],
frame->overlay->pitches[ 2 ]
};

        sws_scale( getContext( &file->videoStream->conversionContext,
                               file->videoStream->_ffmpeg->codec->width,
                               file->videoStream->_ffmpeg->codec->height,
                               file->videoStream->_ffmpeg->codec->pix_fmt,
                               frame->overlay->w, frame->overlay->h,
                               PIX_FMT_YUYV422 ),
                   ( const uint8_t* const* )file->videoStream->decodeFrame->data,
                   file->videoStream->decodeFrame->linesize,
                   0,
                   file->videoStream->_ffmpeg->codec->height,
                   ( uint8_t* const* )frame->overlay->pixels,
                   pitch );

}

Writing the pixels to the Texture Segment Faults, but writing to the Overlay works great. Anyone with any insight / examples or other help? I’d be happy to hear of more straight forward ways to do this but I do like ffmpeg.

Unfortunately it looks like Arjan has stopped working / supporting SDL_ffmpeg.

Thanks in advance.

Hi,

I’m trying to convert Arjan Houben’s SDL_ffmpeg to work directly with SDL1.3 Textures. I have previously used his library using SDL 1.2 and Overlays. I have found that using Surfaces is far too slow for my hardware. Therefore I can’t really use the SDL_CreateTextureFromSurface ( Too bad there is no SDL_CreateTextureFromOverlay )

First I created a texture with,

Code:

videoFrame->texture = SDL_CreateTexture( renderer, SDL_PIXELFORMAT_YUY2, SDL_TEXTUREACCESS_STREAMING, w, h );? //3plane

Hi

I use SDL 1.3 with ffmpeg 0.7.5. Its so far working well for me.

SDL_PIXELFORMAT_YUY2 is not 3 plane.

I use SDL_PIXELFORMAT_YV12 for textures. Works very well.

Hope this useful to you.

Unga— On Tue, 10/4/11, mjohnson wrote:
From: mjohnson@baytekgames.com (mjohnson)
Subject: [SDL] SDL 1.3 and SDL_ffmpeg
To: sdl at lists.libsdl.org
Date: Tuesday, October 4, 2011, 10:15 AM

Unga,

Thanks for your reply. You are right that SDL_PIXELFORMAT_YUY2 is not 3 plane. The comment in my code was wrong.

I did get it working now with SDL_PIXELFORMAT_YUY2. For anyone interested in the future the working code is,

Code:

/* if we did not get a frame or we need to hurry, we return */
if ( got_frame && !file->videoStream->_ffmpeg->codec->hurry_up )
{
	if ( frame->texture )
	{
		void* pixels;
        int tpitch[3];

		SDL_LockTexture(frame->texture, NULL, &pixels, &tpitch[0]);

        sws_scale( getContext( &file->videoStream->conversionContext,
                               file->videoStream->_ffmpeg->codec->width,
                               file->videoStream->_ffmpeg->codec->height,
                               file->videoStream->_ffmpeg->codec->pix_fmt,
                               frame->tempw, frame->temph,
                               PIX_FMT_YUYV422 ),
                   ( const uint8_t* const* )file->videoStream->decodeFrame->data,
                   file->videoStream->decodeFrame->linesize,
                   0,
                   file->videoStream->_ffmpeg->codec->height,
                   &pixels,
                   tpitch );	
        SDL_UnlockTexture( frame->texture );		
	}