How to play video in SDL2.0.1?

There is a native-media Sample in Android NDK, shows how to bind video to the SurfaceView or GLSurfaceView in native-side.
Is there a similar way that to bind video to SDL Surface or other place in SDL2.0.1?

There is a native-media Sample in Android NDK, shows how to bind video to

the SurfaceView or GLSurfaceView in native-side.
Is there a similar way that to bind video to SDL Surface or other place
in SDL2.0.1?

You’ll find tons of example of this since most basic players have an SDL
output module, for instance “ffplay” the reference player in the ffmpeg
package uses SDL.

Obviously how to play video depends on the video decoding framework you are
using, but at the “display” level, if you get a YUV or RGB surface, all you
have to do in SDL is to update the texture, copy it on the screen, and
display it for the frame presentation period.

Provided your decoded image is a libavcodec AVPicture this is can be as
simple as this:

[… create texture from AVCodecContext …]

texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_YV12,
SDL_TEXTUREACCESS_STATIC, ctx->width , ctx->height)

[… every time you decode an image… ]
SDL_UpdateYUVTexture(texture, NULL, frame->data[0], frame->linesize[0],
frame->data[1], frame->linesize[1], frame->data[2], frame->linesize[2]);
SDL_RenderCopy(renderer, texture, NULL, &rect);
SDL_RenderPresent(renderer);–
Bye,
Gabry

2013/12/6 Gabriele Greco <gabriele.greco at darts.it>

There is a native-media Sample in Android NDK, shows how to bind video to

the SurfaceView or GLSurfaceView in native-side.
Is there a similar way that to bind video to SDL Surface or other place
in SDL2.0.1?

You’ll find tons of example of this since most basic players have an SDL
output module, for instance “ffplay” the reference player in the ffmpeg
package uses SDL.

Obviously how to play video depends on the video decoding framework you
are using, but at the “display” level, if you get a YUV or RGB surface, all
you have to do in SDL is to update the texture, copy it on the screen, and
display it for the frame presentation period.

Provided your decoded image is a libavcodec AVPicture this is can be as
simple as this:

[… create texture from AVCodecContext …]

texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_YV12,
SDL_TEXTUREACCESS_STATIC, ctx->width , ctx->height)

[… every time you decode an image… ]
SDL_UpdateYUVTexture(texture, NULL, frame->data[0], frame->linesize[0],
frame->data[1], frame->linesize[1], frame->data[2], frame->linesize[2]);
SDL_RenderCopy(renderer, texture, NULL, &rect);
SDL_RenderPresent(renderer);

Speaking of which, if anyone wants to dig into this and provide a
patch…seems rather useful for video playback :slight_smile:

https://bugzilla.libsdl.org/show_bug.cgi?id=2143--
Gabriel.