Hi,
I have been working on using ffmpeg to display video in SDL2. I had
everything working before 1st Jun RenderCopyEx API commit so that should
prove that ffmpeg saves pixels correctly to the SDL_Texture (Unless
SDL_Texture structure has been changed as well).
Briefly:
vp->bmp_t = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_YV12,
SDL_TEXTUREACCESS_STREAMING, is->video_st->codec->width,
is->video_st->codec->height);
-load pixels to texture:
if(vp->bmp_t && !SDL_LockTexture(vp->bmp_t, NULL, (void **)&pixels,
&pitch)) {
memset(&pict, 0, sizeof(AVPicture));
if(pitch == pFrame->linesize[0]) {
int size = pitch * is->video_st->codec->height;
memcpy(pixels, pFrame->data[0], size);
memcpy(pixels + size, pFrame->data[2], size / 4);
memcpy(pixels + size * 5 / 4, pFrame->data[1], size / 4);
}
else
{
register unsigned char *y1,*y2,*y3,*i1,*i2,*i3;
int i;
y1 = pixels;
y3 = pixels + pitch * is->video_st->codec->height;
y2 = pixels + pitch * is->video_st->codec->height * 5 / 4;
i1=pFrame->data[0];
i2=pFrame->data[1];
i3=pFrame->data[2];
for (i = 0; i<(is->video_st->codec->height/2); i++) {
memcpy(y1,i1,pitch);
i1+=pFrame->linesize[0];
y1+=pitch;
memcpy(y1,i1,pitch);
memcpy(y2,i2,pitch / 2);
memcpy(y3,i3,pitch / 2);
y1+=pitch;
y2+=pitch / 2;
y3+=pitch / 2;
i1+=pFrame->linesize[0];
i2+=pFrame->linesize[1];
i3+=pFrame->linesize[2];
}
}
SDL_UnlockTexture(vp->bmp_t);
- display:
SDL_RenderClear(renderer);
SDL_Point* point = NULL;
SDL_RendererFlip flip = SDL_FLIP_NONE;
//SDL_RenderCopyEx( renderer, vp->bmp_t, NULL , NULL ,NULL , point, flip );
SDL_RenderCopy(renderer, vp->bmp_t,NULL,NULL);
SDL_RenderPresent(renderer);
RenderCopy displays:
http://www.freeimagehosting.net/xb5cr
RenderCopyEx does not display anything.
I need RenderCopyEx in other parts of the program as it is making things
a lot easier with rotation and flipping. I guess it is good to mention
that I tried using just using surface and then transforming it into
texture but it slows down the whole application.
Any help is very much appriciated,
Jacek