An ffmpeg and SDL Tutorial
该教程转自这个网站的服务器在美国,故需要代理服务器才能链接到。链接的时候需要将 "www."删掉。教程共分为 8 部分,这八个部分的代码都是选自于 ffmpeg 库里面的ffplay.c文件。 由于精力有限,我就没有去翻译这个文档了。英文大家就将就着看吧,反正也不是很难。
What now?
So we have a working player, but it's certainly not as nice as it could be. We did a lot of handwaving, and there are a lot of other features we could add:
- Error handling. The error handling in our code is abysmal, and could be handled a lot better.
- Pausing. We can't pause the movie, which is admittedly a useful feature. We can do this by making use of an internal paused variable in our big struct that we set when the user pauses. Then our audio, video, and decode threads check for it so they don't output anything. We also use av_read_play for network support. It's pretty simple to explain, but it's not obvious to figure out for yourself, so consider this homework if you want to try more. For hints, check out ffplay.c.
- Support for video hardware. For a sample of setting this up, check out the Frame Grabbing section in .
- Seeking by bytes. If you calculate the seek position by bytes instead of seconds, it is more accurate on video files that have discontiguous timestamps, like VOB files.
- Frame dropping. If the video falls too far behind, we should drop the next frame instead of setting a short refresh.
- Network support. This video player can't play network streaming video.
- Support for raw video like YUV files. There are some options we have to set if our player is to support raw video like YUV files, as we cannot guess the size or time_base.
- Fullscreen
- Various options, e.g. different pic formats; see ffplay.c for all the command line switches.
- Other hand-wavy things; for example, the audio buffer in our struct should be declared aligned.
If you want to know more about ffmpeg, we've only covered a portion of it. The next step would be to study how to encode multimedia. A good place to start would be the output_example.c file in the ffmpeg distribution. I may write another tutorial on that, but I might not get around to it.
Well, I hope this tutorial was instructive and fun. If you have any suggestions, bugs, complaints, accolades, etc., please email me at dranger at gmail dot com.
Links:
SDL Documentation
This work is licensed under the Creative Commons Attribution-Share Alike 2.5 License. To view a copy of this license, visit or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.
Code examples are based off of FFplay, Copyright (c) 2003 Fabrice Bellard, and a tutorial by Martin Bohme.
阅读(2055) | 评论(0) | 转发(0) |