您的位置:首页 > 移动开发 > Android开发

FFmpeg和SDL的API

2013-05-10 09:15 447 查看
使用FFmpeg的API和SDL的API进行视频的解码和显示,似乎还是有点技术含量的东西,我最近收到一些email询问视频的解码和显示的实 现,今天hanyionet就献上博文一篇简单地说明一下如何使用这些API,其实使用这些API其实一点都不难,不要被复杂描述吓到。我们所要做就是先 要了解视频的解码和显示到底是怎样的一个过程,然后了解各个API的作用。

进行解码和视频的现实一般来说就是这样的步骤:
初始化–>解码–>图像缩放–>视频显示

以下是一个简单的过程流程图,在每一个步骤中给出一些比较重要的API。

可以看出,不同的步骤的实现,就是找到并使用相对应的API。

图中的API的具体说明,今天一同给出。

FFmpeg API
描述
av_register_all()
Initializes libavformat and registers all the muxers, demuxers and protocols.
avcodec_find_decoder(…)
Finds a decoder with a matching codec ID.
avcodec_alloc_context()
Allocates an AVCodecContext and sets its fields to default values.
avcodec_alloc_frame()
Allocates an AVFrame and sets its fields to default values.
sws_getContext(…)
Returns an SwsContext to be used in sws_scale().
sws_scale(…)
Scales the data in source according to our settings in our SwsContext c. srcStride and dstStride are the source and destination linesize.
avcodec_decode_video(…)
Decodes a video frame from buffer into picture.
 
SDL API
描述
SDL_SetVideoMode()
Set up a video mode with the specified width, height, and bits-per-pixel.
SDL_CreateYUVOverlay()
It is used to create a YUV overlay of the specified width, height and format for the provided display.
SDL_BlitSurface()
This performs a fast blit from the source surface to the destination surface.
SDL_FreeSurface()
Frees (deletes) a SDL surface.
SDL_UpdateRect()
Makes sure the given area is updated on the given screen.
SDL_Flip()
It is used to swap screen buffers. On hardware that supports double-buffering, this function sets up a flip and returns.
SDL_FreeYUVOverlay()
Free a YUV video overlay.
其实要理解FFmpeg的API还有一个非常重要的地方就是理解,各种数据结构的具体内容,譬如AVFrame和AVCodecContext,个人认为这两个结构是比较重要的。

了解的这些API的使用方法后,现在应该做的就是找一个例子例如ffplay.c或者http://dranger.com/ffmpeg/里的例程,体会一下,最后使用这些API搭建出属于自己的视屏播放程序。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Android FFmpeg sdl API 视频