Hi,
I'm cross posting to both SDl and ffmpeg list as this might be linked to both groups. This is a code snippet works to display a video image using SDL2.0 and ffmpeg. This code could probably be improved and one way would be to directly blit into the texture. Do you know which SDL2.0 function should i use do blit the swscale object into a texture without going through the two steps in the code below ?

if (avpacket.stream_index == videoStream) {

                        

avcodec_decode_video2(codec_context, frame, &frame_finished, &avpacket);

                        if(frame_finished)
                        {

                                

                                if(avpicture_alloc(&picture, PIX_FMT_RGB24, w,h) 
< 0){
                                        fprintf(stderr, "problem allocating 
picture!\n");
                                        exit(1);
                                }

                                img_convert_ctx  = 
sws_getCachedContext(img_convert_ctx,
                                                w,
                                                h,
                                                codec_context->pix_fmt,
                                                //PIX_FMT_YUV420P,
                                                w,
                                                h,
                                                PIX_FMT_RGB24,
                                                SWS_BICUBIC,
                                                NULL,
                                                NULL,
                                                NULL);

                                if (img_convert_ctx == NULL)
                                {
                                        fprintf(stderr, "Cannot initialize the 
conversion context!\n");
                                        exit(1);
                                }



                                int s = sws_scale(
                                                img_convert_ctx,
                                                frame->data,
                                                frame->linesize,
                                                0,
                                                h,
                                                picture.data,
                                                picture.linesize);

                        

SDL_Surface *image = SDL_CreateRGBSurfaceFrom(
                                                                                
                                 picture.data[0],
                                                                                
        w,
                                                                                
        h,
                                                                                
        24,
                                                                                
        w*3,
                                                                                
         rmask, gmask, bmask, amask);



     texture = SDL_CreateTextureFromSurface(renderer, image);


                             if (SDL_RenderCopy(renderer, texture, NULL, NULL) 
< 0)
                             {
fprintf(stderr, "SDL_RenderCopy FAILED: %s\n", SDL_GetError());
                                 return -1;
                             }


                             SDL_RenderPresent(renderer);

                             SDL_Delay(20); // Video delay
                             avpicture_free(&picture);
                             SDL_FreeSurface(image);
                             SDL_UnlockTexture(texture);

                        }

                }

_______________________________________________
Libav-user mailing list
[email protected]
http://ffmpeg.org/mailman/listinfo/libav-user

Reply via email to